From 58a489383af6d04c0721b4ef4928d32c2c41c6c3 Mon Sep 17 00:00:00 2001 From: Krzysztof Magusiak Date: Thu, 9 May 2024 13:19:42 +0200 Subject: [PATCH] Update todo and format --- .flake8 | 4 ++-- .gitignore | 3 +-- alphaconf/inject.py | 4 ++-- alphaconf/internal/configuration.py | 9 +++------ example-inv.py | 1 + example-plumbum.py | 1 - pyproject.toml | 2 +- requirements.txt | 6 +++--- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.flake8 b/.flake8 index 74877bf..4b4318d 100644 --- a/.flake8 +++ b/.flake8 @@ -5,7 +5,7 @@ # E123,E133: ignored by default by pep8, so we ignore them here # E203: space before comma, not pep8 compliant # E241,E242: spacing after a comma - not used -# F401: module imported but unused +# E701,E704: multiple statements on one line - handled by black # F812: list comprehension redefines name # W503: line break before operator - ignored as W504 is in pep8 # * Documentation (https://pep257.readthedocs.io/en/latest/error_codes.html) @@ -15,7 +15,7 @@ # D205: 1 blank line required between summary line and description # D210: no whitespaces allowed surrounding docstring text - not used # D400: first line should end with a period -ignore = C901,E123,E133,E203,F812,W503,D102,D205,D400 +ignore = C901,E123,E133,E203,E701,E704,F812,W503,D102,D205,D400 max-line-length = 100 exclude = .venv,venv,.git max-complexity = 10 diff --git a/.gitignore b/.gitignore index 76075c1..56c4adc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ __pycache__ dist .ipynb_checkpoints *.egg-info -.mypy_cache -.pytest_cache +/*_cache diff --git a/alphaconf/inject.py b/alphaconf/inject.py index 7c8e93d..26de30d 100644 --- a/alphaconf/inject.py +++ b/alphaconf/inject.py @@ -52,8 +52,8 @@ def getter( ktype = next(type_from_annotation(ptype), None) if param is not None and param.default is not param.empty: xparam = param - return ( - lambda: xparam.default + return lambda: ( + xparam.default if (value := alphaconf.get(key, ktype, default=None)) is None and xparam.default is not xparam.empty else value diff --git a/alphaconf/internal/configuration.py b/alphaconf/internal/configuration.py index 083effd..b636920 100644 --- a/alphaconf/internal/configuration.py +++ b/alphaconf/internal/configuration.py @@ -55,8 +55,7 @@ def get( type: Type[T], *, default: Union[T, RaiseOnMissingType] = raise_on_missing, - ) -> T: - ... + ) -> T: ... @overload def get( @@ -65,8 +64,7 @@ def get( type: Union[str, None] = None, *, default: Any = raise_on_missing, - ) -> Any: - ... + ) -> Any: ... @overload def get( @@ -75,8 +73,7 @@ def get( type: None = None, *, default: Union[T, RaiseOnMissingType] = raise_on_missing, - ) -> T: - ... + ) -> T: ... def get(self, key: Union[str, Type], type=None, *, default=raise_on_missing): """Get a configuation value and cast to the correct type""" diff --git a/example-inv.py b/example-inv.py index fc9460e..cdd40db 100644 --- a/example-inv.py +++ b/example-inv.py @@ -16,4 +16,5 @@ def doit(ctx, param=None): # add some default configuration and run/configure invoke's namespace alphaconf.setup_configuration({'backup': 'all'}) +# TODO just setup logging and load variables into ns? alphaconf.invoke.run(__name__, globals()) diff --git a/example-plumbum.py b/example-plumbum.py index 90b393c..cb415c2 100755 --- a/example-plumbum.py +++ b/example-plumbum.py @@ -13,7 +13,6 @@ @app.command() def main(): """Simple demo of alphaconf with plumbum""" - log = logging.getLogger(__name__) cmd = plumbum.local[alphaconf.get("cmd")] log.info("Running a command %s", cmd) diff --git a/pyproject.toml b/pyproject.toml index 3109fe6..e90049a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ dynamic = ["version"] description = "Write simple scripts leveraging omegaconf" readme = "README.md" keywords = ["configuration", "omegaconf", "pydantic", "script"] -license = {text = "BSD License"} +license = {file = "LICENSE"} requires-python = ">=3.9" classifiers = [ # https://pypi.org/pypi?%3Aaction=list_classifiers diff --git a/requirements.txt b/requirements.txt index a0fcc0b..62860de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ # Build tools setuptools setuptools_scm -black -flake8 -isort +black>=22 +flake8>=7 +isort>=5 mypy pytest types-toml