diff --git a/src/darkstar/__init__.py b/src/darkstar/__init__.py index ad0249b..4446c73 100644 --- a/src/darkstar/__init__.py +++ b/src/darkstar/__init__.py @@ -3,4 +3,4 @@ A web framework for using htmx with Starlette """ -__version__ = "0.1.4" +__version__ = "0.1.5" diff --git a/src/darkstar/applications.py b/src/darkstar/applications.py index 13ff47b..5675b5d 100644 --- a/src/darkstar/applications.py +++ b/src/darkstar/applications.py @@ -79,7 +79,6 @@ def __init__( debug: bool = False, routes: typing.Sequence[BaseRoute] = [], static_directory: str = "static", - global_objects=[], middleware: typing.Sequence[Middleware] = None, exception_handlers: typing.Mapping[ typing.Any, @@ -92,11 +91,11 @@ def __init__( lifespan: typing.Callable[["Starlette"], typing.AsyncContextManager] = None, ) -> None: - self.global_objects = global_objects - global dark_star_templates dark_star_templates = Jinja2Templates(routes_path) + self.template_env = dark_star_templates.env + path_routes = self._collect_routes(routes_path) if not any( @@ -127,24 +126,19 @@ def _collect_routes(self, routes_path) -> typing.Sequence[BaseRoute]: ) ) - new_globals = {x.__name__: x for x in self.global_objects} - - compiled_function = exec( - compile(modded_function, f"{path}", "exec"), - new_globals.update(globals()), - ) + exec(compile(modded_function, f"{path}", "exec"), globals()) route_options = get_options(python) if path.relative_to(routes_path) == Path("index.py"): if "name" not in route_options: route_options["name"] = "index" - routes.append(Route("/", locals()[function_name], **route_options)) + routes.append(Route("/", globals()[function_name], **route_options)) else: routes.append( Route( f"/{path.relative_to(routes_path).with_suffix('')}/", - locals()[function_name], + globals()[function_name], **route_options, ) )