diff --git a/hworker/config/__init__.py b/hworker/config/__init__.py index 438a7bd..6a0a860 100755 --- a/hworker/config/__init__.py +++ b/hworker/config/__init__.py @@ -15,6 +15,7 @@ default_name: Final = "default_hworker" extension: Final = ".toml" profile: list = [] +DAY_START = 6 # Additinal 6 hours for day to start after 6:00AM ☺ def read_from_path(path: Path) -> dict: @@ -58,18 +59,25 @@ def process_configs(user_config: str, *extras: str) -> Path: return finalpath -def expand_macro(content: dict, parent=str) -> None: - """Expand "`f-string`" fields +def expand_macro(content: dict, parent: str = "") -> None: + """Expand "`f-string`" fields and unify dates :param content: currnet section content :param parent: parnet section name :return: """ for key, value in content.items(): - if isinstance(value, dict): - expand_macro(value, key) - if isinstance(value, str) and value[0] == value[-1] == "`": - content[key] = value[1:-1].format(**content | {"SELF": key, "PARENT": parent}) + match value: + case dict(): + expand_macro(value, key) + case datetime.datetime(): + pass + case datetime.date(): + content[key] = datetime.datetime.combine(value, datetime.time(DAY_START)) + case str() if "`" in value: + res = value.split("`") + res[1::2] = [r.format(**content | {"SELF": key, "PARENT": parent}) for r in res[1::2]] + content[key] = "".join(res) def config() -> dict: diff --git a/tests/test_config.py b/tests/test_config.py index bf769bc..69866d3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -18,6 +18,7 @@ get_task_info, create_config, no_merge_processing, + DAY_START, ) from .user_config import user_config @@ -65,10 +66,10 @@ def test_task_info(self, user_config): "resource_limit": 3145728, "time_limit": 2, "deliver_ID": "20230101/01", - "hard_deadline": datetime(2023, 1, 14, 0, 0), + "hard_deadline": datetime(2023, 1, 14, DAY_START, 0), "hard_deadline_delta": "open_date+13d", - "open_date": datetime(2023, 1, 1, 0, 0), - "soft_deadline": datetime(2023, 1, 7, 0, 0), + "open_date": datetime(2023, 1, 1, DAY_START, 0), + "soft_deadline": datetime(2023, 1, 7, DAY_START, 0), "soft_deadline_delta": "open_date+6d", }