From d9097218e2d515a88ac9b6039c09fab5859c2f4b Mon Sep 17 00:00:00 2001 From: Daven Quinn Date: Fri, 12 Jan 2024 22:49:14 -0600 Subject: [PATCH] Update structure of subsystems manager --- app-frame/macrostrat/app_frame/__init__.py | 2 ++ .../macrostrat/app_frame/subsystems/__init__.py | 12 +++++++++--- app-frame/macrostrat/app_frame/subsystems/defs.py | 5 ++--- app-frame/poetry.lock | 13 ++++++++++++- app-frame/pyproject.toml | 1 + 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app-frame/macrostrat/app_frame/__init__.py b/app-frame/macrostrat/app_frame/__init__.py index 9b3886a..a471258 100644 --- a/app-frame/macrostrat/app_frame/__init__.py +++ b/app-frame/macrostrat/app_frame/__init__.py @@ -1,2 +1,4 @@ from .core import Application from .compose import compose +from .subsystems import SubsystemManager, Subsystem, SubsystemError +from .exc import ApplicationError diff --git a/app-frame/macrostrat/app_frame/subsystems/__init__.py b/app-frame/macrostrat/app_frame/subsystems/__init__.py index 9a3fb12..8cafcd0 100644 --- a/app-frame/macrostrat/app_frame/subsystems/__init__.py +++ b/app-frame/macrostrat/app_frame/subsystems/__init__.py @@ -2,6 +2,7 @@ from ..core import ApplicationBase from packaging.specifiers import InvalidSpecifier, SpecifierSet from packaging.version import Version +from typing import Optional from macrostrat.utils.logs import get_logger @@ -20,13 +21,18 @@ class SubsystemManager: """ _hooks_fired = [] - _app: ApplicationBase + _app: Optional[ApplicationBase] = None + _subsystem_cls: Subsystem = Subsystem - def __init__(self, app: ApplicationBase): - self._app = app + def __init__(self, subsystem_cls: Subsystem = Subsystem): + self._app = None self.__init_store = [] self.__store = None + # Ensure that the plugin class is a subclass of Subsystem + assert issubclass(subsystem_cls, Subsystem) or subsystem_cls is Subsystem + self._subsystem_cls = subsystem_cls + def __iter__(self): try: yield from self.__store diff --git a/app-frame/macrostrat/app_frame/subsystems/defs.py b/app-frame/macrostrat/app_frame/subsystems/defs.py index 861f8b3..e3f9ffb 100644 --- a/app-frame/macrostrat/app_frame/subsystems/defs.py +++ b/app-frame/macrostrat/app_frame/subsystems/defs.py @@ -1,4 +1,4 @@ -from macrostrat.app_frame import ApplicationError +from ..exc import ApplicationError class SubsystemError(ApplicationError): @@ -17,7 +17,6 @@ class Subsystem: def __init__(self, app): self.app = app - self.db = self.app.db - def should_enable(self): + def should_enable(self, mgr: "SubsystemManager"): return True diff --git a/app-frame/poetry.lock b/app-frame/poetry.lock index 662b78c..8816256 100644 --- a/app-frame/poetry.lock +++ b/app-frame/poetry.lock @@ -190,6 +190,17 @@ pygments = ">=2.13.0,<3.0.0" [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] +[[package]] +name = "toposort" +version = "1.10" +description = "Implements a topological sort algorithm." +optional = false +python-versions = "*" +files = [ + {file = "toposort-1.10-py3-none-any.whl", hash = "sha256:cbdbc0d0bee4d2695ab2ceec97fe0679e9c10eab4b2a87a9372b929e70563a87"}, + {file = "toposort-1.10.tar.gz", hash = "sha256:bfbb479c53d0a696ea7402601f4e693c97b0367837c8898bc6471adfca37a6bd"}, +] + [[package]] name = "typer" version = "0.9.0" @@ -225,4 +236,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "a2a524ce463937d0831bef398bea837c509f6b3d964db5b91a4b9ce5fb3bcee0" +content-hash = "48ab9ab958c58f9851147b92ae4465052bc1638d306576e2e566509bcf87340c" diff --git a/app-frame/pyproject.toml b/app-frame/pyproject.toml index c41dbc3..0c901a5 100644 --- a/app-frame/pyproject.toml +++ b/app-frame/pyproject.toml @@ -12,6 +12,7 @@ version = "1.2.0" "macrostrat.utils" = "^1.1.0" python = "^3.10" python-dotenv = "^1.0.0" +toposort = "^1.5" rich = "^13" typer = "^0.9.0"