Skip to content

Commit

Permalink
🐛📝 Make primary_fields unique and add typehints in example
Browse files Browse the repository at this point in the history
  • Loading branch information
Asthestarsfalll committed Jul 10, 2024
1 parent 8607f23 commit 6da1d7f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions example/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def excute(command: str, inputs=None):


def init():
excute("excore --install-completion")
excute("excore init --force", predefined_inputs.values())
cfg = toml.load("./.excore.toml")
cfg["registries"] = [
Expand All @@ -40,6 +41,7 @@ def init():
toml.dump(cfg, f)
excute("excore update")
excute("excore auto-register")
excute("excore generate-typehints temp_typing --config ./configs/run.toml")


if __name__ == "__main__":
Expand Down
8 changes: 8 additions & 0 deletions example/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

from excore import Registry, add_logger, config, logger

try:
from src.temp_typing import RunInfo, TypedModules
except ModuleNotFoundError as err:
raise RuntimeError("Run `python init.py` first!") from err

Registry.load()
MODELS = Registry.get_registry("Model")
print(MODELS)
Expand Down Expand Up @@ -35,6 +40,9 @@ def _check_func(values):
assert cfg.Optimizer == cfg.LRSche.CosDecay["optimizer"]
assert cfg.Model.FCN["backbone"] == cfg.Backbone
modules_dict, cfg_dict = config.build_all(cfg)
# `excore generate-typehints temp_typing --config ./configs/run.toml`
modules_dict: TypedModules
cfg: RunInfo
assert id(modules_dict.Optimizer) == id(modules_dict.LRSche.optimizer)
assert id(modules_dict.Model.backbone) == id(modules_dict.Backbone)
assert modules_dict.Model.head.timer == time
Expand Down
9 changes: 6 additions & 3 deletions excore/cli/_extention.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from typing import Optional

from typer import Argument as CArg
from typer import Option as COp
Expand All @@ -25,7 +26,7 @@ def config_extention():
_generate_json_schema_and_class_mapping(_workspace_cfg["json_schema_fields"])


def _generate_typehints(entry: str, class_name: str, info_class_name: str, config: str):
def _generate_typehints(entry: str, class_name: str, info_class_name: str, config: Optional[str]):
if not _workspace_cfg["primary_fields"]:
logger.critical("Please initialize the workspace first.")
return
Expand All @@ -52,10 +53,12 @@ def _generate_typehints(entry: str, class_name: str, info_class_name: str, confi

@app.command()
def generate_typehints(
entry: Annotated[str, CArg(help="The file to generate.")] = "types",
entry: Annotated[str, CArg(help="The file to generate.")] = "module_types",
class_name: Annotated[str, COp(help="The class name of type hints.")] = "TypedModules",
info_class_name: Annotated[str, COp(help="The class name of run_info.")] = "RunInfo",
config: Annotated[str, COp(help="Used generate type hints for isolated objects.")] = None,
config: Annotated[
Optional[str], COp(help="Used generate type hints for isolated objects.")
] = None,
):
"""
Generate type hints for modules and isolated objects.
Expand Down
2 changes: 1 addition & 1 deletion excore/cli/_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _parse_registries(reg_and_fields):
rev[j] = i[0]
targets.extend(tar)
json_schema["isolated_fields"] = isolated_fields
return targets, rev, json_schema
return set(targets), rev, json_schema


def _get_registries(reg_and_fields):
Expand Down

0 comments on commit 6da1d7f

Please sign in to comment.