Skip to content

Commit

Permalink
Update structure of subsystems manager
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Jan 13, 2024
1 parent 066fb16 commit d909721
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app-frame/macrostrat/app_frame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .core import Application
from .compose import compose
from .subsystems import SubsystemManager, Subsystem, SubsystemError
from .exc import ApplicationError
12 changes: 9 additions & 3 deletions app-frame/macrostrat/app_frame/subsystems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app-frame/macrostrat/app_frame/subsystems/defs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from macrostrat.app_frame import ApplicationError
from ..exc import ApplicationError


class SubsystemError(ApplicationError):
Expand All @@ -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
13 changes: 12 additions & 1 deletion app-frame/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app-frame/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit d909721

Please sign in to comment.