diff options
author | 2024-07-08 15:09:17 +0100 | |
---|---|---|
committer | 2024-07-08 15:09:17 +0100 | |
commit | 642c0795c8738bf8b9ae39b9cf0180f7cdbac650 (patch) | |
tree | 4a075255d00d9f8a2f369567bdb79f6eefa4be9a /backend/route_manager.py | |
parent | Migration to official Sentry release CI action (#275) (diff) | |
parent | Stop using gunicorn and use uvicorn directly to run application (diff) |
Merge pull request #276 from python-discord/jb3/environ/python-3.12
3.12 + Updates
Diffstat (limited to 'backend/route_manager.py')
-rw-r--r-- | backend/route_manager.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/backend/route_manager.py b/backend/route_manager.py index 2d95bb2..b35ca0b 100644 --- a/backend/route_manager.py +++ b/backend/route_manager.py @@ -1,6 +1,4 @@ -""" -Module to dynamically generate a Starlette routing map based on a directory tree. -""" +"""Module to dynamically generate a Starlette routing map based on a directory tree.""" import importlib import inspect @@ -27,7 +25,7 @@ def construct_route_map_from_dict(route_dict: dict) -> list[BaseRoute]: return route_map -def is_route_class(member: t.Any) -> bool: # noqa: ANN401 +def is_route_class(member: t.Any) -> bool: return inspect.isclass(member) and issubclass(member, Route) and member != Route @@ -35,7 +33,7 @@ def route_classes() -> t.Iterator[tuple[Path, type[Route]]]: routes_directory = Path("backend") / "routes" for module_path in routes_directory.rglob("*.py"): - import_name = f"{'.'.join(module_path.parent.parts)}.{module_path.stem}" + import_name = f"{".".join(module_path.parent.parts)}.{module_path.stem}" route_module = importlib.import_module(import_name) for _member_name, member in inspect.getmembers(route_module): if is_route_class(member): @@ -47,7 +45,7 @@ def create_route_map() -> list[BaseRoute]: route_dict = nested_dict() for module_path, member in route_classes(): - # module_path == Path("backend/routes/foo/bar/baz/bin.py") + # For Path: "backend/routes/foo/bar/baz/bin.py" # => levels == ["foo", "bar", "baz"] levels = module_path.parent.parts[2:] current_level = None |