From 73cc3ace24762a6148bb86c07179da6ae29c63cb Mon Sep 17 00:00:00 2001 From: zhouhy Date: Sun, 4 Jan 2026 19:49:18 +0800 Subject: [PATCH 1/3] fix readme, add pip install --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index b411b9f..0161a39 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,11 @@ A Python library for hierarchical configuration management with inheritance, cro ## Installation +``` +pip install configurize +``` + +for development ```bash pip install . ``` From 7e117be71f95bd47f0a096d853424e8f1c3cc9ba Mon Sep 17 00:00:00 2001 From: zhouhy Date: Tue, 6 Jan 2026 11:33:16 +0800 Subject: [PATCH 2/3] feat: add TaskSpec --- configurize/__init__.py | 2 +- configurize/config.py | 46 ++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/configurize/__init__.py b/configurize/__init__.py index dc92b7e..a8ab5ef 100644 --- a/configurize/__init__.py +++ b/configurize/__init__.py @@ -1,5 +1,5 @@ from .allowed_types import ALLOWED_TYPES, recur_to_allowed_types -from .config import Config, ConfigDiff, config_diff +from .config import Config, ConfigDiff, TaskSpec, config_diff from .data_class import DataClass from .reference import Ref from .utils import writable_property diff --git a/configurize/config.py b/configurize/config.py index a9ce817..57f7f48 100644 --- a/configurize/config.py +++ b/configurize/config.py @@ -5,7 +5,7 @@ import weakref from contextlib import contextmanager from functools import partial -from typing import Any, Callable +from typing import Any, Callable, TypedDict from loguru import logger @@ -15,6 +15,22 @@ from .utils import get_func_brief, writable_property +class TaskSpec(TypedDict, total=False): + """Indicate resource & entrypoint for specific task. + Below attributes DO NOT need default value if not set. + """ + + # Override corresponding fields in ResourceConfig if set + replica: int + """Number of replica(nodes) this task should run on.""" + command: str + """Entrypoint for this task. e.g. 'redis-server --port 12345'""" + envs: dict[str, Any] + """Environment variables for this task.""" + image: str + """Docker image for this task. Optional.""" + + class Config(DataClass): """Base Config Type, like dataclass, extra support: - config.sub_config = SubConfig() @@ -71,9 +87,8 @@ class Config(DataClass): - key2 must same as in expected_cfg[key2] if it exists in expected_cfg. """ - task_specs: dict[str, dict] - """If set, this module requires an individual sub-task. Adding this should be equal to add task to - ResourceConfig.task_specs + task_specs: dict[str, TaskSpec] + """If set, this module requires somes individual entrypoints. """ @writable_property @@ -105,6 +120,16 @@ def root(self) -> "Config": def assert_critical_attrs_expected( self, expected_cfg: "dict | Config", cum_errs: list = None ): + """Recursively compare self with another 'expected_cfg', raise error + if any of 'critical_keys' mismatches. + + Args: + expected_cfg (dict | Config): The reference config, NOTE: only critical_keys of + THIS(self) config will be checked. + + Raises: + Exception: raise all mismatch keys. + """ errs = [] # hold error and raise together # recursive check sub nodes for k, v in self.items(): @@ -150,13 +175,6 @@ def assert_critical_attrs_expected( text = "\n".join(text) raise Exception(f"{text}\nAttributes Check Fail!") - def _ensure_exp_args_parsed(self): - """Ensure CLI overrides are applied by running update_from_args once.""" - root = self.root() - updater = getattr(root, "update_from_args", None) - if callable(updater): - updater() - def _deref(self, name, value, deref=True): if isinstance(value, Ref): try: @@ -235,7 +253,7 @@ def __setattr__(self, name: str, value: Any) -> None: self._set_attribute_traces[name].append((value, caller_info, defined)) return super().__setattr__(name, value) - def _all_set_history(self): + def _all_set_history(self) -> dict[str, list[tuple[Any, str, bool]]]: history = {} if self._set_attribute_traces: for k, trace in self._set_attribute_traces.items(): @@ -246,6 +264,10 @@ def _all_set_history(self): return history def __init__(self, **kwargs): + """ + 1. set kwargs on self. + 2. build all my sub-configs. + """ self._merge_args(kwargs) for k, v in self.items(deref=False): From 1eb3376fa483a457a990b9a0c6c729862e680565 Mon Sep 17 00:00:00 2001 From: zhouhy Date: Tue, 6 Jan 2026 11:36:25 +0800 Subject: [PATCH 3/3] clean --- README.md | 2 +- configurize/config.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0161a39..3808fe8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Python library for hierarchical configuration management with inheritance, cro ## Installation -``` +```bash pip install configurize ``` diff --git a/configurize/config.py b/configurize/config.py index 57f7f48..0c78bb3 100644 --- a/configurize/config.py +++ b/configurize/config.py @@ -20,7 +20,6 @@ class TaskSpec(TypedDict, total=False): Below attributes DO NOT need default value if not set. """ - # Override corresponding fields in ResourceConfig if set replica: int """Number of replica(nodes) this task should run on.""" command: str