feat: add task key sub_tag
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from collections import defaultdict
|
||||
import operator
|
||||
from pathlib import Path
|
||||
|
||||
from ..common.template import PathTemplate
|
||||
from ..entry.detector import ENTRY_NONE, ENTRY_SKIP, EntryDetector
|
||||
from ..entry.entry import Entry, TaskKey
|
||||
from ..entry.entry import Entry, Task, TaskKey
|
||||
from .loader import PresetLoader, PresetLoaderConfig
|
||||
from .model import Variables
|
||||
|
||||
@@ -13,12 +13,12 @@ class PresetEntryDetector(EntryDetector):
|
||||
def __init__(self, preset_loader_config: PresetLoaderConfig | None = None):
|
||||
self._preset_loader_config = preset_loader_config
|
||||
|
||||
def detect_entry(self, basepath: Path) -> Entry:
|
||||
def detect_entry(self, basepath: Path, rootpath: Path) -> Entry:
|
||||
template = PathTemplate(basepath)
|
||||
preset = PresetLoader(basepath, self._preset_loader_config).load()
|
||||
if preset.skip:
|
||||
return ENTRY_SKIP
|
||||
tasks = defaultdict(list)
|
||||
tasks = []
|
||||
for tag, preset in preset.presets.items():
|
||||
preset_variables: Variables = {"entry_path": basepath}
|
||||
if preset.variables:
|
||||
@@ -28,17 +28,24 @@ class PresetEntryDetector(EntryDetector):
|
||||
):
|
||||
continue
|
||||
for task_name, task_pack in preset.tasks.items():
|
||||
for task in task_pack.values():
|
||||
if not task.conditions or template.check_conditions(
|
||||
task.conditions, preset_variables
|
||||
for sub_tag, task_preset in task_pack.items():
|
||||
if not task_preset.conditions or template.check_conditions(
|
||||
task_preset.conditions, preset_variables
|
||||
):
|
||||
variables = preset_variables.copy()
|
||||
if task.variables:
|
||||
template.update_variables(task.variables, variables)
|
||||
tasks[TaskKey(task_name, tag)] += [
|
||||
template.fill_template(command, variables)
|
||||
for command in task.commands
|
||||
]
|
||||
if task_preset.variables:
|
||||
template.update_variables(task_preset.variables, variables)
|
||||
task = Task(
|
||||
key=TaskKey(task_name, tag, sub_tag),
|
||||
commands=[
|
||||
template.fill_template(command, variables)
|
||||
for command in task_preset.commands
|
||||
],
|
||||
priority=task_preset.priority,
|
||||
cwd=task_preset.cwd,
|
||||
)
|
||||
tasks.append(task)
|
||||
if tasks:
|
||||
return Entry(tasks, basepath)
|
||||
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
||||
return Entry(tasks, basepath, rootpath)
|
||||
return ENTRY_NONE
|
||||
|
||||
Reference in New Issue
Block a user