Skip to content

Commit

Permalink
ref: move cycle date iterator from parsing to core
Browse files Browse the repository at this point in the history
  • Loading branch information
leclairm committed Nov 7, 2024
1 parent 2868b0e commit 48bb377
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/sirocco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
ConfigCycleTaskInput,
ConfigTask,
ConfigWorkflow,
_DataBaseModel,
load_workflow_config,
)

if TYPE_CHECKING:
from collections.abc import Iterator
from datetime import datetime
from sirocco.parsing._yaml_data_models import ConfigCycle, _DateBaseModel


logging.basicConfig()
Expand Down Expand Up @@ -259,7 +259,7 @@ def __init__(self, workflow_config: ConfigWorkflow) -> None:

# 2 - create output data nodes
for cycle_config in workflow_config.cycles:
for date in cycle_config.dates():
for date in self.cycle_dates(cycle_config):
for task_ref in cycle_config.tasks:
for data_ref in task_ref.outputs:
data_name = data_ref.name
Expand All @@ -269,7 +269,7 @@ def __init__(self, workflow_config: ConfigWorkflow) -> None:
# 3 - create cycles and tasks
for cycle_config in workflow_config.cycles:
cycle_name = cycle_config.name
for date in cycle_config.dates():
for date in self.cycle_dates(cycle_config):
cycle_tasks = []
for task_ref in cycle_config.tasks:
task_name = task_ref.name
Expand All @@ -284,6 +284,12 @@ def __init__(self, workflow_config: ConfigWorkflow) -> None:
for task in self.tasks.values():
task.link_wait_on_tasks()

def cycle_dates(self, cycle_config: ConfigCycle) -> Iterator[datetime]:
yield (date := cycle_config.start_date)
if cycle_config.period is not None:
while (date := date + cycle_config.period) < cycle_config.end_date:
yield date

def _str_from_method(self, method_name: Literal["__str__", "_str_pretty_"]) -> str:
str_method = getattr(NodeStr, method_name)
ind = ""
Expand Down
6 changes: 0 additions & 6 deletions src/sirocco/parsing/_yaml_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,6 @@ def check_period_is_not_negative_or_zero(self) -> ConfigCycle:
raise ValueError(msg)
return self

def dates(self) -> Iterator[datetime]:
yield (date := self.start_date)
if self.period is not None:
while (date := date + self.period) < self.end_date:
yield date


class ConfigWorkflow(BaseModel):
name: str | None = None
Expand Down

0 comments on commit 48bb377

Please sign in to comment.