Skip to content

Commit

Permalink
🐛 Remove order dependency (#40)
Browse files Browse the repository at this point in the history
* 🐛 Remove order dependency

* 🐛 update

* 🐛 fix registry error with pytest
  • Loading branch information
Asthestarsfalll authored Jul 15, 2024
1 parent e20f4f3 commit 9735c62
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 48 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ jobs:
- name: Test with pytest
run: |
cd ./tests
export EXCORE_DEBUG=1
poetry run python init.py
poetry run pytest --cov=../excore
poetry run pytest test_config.py
poetry run pytest test_config.py
poetry run pytest test_config.py
poetry run pytest test_config.py
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
7 changes: 4 additions & 3 deletions excore/config/lazy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, config: ConfigDict) -> None:
config.registered_fields = list(Registry._registry_pool.keys())
config.all_fields = set([*config.registered_fields, *config.primary_fields])
self._config = deepcopy(config)
self._origin_config = deepcopy(config)
self._original_config = deepcopy(config)
self.__is_parsed__ = False

def parse(self):
Expand All @@ -27,10 +27,11 @@ def parse(self):
self._config.parse()
logger.success("Config parsing cost {:.4f}s!", time.time() - st)
self.__is_parsed__ = True
logger.ex(self._config)

@property
def config(self):
return self._origin_config
return self._original_config

def update(self, cfg: "LazyConfig"):
self._config.update(cfg._config)
Expand Down Expand Up @@ -75,7 +76,7 @@ def build_all(self) -> Tuple[ModuleWrapper, Dict]:
return module_dict, isolated_dict

def dump(self, dump_path: str) -> None:
self._origin_config.dump(dump_path)
self._original_config.dump(dump_path)

def __str__(self):
return str(self._config)
6 changes: 6 additions & 0 deletions excore/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _str_to_target(module_name):
class ModuleNode(dict):
cls: Any
_no_call: bool = field(default=False, repr=False)
priority: int = field(default=0, repr=False)

def _get_params(self, **kwargs):
params = {}
Expand Down Expand Up @@ -153,6 +154,7 @@ def from_node(cls, _other: "ModuleNode") -> "ModuleNode":


class InterNode(ModuleNode):
priority = 2
pass


Expand All @@ -165,12 +167,16 @@ def __call__(self, **kwargs):


class ReusedNode(InterNode):
priority: int = 3

@CacheOut()
def __call__(self, **kwargs):
return super().__call__(**kwargs)


class ClassNode(InterNode):
priority: int = 1

def __call__(self):
return self.cls

Expand Down
Loading

0 comments on commit 9735c62

Please sign in to comment.