Skip to content

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 10, 2023
1 parent 7f3ba32 commit fd073f3
Show file tree
Hide file tree
Showing 32 changed files with 276 additions and 183 deletions.
25 changes: 11 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace


- repo: https://github.com/pycqa/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
- id: isort
name: isort (python)

- id: ruff
# - id: ruff-format

- repo: https://github.com/PyCQA/flake8
rev: '6.0.0'
rev: '6.1.0'
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8-pytest-style==1.6
- flake8-noqa==1.3
- flake8-bugbear==23.9.16
- flake8-comprehensions==3.14.0
- flake8-pytest-style==1.7.2
- pep8-naming==0.13.3


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

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
64 changes: 64 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

line-length = 120
indent-width = 4

target-version = "py38"

# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports
ignore-init-module-imports = true
src = ["src", "test"]
extend-exclude = ["__init__.py"]

select = [
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up

"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
"TCH", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch
"TD", # https://docs.astral.sh/ruff/rules/#flake8-todos-td

"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
"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
]

ignore = [
"RET501" # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
]


[format]
# Use single quotes for non-triple-quoted strings.
quote-style = "single"


[lint.isort]
known-local-folder = ["easyconfig"]
known-first-party = ["tests", "helper"]


[lint.flake8-builtins]
builtins-ignorelist = ["id"]


[lint.per-file-ignores]
"docs/conf.py" = ["INP001", "A001"]
"setup.py" = ["PTH123"]
9 changes: 6 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
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, os.path.join(os.path.abspath('..'), 'src'))
sys.path.insert(0, str(src_folder))

import easyconfig # noqa: E402

# -- Project information -----------------------------------------------------
project = 'easyconfig'
copyright = '2022, spacemanspiff2007'
copyright = '2023, 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 == 6.2.1
sphinx-autodoc-typehints == 1.23.0
sphinx_rtd_theme == 1.2.2
sphinx == 7.2.6
sphinx-autodoc-typehints == 1.25.0
sphinx_rtd_theme == 1.3.0
sphinx-exec-code == 0.10
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.1 (2023-11-10)
- Updated dependencies and code linters

#### 0.3.0 (2023-03-17)
- Breaking: requires pydantic 2.0
- Added support for variable expansion through environment variables and docker secrets
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

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

# linter
ruff >= 0.1.5, < 0.2
2 changes: 1 addition & 1 deletion requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pydantic >= 2.0, < 3.0
pydantic-settings >= 2.0, < 3.0
ruamel.yaml >= 0.17, < 0.18
ruamel.yaml >= 0.17, < 0.19
typing-extensions >= 4.4, < 5
46 changes: 20 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def load_version() -> str:
version: typing.Dict[str, str] = {}
with open("src/easyconfig/__version__.py") as fp:
with open('src/easyconfig/__version__.py') as fp:
exec(fp.read(), version)
assert version['__version__'], version
return version['__version__']
Expand All @@ -26,44 +26,38 @@ def load_req() -> typing.List[str]:
readme = Path(__file__).with_name('readme.md')
long_description = ''
if readme.is_file():
with readme.open("r", encoding='utf-8') as fh:
with readme.open('r', encoding='utf-8') as fh:
long_description = fh.read()

setup(
name="easyconfig",
name='easyconfig',
version=__version__,
author="spaceman_spiff",
author='spaceman_spiff',
# author_email="",
description="Easy application configuration with yaml files",
keywords=[
'yaml',
'configuration',
'pydantic',
'settings',
'config'
],
description='Easy application configuration with yaml files',
keywords=['yaml', 'configuration', 'pydantic', 'settings', 'config'],
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/spacemanspiff2007/easyconfig",
long_description_content_type='text/markdown',
url='https://github.com/spacemanspiff2007/easyconfig',
project_urls={
'GitHub': 'https://github.com/spacemanspiff2007/easyconfig',
},
package_dir={'': 'src'},
package_data={'easyconfig': ["py.typed"]},
package_data={'easyconfig': ['py.typed']},
packages=find_packages('src', exclude=['tests*']),
install_requires=load_req(),
python_requires='>=3.8',
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries"
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Software Development :: Libraries',
],
)
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.0'
__version__ = '0.3.1'
30 changes: 16 additions & 14 deletions src/easyconfig/config_objs/app_config.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
from __future__ import annotations

from io import StringIO
from pathlib import Path
from typing import Optional, Tuple, Union

from pydantic import BaseModel
from typing_extensions import Self
from typing import TYPE_CHECKING

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

from ..errors import FileDefaultsNotSetError
from .object_config import ConfigObj
if TYPE_CHECKING:
from pydantic import BaseModel
from typing_extensions import Self


class AppConfig(ConfigObj):
def __init__(self, model: BaseModel, path: Tuple[str, ...] = ('__root__',),
parent: Union[MISSING_TYPE, Self] = MISSING):
def __init__(self, model: BaseModel, path: tuple[str, ...] = ('__root__',), parent: MISSING_TYPE | Self = MISSING):
super().__init__(model, path, parent)

self._file_defaults: Optional[BaseModel] = None
self._file_path: Optional[Path] = None
self._file_defaults: BaseModel | None = None
self._file_path: Path | None = None

def set_file_path(self, path: Union[Path, str]):
def set_file_path(self, path: Path | str):
"""Set the path to the configuration file.
If no file extension is specified ``.yml`` will be automatically appended.
Expand All @@ -30,7 +31,8 @@ def set_file_path(self, path: Union[Path, str]):
if isinstance(path, str):
path = Path(path)
if not isinstance(path, Path):
raise ValueError(f'Path to configuration file not of type Path: {path} ({type(path)})')
msg = f'Path to configuration file not of type Path: {path} ({type(path)})'
raise TypeError(msg)

self._file_path = path.resolve()
if not self._file_path.suffix:
Expand All @@ -52,7 +54,7 @@ def load_config_dict(self, cfg: dict, /, expansion: bool = True):
self._set_values(model_obj)
return self

def load_config_file(self, path: Union[Path, str] = None, expansion: bool = True):
def load_config_file(self, path: Path | str | None = None, expansion: bool = True):
"""Load configuration from a yaml file. If the file does not exist a default file will be created
:param path: Path to file
Expand Down
Loading

0 comments on commit fd073f3

Please sign in to comment.