diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/hydrorollcore/core.py | 6 | ||||
| -rw-r--r-- | src/hydrorollcore/rule.py | 14 | ||||
| -rw-r--r-- | src/hydrorollcore/typing.py | 2 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/hydrorollcore/core.py b/src/hydrorollcore/core.py index f3c83989..56ec9404 100644 --- a/src/hydrorollcore/core.py +++ b/src/hydrorollcore/core.py @@ -15,12 +15,14 @@ class Core: try: module = importlib.import_module(rule) except ImportError as e: - raise RuleLoadError(f'Failed to load rule {rule}: {e}') + raise RuleLoadError(f'Failed to load rule {rule}: {e}') from e try: rule_cls = getattr(module, rule.split('.')[-1]) if not issubclass(rule_cls, Rule): raise RuleLoadError(f"Class '{rule_cls.__name__}' is not a subclass of 'Rule'") except AttributeError as e: - raise RuleLoadError(f"Failed to get rule class from module '{rule}': {e}") + raise RuleLoadError( + f"Failed to get rule class from module '{rule}': {e}" + ) from e loaded_rules.append(rule_cls()) return loaded_rules diff --git a/src/hydrorollcore/rule.py b/src/hydrorollcore/rule.py index 6a89b68b..eb4b92cd 100644 --- a/src/hydrorollcore/rule.py +++ b/src/hydrorollcore/rule.py @@ -1,4 +1,16 @@ from abc import ABCMeta, abstractmethod +from enum import Enum + +__all__ = ["RuleLoadType", "Rule"] + + +class RuleLoadType(Enum): + """The Type Of Rules To Be Loaded""" + + DIR = "dir" + NAME = "name" + FILE = "file" + CLASS = "class" class Rule(metaclass=ABCMeta): @@ -9,7 +21,7 @@ class Rule(metaclass=ABCMeta): @classmethod def __subclasshook__(cls, other): if cls is Rule: - return hasattr(other, 'run') and callable(getattr(other, 'run')) + return hasattr(other, "run") and callable(getattr(other, "run")) return NotImplemented @abstractmethod diff --git a/src/hydrorollcore/typing.py b/src/hydrorollcore/typing.py index 4a29d3c2..ca6a7e65 100644 --- a/src/hydrorollcore/typing.py +++ b/src/hydrorollcore/typing.py @@ -1,5 +1,5 @@ from pydantic import BaseModel - +from typing import TYPE_CHECKING, TypeVar, Callable, NoReturn, Awaitable class Config(BaseModel): rule_dir: list = [] |
