aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-10-26 02:07:43 +0800
committer简律纯 <i@jyunko.cn>2023-10-26 02:07:43 +0800
commit588ae0692789b56607aaf15658b23f069877e481 (patch)
tree0440f5d5e991282f8e953aba3be874f003daad1b /src
parentd3db3acda76ebc5d25b9ef661b6a63089dee0720 (diff)
downloadinfini-588ae0692789b56607aaf15658b23f069877e481.tar.gz
infini-588ae0692789b56607aaf15658b23f069877e481.zip
feat: newdocs
Diffstat (limited to 'src')
-rw-r--r--src/hydrorollcore/core.py6
-rw-r--r--src/hydrorollcore/rule.py14
-rw-r--r--src/hydrorollcore/typing.py2
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 = []