Skip to content

Commit

Permalink
Make tasks aware of config context (#71)
Browse files Browse the repository at this point in the history
- Provide config rootdir to tasks
- Provide start and end dates as well
- isolate tests
  • Loading branch information
leclairm authored Dec 20, 2024
1 parent 9a9c093 commit 5608e2e
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 9 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Project specific / generated files
tests/files/data/*.new.txt
tests/cases/*/data/*.new.txt
tests/cases/*/svg/*
!tests/cases/*/svg/.gitkeep

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -163,6 +165,3 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

tests/files/svgs/*
!tests/files/svgs/.gitkeep
11 changes: 11 additions & 0 deletions src/sirocco/core/graph_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

if TYPE_CHECKING:
from collections.abc import Iterator
from datetime import datetime
from pathlib import Path

from sirocco.parsing._yaml_data_models import ConfigBaseData, ConfigCycleTask, ConfigTask, TargetNodesBaseModel

Expand All @@ -36,6 +38,9 @@ class Task(ConfigBaseTaskSpecs, GraphItem):
inputs: list[Data] = field(default_factory=list)
outputs: list[Data] = field(default_factory=list)
wait_on: list[Task] = field(default_factory=list)
config_rootdir: Path | None = None
start_date: datetime | None = None
end_date: datetime | None = None

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
Expand All @@ -48,6 +53,9 @@ def __init_subclass__(cls, **kwargs):
def from_config(
cls,
config: ConfigTask,
config_rootdir: Path,
start_date: datetime | None,
end_date: datetime | None,
coordinates: dict[str, Any],
datastore: Store,
graph_spec: ConfigCycleTask,
Expand All @@ -64,7 +72,10 @@ def from_config(
raise ValueError(msg)

new = plugin_cls(
config_rootdir=config_rootdir,
coordinates=coordinates,
start_date=start_date,
end_date=end_date,
inputs=inputs,
outputs=outputs,
**cls_config,
Expand Down
8 changes: 7 additions & 1 deletion src/sirocco/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ def iter_coordinates(param_refs: list, date: datetime | None = None) -> Iterator

for coordinates in iter_coordinates(param_refs=task_config.parameters, date=date):
task = Task.from_config(
config=task_config, coordinates=coordinates, datastore=self.data, graph_spec=task_graph_spec
config=task_config,
config_rootdir=workflow_config.rootdir,
start_date=cycle_config.start_date,
end_date=cycle_config.end_date,
coordinates=coordinates,
datastore=self.data,
graph_spec=task_graph_spec,
)
self.tasks.add(task)
cycle_tasks.append(task)
Expand Down
3 changes: 3 additions & 0 deletions src/sirocco/parsing/_yaml_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def get_plugin_from_named_base_model(data: dict) -> str:

class ConfigWorkflow(BaseModel):
name: str | None = None
rootdir: Path | None = None
cycles: list[ConfigCycle]
tasks: list[ConfigTask]
data: ConfigData
Expand Down Expand Up @@ -447,4 +448,6 @@ def load_workflow_config(workflow_config: str) -> ConfigWorkflow:
if parsed_workflow.name is None:
parsed_workflow.name = config_path.stem

parsed_workflow.rootdir = config_path.resolve().parent

return parsed_workflow
1 change: 1 addition & 0 deletions src/sirocco/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def format_task(self, obj: core.Task) -> str:
repr_attrs.remove("inputs")
repr_attrs.remove("outputs")
repr_attrs.remove("wait_on")
repr_attrs.remove("config_rootdir")

for attr_name in repr_attrs:
attr = getattr(obj, attr_name)
Expand Down
File renamed without changes.

Large diffs are not rendered by default.

File renamed without changes.

Large diffs are not rendered by default.

Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ cycles:
- icon_restart [date: 2026-01-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 1, 1, 0, 0)}
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
command: '$PWD/tests/files/scripts/icon.py'
cli arguments: positional=None keyword={'--restart': 'icon_restart'} flags=None source_file=None
Expand All @@ -20,6 +22,8 @@ cycles:
- icon_restart [date: 2026-03-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 3, 1, 0, 0)}
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
command: '$PWD/tests/files/scripts/icon.py'
cli arguments: positional=None keyword={'--restart': 'icon_restart'} flags=None source_file=None
Expand All @@ -33,6 +37,8 @@ cycles:
- icon_restart [date: 2026-05-01 00:00:00]
name: 'icon'
coordinates: {'date': datetime.datetime(2026, 5, 1, 0, 0)}
start date: 2026-01-01 00:00:00
end date: 2026-06-01 00:00:00
plugin: 'shell'
command: '$PWD/tests/files/scripts/icon.py'
cli arguments: positional=None keyword={'--restart': 'icon_restart'} flags=None source_file=None
Expand Down
Empty file added tests/cases/small/svg/.gitkeep
Empty file.
8 changes: 4 additions & 4 deletions tests/test_wc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def pprinter():


config_test_files = [
"tests/files/configs/test_config_small.yml",
"tests/files/configs/test_config_large.yml",
"tests/files/configs/test_config_parameters.yml",
"tests/cases/small/config/test_config_small.yml",
"tests/cases/large/config/test_config_large.yml",
"tests/cases/parameters/config/test_config_parameters.yml",
]


Expand All @@ -25,7 +25,7 @@ def config_paths(request):
return {
"yml": config_path,
"txt": (config_path.parent.parent / "data" / config_path.name).with_suffix(".txt"),
"svg": (config_path.parent.parent / "svgs" / config_path.name).with_suffix(".svg"),
"svg": (config_path.parent.parent / "svg" / config_path.name).with_suffix(".svg"),
}


Expand Down

0 comments on commit 5608e2e

Please sign in to comment.