Skip to content

Commit

Permalink
note todo and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Jan 27, 2025
1 parent 822ca83 commit 7e6e0a7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
22 changes: 10 additions & 12 deletions src/sirocco/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,19 @@
class Workflow:
"""Internal representation of a workflow"""

def __init__(self,
name: str,
rootdir: Path,
cycles: list[ConfigCycle],
tasks: list[ConfigTask],
data: ConfigData,
parameters: dict[str, list],
) -> None:

def __init__(
self,
name: str,
rootdir: Path,
cycles: list[ConfigCycle],
tasks: list[ConfigTask],
data: ConfigData,
parameters: dict[str, list],
) -> None:
self.name: str = name
if not isinstance(rootdir, Path):
msg = f"Need to provide path for rootdir but got {type(rootdir)}"
raise TypeError(msg)
# TODO rename to rootdir since it does not make sense with this constructor
self.config_rootdir: Path = rootdir

self.tasks: Store = Store()
Expand Down Expand Up @@ -104,6 +103,7 @@ def iter_coordinates(param_refs: list, date: datetime | None = None) -> Iterator
@staticmethod
def _build_data_dict(data: ConfigData) -> dict[str, ConfigAvailableData | ConfigGeneratedData]:
return {data.name: data for data in chain(data.available, data.generated)}

@staticmethod
def _build_tasks_dict(tasks: list[ConfigTask]) -> dict[str, ConfigTask]:
return {task.name: task for task in tasks}
Expand All @@ -115,7 +115,6 @@ def cycle_dates(cycle_config: ConfigCycle) -> Iterator[datetime]:
while (date := date + cycle_config.period) < cycle_config.end_date:
yield date

# TODO to be more consistent with `ConfigWorkflow` I would rename `from_yaml` to `from_config_file`, in a separate PR/commit, what you think?
@classmethod
def from_yaml(cls: type[Self], config_filename: str) -> Self:
"""
Expand All @@ -125,7 +124,6 @@ def from_yaml(cls: type[Self], config_filename: str) -> Self:
"""
return cls.from_config_workflow(ConfigWorkflow.from_config_file(config_filename))


@classmethod
def from_config_workflow(cls: type[Self], config_workflow: ConfigWorkflow) -> Workflow:
return cls(
Expand Down
4 changes: 3 additions & 1 deletion src/sirocco/parsing/_yaml_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@

from sirocco.parsing._utils import TimeUtils

# TODO if the type is not specified why bother specifying it? Isn't list[ITEM_T] similar useful for type checking as list at the moment?
ITEM_T = typing.TypeVar("ITEM_T")


def list_not_empty(value: list[ITEM_T]) -> list[ITEM_T]:
if len(value) < 1:
msg = "At least one element is required."
raise ValueError(msg)
return value


class _NamedBaseModel(BaseModel):
"""Base class for all classes with a key that specifies their name.
Expand Down Expand Up @@ -514,6 +515,7 @@ def get_plugin_from_named_base_model(
Discriminator(get_plugin_from_named_base_model),
]


class ConfigWorkflow(BaseModel):
"""
The root of the configuration tree.
Expand Down
1 change: 0 additions & 1 deletion tests/test_wc_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def config_paths(request):

def test_parse_config_file(config_paths, pprinter):
reference_str = config_paths["txt"].read_text()
# TODO to be more consistent with `ConfigWorkflow` I would rename `from_yaml` to `from_config_file`, in a separate PR/commit, what you think?
test_str = pprinter.format(Workflow.from_yaml(config_paths["yml"]))
if test_str != reference_str:
new_path = Path(config_paths["txt"]).with_suffix(".new.txt")
Expand Down

0 comments on commit 7e6e0a7

Please sign in to comment.