Skip to content

Commit

Permalink
migrate to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
narumiruna committed Feb 5, 2024
1 parent e2f6230 commit 4355b3b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 193 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ install:
poetry install

lint:
poetry run flake8 -v
poetry run ruff check .

test:
poetry run pytest -v -s --cov=mlconfig tests

publish:
poetry build -f wheel
poetry publish

.PHONY: lint test publish
12 changes: 6 additions & 6 deletions mlconfig/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from omegaconf import OmegaConf

_REGISTRY = {}
_KEY_OF_FUNC_OR_CLS = "name"
_registry = {}
_key = "name"


def load(f=None, obj=None) -> OmegaConf:
Expand Down Expand Up @@ -50,8 +50,8 @@ def _register(func_or_cls, name=None):
if name is None:
name = func_or_cls.__name__

if name not in _REGISTRY:
_REGISTRY[name] = func_or_cls
if name not in _registry:
_registry[name] = func_or_cls
else:
raise ValueError("duplicate name {} found".format(name))

Expand All @@ -64,14 +64,14 @@ def _register(func_or_cls, name=None):


def getcls(conf):
return _REGISTRY[conf[_KEY_OF_FUNC_OR_CLS]]
return _registry[conf[_key]]


def instantiate(conf, *args, **kwargs):
kwargs = copy.deepcopy(kwargs)

for k, v in conf.items():
if k not in kwargs and k != _KEY_OF_FUNC_OR_CLS:
if k not in kwargs and k != _key:
kwargs[k] = v

func_or_cls = getcls(conf)
Expand Down
210 changes: 28 additions & 182 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4355b3b

Please sign in to comment.