diff --git a/docs/blog/2024-2-29-config-system-in-deeplearning.mdx b/docs/blog/2024-2-29-config-system-in-deeplearning.mdx index 222529c..a87dc33 100644 --- a/docs/blog/2024-2-29-config-system-in-deeplearning.mdx +++ b/docs/blog/2024-2-29-config-system-in-deeplearning.mdx @@ -328,7 +328,7 @@ model = modules.Model ExCore同样支持python形式的配置文件,与detectron2基本一致,不过实例化时只需调用`__call__`方法即可,如下: ```python -from excore.config.model import ModuleNode +from excore.config.models import ModuleNode from xxx import Module cfg = ModuleNode(Module) << dict(arg1=1, arg2=2) diff --git a/docs/docs/config/config_extention.mdx b/docs/docs/config/config_extention.mdx index 6323c64..5ff9e36 100644 --- a/docs/docs/config/config_extention.mdx +++ b/docs/docs/config/config_extention.mdx @@ -36,7 +36,7 @@ It will generate a python file named `types`: ```python from typing import Union, Any -from excore.config.model import ModuleNode, ModuleWrapper +from excore.config.models import ModuleNode, ModuleWrapper class ModuleType: Model: Union[ModuleNode, ModuleWrapper] diff --git a/docs/docs/config/node.mdx b/docs/docs/config/node.mdx index 4cdcb1d..570fc0c 100644 --- a/docs/docs/config/node.mdx +++ b/docs/docs/config/node.mdx @@ -11,7 +11,7 @@ title: Module nodes In fact, those nodes is called `LazyCall` in `detectron2`. Although the whole system is designed for toml file, but they still can be used in pure python configurations. For instance: ```python -from excore.config.model import ModuleNode +from excore.config.models import ModuleNode from xxx import Module cfg = ModuleNode(Module) << dict(arg1=1, arg2=2) @@ -54,7 +54,7 @@ Wrap the chained invocation of a node, for example: If we want to implement `ResNet().blocks.conv()`, we can use `ChainedInvocationWrapper` ```python -from excore.config.model import ModuleNode, ChainedInvocationWrapper +from excore.config.models import ModuleNode, ChainedInvocationWrapper from xxx import ResNet ChainedInvocationWrapper(ModuleNode(ResNet), ["blocks", "conv()"]) diff --git a/excore/cli/_extention.py b/excore/cli/_extention.py index f6ae725..dcea5cd 100644 --- a/excore/cli/_extention.py +++ b/excore/cli/_extention.py @@ -36,7 +36,7 @@ def _generate_typehints( logger.info(f"Generating module type hints in {target_file}.") with open(target_file, "w", encoding="UTF-8") as f: f.write(f"from typing import Union{', Any' if config else ''}\n") - f.write("from excore.config.model import ModuleNode, ModuleWrapper\n\n") + f.write("from excore.config.models import ModuleNode, ModuleWrapper\n\n") f.write(f"class {class_name}:\n") for i in workspace.primary_fields: f.write(f" {i}: Union[ModuleNode, ModuleWrapper]\n") diff --git a/excore/config/__init__.py b/excore/config/__init__.py index ec45f8b..7b0fb2c 100644 --- a/excore/config/__init__.py +++ b/excore/config/__init__.py @@ -1,6 +1,6 @@ from .action import DictAction from .config import build_all, load, load_config -from .model import ( +from .models import ( ChainedInvocationWrapper, ClassNode, InterNode, diff --git a/excore/config/_json_schema.py b/excore/config/_json_schema.py index 247535a..3ed7fcf 100644 --- a/excore/config/_json_schema.py +++ b/excore/config/_json_schema.py @@ -15,7 +15,7 @@ from ..engine.hook import ConfigArgumentHook from ..engine.logging import logger from ..engine.registry import Registry, load_registries -from .model import _str_to_target +from .models import _str_to_target if sys.version_info >= (3, 10, 0): from types import NoneType, UnionType # type: ignore diff --git a/excore/config/config.py b/excore/config/config.py index f457dca..554534e 100644 --- a/excore/config/config.py +++ b/excore/config/config.py @@ -10,7 +10,7 @@ from ..engine.logging import logger from ..engine.registry import load_registries from .lazy_config import LazyConfig -from .model import ModuleWrapper +from .models import ModuleWrapper from .parse import ConfigDict __all__ = ["load", "build_all", "load_config"] diff --git a/excore/config/lazy_config.py b/excore/config/lazy_config.py index a38a6c2..57d0fd5 100644 --- a/excore/config/lazy_config.py +++ b/excore/config/lazy_config.py @@ -7,7 +7,7 @@ from ..engine.hook import ConfigHookManager, Hook from ..engine.logging import logger from ..engine.registry import Registry -from .model import ConfigHookNode, InterNode, ModuleWrapper +from .models import ConfigHookNode, InterNode, ModuleWrapper from .parse import ConfigDict diff --git a/excore/config/model.py b/excore/config/models.py similarity index 98% rename from excore/config/model.py rename to excore/config/models.py index aaa07c4..b45abff 100644 --- a/excore/config/model.py +++ b/excore/config/models.py @@ -25,7 +25,7 @@ NoCallSkipFlag = Self ConfigHookSkipFlag = Type[None] - SpecialFlag = Literal["@", "!", "$", "&", ""] + SpecialFlag = Literal["@", "!", "$", "&", "*", ""] __all__ = ["silent"] @@ -34,6 +34,7 @@ INTER_FLAG: Literal["!"] = "!" CLASS_FLAG: Literal["$"] = "$" REFER_FLAG: Literal["&"] = "&" +DETAI_FLAG: Literal["*"] = "*" OTHER_FLAG: Literal[""] = "" LOG_BUILD_MESSAGE = True @@ -59,7 +60,7 @@ def _is_special(k: str) -> tuple[str, SpecialFlag]: Returns: Tuple[str, str]: A tuple containing the modified string and the special character. """ - pattern = re.compile(r"^([@!$&])(.*)$") + pattern = re.compile(r"^([@!$&*])(.*)$") match = pattern.match(k) if match: return match.group(2), match.group(1) # type: ignore @@ -169,7 +170,6 @@ def from_node(cls, _other: ModuleNode) -> ModuleNode: class InterNode(ModuleNode): priority = 2 - pass class ConfigHookNode(ModuleNode): diff --git a/excore/config/parse.py b/excore/config/parse.py index d09654e..5d85dc9 100644 --- a/excore/config/parse.py +++ b/excore/config/parse.py @@ -5,7 +5,7 @@ from .._exceptions import CoreConfigParseError, ImplicitModuleParseError from .._misc import _create_table from ..engine import Registry, logger -from .model import ( +from .models import ( OTHER_FLAG, REFER_FLAG, ChainedInvocationWrapper, @@ -23,7 +23,7 @@ from typing_extensions import Self - from .model import ConfigNode, NodeType, SpecialFlag + from .models import ConfigNode, NodeType, SpecialFlag def _check_implicit_module(module: ModuleNode) -> None: diff --git a/tests/test_config.py b/tests/test_config.py index 86d1875..28f4ebe 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -14,7 +14,7 @@ ImplicitModuleParseError, ModuleBuildError, ) -from excore.config.model import ModuleNode, ReusedNode +from excore.config.models import ModuleNode, ReusedNode from excore.engine import logger diff --git a/tests/test_model.py b/tests/test_model.py index e92f5ad..8aa2abc 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -1,6 +1,6 @@ import pytest -from excore.config.model import ModuleNode +from excore.config.models import ModuleNode def test_lshift(): diff --git a/tests/test_z_cli.py b/tests/test_z_cli.py index 6e21d43..df99726 100644 --- a/tests/test_z_cli.py +++ b/tests/test_z_cli.py @@ -27,7 +27,6 @@ def test_primary(): def test_typehints(): - # FIXME(typer): Argument excute( "excore generate-typehints temp_typing --class-name " "TypedWrapper --info-class-name Info --config ./configs/launch/test_optim.toml"