Skip to content

Commit

Permalink
0.3.2 (#73)
Browse files Browse the repository at this point in the history
* Update CI
* Ruff fixes
  • Loading branch information
spacemanspiff2007 committed Jan 10, 2024
1 parent fd073f3 commit 288ea3e
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 77 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ max-line-length = 120

exclude =
__init__.py
docs/conf.py

.git,
.tox,
11 changes: 6 additions & 5 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write

steps:
- uses: actions/checkout@v3
with:
ref: master
ref: main
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
Expand All @@ -27,7 +31,4 @@ jobs:
python setup.py sdist bdist_wheel
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_api_key }}
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 1 addition & 2 deletions .github/workflows/run_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ jobs:
python-version: '3.10'
- uses: pre-commit/action@v3.0.0


test:
needs: pre-commit
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
24 changes: 9 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace

Expand All @@ -14,23 +19,12 @@ repos:
- id: ruff
# - id: ruff-format

- repo: https://github.com/PyCQA/flake8
rev: '6.1.0'
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.9.16
- flake8-comprehensions==3.14.0
- flake8-pytest-style==1.7.2
- pep8-naming==0.13.3
- id: rst-backticks

- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
File renamed without changes.
33 changes: 22 additions & 11 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ select = [
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf

# "PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
# "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
"PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
]

ignore = [
"RET501" # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
"PLR1711", # https://docs.astral.sh/ruff/rules/useless-return/
]


Expand All @@ -50,15 +52,24 @@ ignore = [
quote-style = "single"


[lint.isort]
known-local-folder = ["easyconfig"]
known-first-party = ["tests", "helper"]
[lint.per-file-ignores]
"docs/*" = [
"A001", # A001 Variable `copyright` is shadowing a Python builtin
"E402", # E402 Module level import not at top of file
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
]

"tests/*" = [
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
"ISC002", # ISC002 Implicitly concatenated string literals over multiple lines
"PLR2004", # PLR2004 Magic value used in comparison, consider replacing 5 with a constant variable
]

[lint.flake8-builtins]
builtins-ignorelist = ["id"]
"setup.py" = ["PTH123"]
"src/easyconfig/yaml/from_model.py" = ["PLR0911"] # PLR0911 Too many return statements (7 > 6)


[lint.per-file-ignores]
"docs/conf.py" = ["INP001", "A001"]
"setup.py" = ["PTH123"]

[lint.isort]
# https://docs.astral.sh/ruff/settings/#isort-lines-after-imports
lines-after-imports = 2
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
import sys
from pathlib import Path


src_folder = Path(__file__).parent.with_name('src')
assert src_folder.is_dir()

# required for autodoc
sys.path.insert(0, str(src_folder))

import easyconfig # noqa: E402
import easyconfig


# -- Project information -----------------------------------------------------
project = 'easyconfig'
copyright = '2023, spacemanspiff2007'
copyright = '2024, spacemanspiff2007'
author = 'spacemanspiff2007'

# The full version, including alpha/beta/rc tags
Expand Down
6 changes: 3 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Packages required to build the documentation
sphinx == 7.2.6
sphinx-autodoc-typehints == 1.25.0
sphinx_rtd_theme == 1.3.0
sphinx-exec-code == 0.10
sphinx-autodoc-typehints == 1.25.2
sphinx_rtd_theme == 2.0.0
sphinx-exec-code == 0.12
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ That way the users can have some guidance how to change the program behaviour.
It's possible to use environment variable or files for expansion. Easyconfig will load all values

# Changelog
#### 0.3.2 (2024-01-10)
- Updated CI and code linters

#### 0.3.1 (2023-11-10)
- Updated dependencies and code linters

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-r requirements_setup.txt

# testing dependencies
pytest >= 7.4, < 8
pre-commit >= 3.5, < 4
pytest == 7.4.4
pre-commit == 3.5.0

# linter
ruff >= 0.1.5, < 0.2
ruff == 0.1.11
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def load_req() -> typing.List[str]:
print(f'Version: {__version__}')
print('')

# When we run tox tests we don't have these files available so we skip them
# When we run tox tests we don't have these files available, so we skip them
readme = Path(__file__).with_name('readme.md')
long_description = ''
if readme.is_file():
Expand All @@ -35,7 +35,7 @@ def load_req() -> typing.List[str]:
author='spaceman_spiff',
# author_email="",
description='Easy application configuration with yaml files',
keywords=['yaml', 'configuration', 'pydantic', 'settings', 'config'],
keywords=['yaml', 'configuration', 'pydantic', 'settings', 'config', 'yml'],
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/spacemanspiff2007/easyconfig',
Expand All @@ -57,6 +57,7 @@ def load_req() -> typing.List[str]:
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Software Development :: Libraries',
],
Expand Down
2 changes: 1 addition & 1 deletion src/easyconfig/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.1'
__version__ = '0.3.2'
5 changes: 3 additions & 2 deletions src/easyconfig/config_objs/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
from pathlib import Path
from typing import TYPE_CHECKING

from ..errors import FileDefaultsNotSetError
from .object_config import ConfigObj
from easyconfig.__const__ import MISSING, MISSING_TYPE
from easyconfig.config_objs.object_config import ConfigObj
from easyconfig.errors import FileDefaultsNotSetError
from easyconfig.expansion import expand_obj
from easyconfig.yaml import CommentedMap, cmap_from_model, write_aligned_yaml, yaml_rt


if TYPE_CHECKING:
from pydantic import BaseModel
from typing_extensions import Self
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/config_objs/object_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from easyconfig.config_objs import ConfigObjSubscription, SubscriptionParent
from easyconfig.errors import DuplicateSubscriptionError, FunctionCallNotAllowedError


if TYPE_CHECKING:
from pydantic.fields import FieldInfo

Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/config_objs/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from easyconfig.errors import SubscriptionAlreadyCanceledError


if TYPE_CHECKING:
import easyconfig

Expand Down
5 changes: 3 additions & 2 deletions src/easyconfig/create_app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from easyconfig.config_objs.app_config import AppConfig, yaml_rt
from easyconfig.errors import ExtraKwArgsNotAllowedError


TYPE_WRAPPED = TypeVar('TYPE_WRAPPED', bound=BaseModel)
TYPE_DEFAULTS = Union[BaseModel, Dict[str, Any]]

Expand Down Expand Up @@ -37,7 +38,7 @@ def check_field_args(model: AppConfig, allowed: FrozenSet[str]):


def get_file_values(
model: TYPE_WRAPPED, file_values: Union[MISSING_TYPE, None, TYPE_DEFAULTS, Callable[[], TYPE_DEFAULTS]] = MISSING
model: BaseModel, file_values: Union[MISSING_TYPE, None, TYPE_DEFAULTS, Callable[[], TYPE_DEFAULTS]] = MISSING
) -> Optional[BaseModel]:
# Implicit default
if file_values is MISSING:
Expand All @@ -49,7 +50,7 @@ def get_file_values(

# dict -> build models
if isinstance(file_values, dict):
file_values = model.__class__.parse_obj(file_values)
file_values = model.model_validate(file_values)

if file_values is not None and not isinstance(file_values, BaseModel):
msg = f'Default must be None or an instance of {BaseModel.__class__.__name__}! Got {type(file_values)}'
Expand Down
2 changes: 1 addition & 1 deletion src/easyconfig/errors/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def default_exception_handler(e: Exception):


def set_exception_handler(handler: Callable[[Exception], Any]):
global HANDLER
global HANDLER # noqa: PLW0603
HANDLER = handler


Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .load_var import read_env_var
from .location import ExpansionLocation


RE_REPLACE = re.compile(r'''
(?<!\$)\$\{
(?P<value>.*?[^$])?
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/load_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .location import ExpansionLocation, log


# https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
RE_WIN_PATH = re.compile(
r'''
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/expansion/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from easyconfig.errors.errors import CyclicEnvironmentVariableReferenceError


log = logging.getLogger('easyconfig.expansion')


Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from easyconfig.models.config import ConfigMixin


if TYPE_CHECKING:
from pathlib import Path

Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from easyconfig.errors import FunctionCallNotAllowedError


if TYPE_CHECKING:
import easyconfig
import easyconfig.config_objs
Expand Down
2 changes: 1 addition & 1 deletion src/easyconfig/yaml/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def remove_none(obj: Union[dict]):
remove_none(value)
if not value:
rem.append(index)
else:
else: # noqa: PLR5501
if value is None:
rem.append(index)

Expand Down
2 changes: 0 additions & 2 deletions src/easyconfig/yaml/from_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from easyconfig.__const__ import ARG_NAME_IN_FILE, MISSING
from easyconfig.yaml import CommentedMap, CommentedSeq

NoneType = type(None)


def _get_yaml_value(obj, parent_model: BaseModel, *, skip_none=True, obj_name: str | None = None):
if obj is None:
Expand Down
1 change: 1 addition & 0 deletions src/easyconfig/yaml/yaml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ruamel.yaml # type: ignore


yaml_rt = ruamel.yaml.YAML(typ='rt')
yaml_safe = ruamel.yaml.YAML(typ='safe')

Expand Down

0 comments on commit 288ea3e

Please sign in to comment.