refactor: update project code
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
from collections import defaultdict
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from ..entry import Entry, EntryDetector
|
||||
from ..pipe.core import PipeParser, PipeRunner
|
||||
@@ -12,21 +11,21 @@ __all__ = ("PresetEntryDetector",)
|
||||
class PresetEntryDetector(EntryDetector):
|
||||
_PIPE_PARSER = PipeParser()
|
||||
|
||||
def __init__(self, preset_resolver_config: Optional[PresetResolverConfig] = None):
|
||||
def __init__(self, preset_resolver_config: PresetResolverConfig | None = None):
|
||||
self._pipeparser = PipeParser()
|
||||
self._preset_resolver_config = preset_resolver_config
|
||||
|
||||
def detect_entry(self, basepath: Path) -> Optional["Entry"]:
|
||||
def detect_entry(self, basepath: Path) -> Entry | None:
|
||||
preset = PresetResolver(basepath, self._preset_resolver_config).resolve_preset()
|
||||
if preset.skip:
|
||||
return
|
||||
return None
|
||||
piperunner = PipeRunner(basepath)
|
||||
tasks = defaultdict(list)
|
||||
for preset_name, preset in preset.presets.items():
|
||||
for preset in preset.presets.values():
|
||||
if not piperunner.check_conditions(preset.conditions):
|
||||
continue
|
||||
for task_name, task_pack in preset.tasks.items():
|
||||
for task_item_name, task in task_pack.items():
|
||||
for task in task_pack.values():
|
||||
if piperunner.check_conditions(task.conditions):
|
||||
variables = {
|
||||
"entry_path": basepath,
|
||||
@@ -43,3 +42,4 @@ class PresetEntryDetector(EntryDetector):
|
||||
]
|
||||
if tasks:
|
||||
return Entry(tasks, basepath)
|
||||
return None
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Dict, Iterable, Optional
|
||||
from typing import Iterable
|
||||
|
||||
import tomli
|
||||
|
||||
@@ -21,16 +21,15 @@ class PresetResolverConfig:
|
||||
|
||||
|
||||
class PresetResolver:
|
||||
_source_cache: Dict[Path, dict] = {}
|
||||
_source_cache: dict[Path, dict] = {}
|
||||
|
||||
def __init__(self, basepath: Path, config: Optional[PresetResolverConfig] = None):
|
||||
def __init__(self, basepath: Path, config: PresetResolverConfig | None = None):
|
||||
self._basepath = basepath
|
||||
self._config = config or PresetResolverConfig()
|
||||
|
||||
def iter_sources(self) -> Iterable[Path]:
|
||||
if self._config.default:
|
||||
for filepath in (Path(__file__).parent / "default").iterdir():
|
||||
yield filepath
|
||||
yield from (Path(__file__).parent / "default").iterdir()
|
||||
if self._config.user:
|
||||
user_preset = Path.home() / ".preset.toml"
|
||||
if user_preset.exists():
|
||||
|
||||
Reference in New Issue
Block a user