Skip to content

Commit bc16d39

Browse files
0.4.0 (#76)
1 parent 4d82405 commit bc16d39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1039
-265
lines changed

.github/workflows/publish-pypi.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
id-token: write
1414

1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
with:
1818
ref: master
19-
- name: Set up Python 3.10
20-
uses: actions/setup-python@v4
19+
- name: Set up Python 3.12
20+
uses: actions/setup-python@v5
2121
with:
22-
python-version: '3.10'
22+
python-version: '3.12'
2323

2424
- name: Install setuptools
2525
run: |

.github/workflows/run_tox.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ jobs:
77
name: pre-commit
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-python@v4
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v5
1212
with:
13-
python-version: '3.10'
14-
- uses: pre-commit/[email protected].0
13+
python-version: '3.12'
14+
- uses: pre-commit/[email protected].1
1515

1616
test:
1717
needs: pre-commit
1818
runs-on: ubuntu-latest
1919
strategy:
2020
max-parallel: 4
2121
matrix:
22-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
22+
python-version: ['3.10', '3.11', '3.12', '3.13']
2323

2424
steps:
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v4
27+
uses: actions/setup-python@v5
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030
- name: Install dependencies

.pre-commit-config.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-ast
66
- id: check-builtin-literals
@@ -13,17 +13,34 @@ repos:
1313
- id: trailing-whitespace
1414

1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
# Ruff version.
17-
rev: v0.1.5
16+
rev: v0.8.2
1817
hooks:
1918
- id: ruff
20-
# - id: ruff-format
19+
name: ruff unused imports
20+
# F401 [*] {name} imported but unused
21+
args: [ "--select", "F401", "--extend-exclude", "__init__.py", "--fix"]
22+
23+
- id: ruff
24+
# I001 [*] Import block is un-sorted or un-formatted
25+
# UP035 [*] Import from {target} instead: {names}
26+
# Q000 [*] Double quote found but single quotes preferred
27+
# Q001 [*] Double quote multiline found but single quotes preferred
28+
args: [ "--select", "I001,UP035,Q000,Q001", "--fix"]
29+
2130

2231
- repo: https://github.com/pre-commit/pygrep-hooks
2332
rev: v1.10.0
2433
hooks:
2534
- id: rst-backticks
2635

36+
- repo: https://github.com/JelleZijlstra/autotyping
37+
rev: 24.9.0
38+
hooks:
39+
- id: autotyping
40+
types: [python]
41+
args: [--safe]
42+
43+
2744
- repo: meta
2845
hooks:
2946
- id: check-hooks-apply

.ruff.toml

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,106 @@
1-
2-
line-length = 120
31
indent-width = 4
2+
line-length = 120
3+
4+
target-version = "py310"
45

5-
target-version = "py38"
6-
7-
# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports
8-
ignore-init-module-imports = true
9-
src = ["src", "test"]
10-
extend-exclude = ["__init__.py"]
11-
12-
select = [
13-
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
14-
"I", # https://docs.astral.sh/ruff/rules/#isort-i
15-
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
16-
17-
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
18-
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
19-
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
20-
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
21-
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
22-
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
23-
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
24-
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
25-
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
26-
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
27-
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
28-
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
29-
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
30-
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
31-
"TCH", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch
32-
"TD", # https://docs.astral.sh/ruff/rules/#flake8-todos-td
33-
34-
"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
35-
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
36-
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
37-
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
38-
39-
"PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
6+
src = [
7+
"src",
8+
"tests"
409
]
4110

11+
12+
[lint]
13+
select = ["ALL"]
14+
4215
ignore = [
43-
"A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/
16+
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
17+
"T20", # https://docs.astral.sh/ruff/rules/#flake8-print-t20
18+
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
19+
"SLF", # https://docs.astral.sh/ruff/rules/#flake8-self-slf
20+
4421
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
4522
"TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
46-
"PLR1711", # https://docs.astral.sh/ruff/rules/useless-return/
23+
24+
# https://docs.astral.sh/ruff/rules/#flake8-builtins-a
25+
"A003", # Python builtin is shadowed by class attribute {name} from {row}
26+
27+
# https://docs.astral.sh/ruff/rules/#pyflakes-f
28+
"F401", # {name} imported but unused; consider using importlib.util.find_spec to test for availability
29+
30+
# https://docs.astral.sh/ruff/rules/#flake8-bandit-s
31+
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
32+
33+
# https://docs.astral.sh/ruff/rules/#pyupgrade-up
34+
"UP038", # Use X | Y in {} call instead of (X, Y)
35+
36+
# https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
37+
"ANN101", # Missing type annotation for {name} in method
38+
"ANN102", # Missing type annotation for {name} in classmethod
39+
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {name}
40+
41+
# https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble
42+
"BLE001", # Do not catch blind exception: {name}
43+
44+
# https://docs.astral.sh/ruff/rules/#flake8-raise-rse
45+
"RSE102", # Unnecessary parentheses on raised exception
46+
47+
# https://docs.astral.sh/ruff/rules/#flake8-commas-com
48+
"COM812", # Trailing comma missing
49+
"COM819", # Trailing comma prohibited
50+
51+
# https://docs.astral.sh/ruff/rules/#warning-w_1
52+
"PLW0603", # Using the global statement to update {name} is discouraged
53+
54+
# https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
55+
"G004", # Logging statement uses f-string
56+
57+
# https://docs.astral.sh/ruff/rules/#refactor-r
58+
"PLR1711", # Useless return statement at end of function
59+
60+
# https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
61+
"RUF005", # Consider {expression} instead of concatenation
62+
63+
# https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
64+
"PT007", # Wrong values type in @pytest.mark.parametrize expected {values} of {row}
4765
]
4866

4967

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

5471

55-
[lint.per-file-ignores]
56-
"docs/*" = [
57-
"A001", # A001 Variable `copyright` is shadowing a Python builtin
58-
"E402", # E402 Module level import not at top of file
59-
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
60-
]
72+
# https://docs.astral.sh/ruff/settings/#lintflake8-quotes
73+
[lint.flake8-quotes]
74+
inline-quotes = "single"
75+
multiline-quotes = "single"
6176

62-
"tests/*" = [
63-
"INP001", # INP001 File `FILE_NAME` is part of an implicit namespace package. Add an `__init__.py`.
64-
"ISC002", # ISC002 Implicitly concatenated string literals over multiple lines
65-
"PLR2004", # PLR2004 Magic value used in comparison, consider replacing 5 with a constant variable
77+
78+
[lint.flake8-builtins]
79+
builtins-ignorelist = ["id", "input"]
80+
81+
82+
# https://docs.astral.sh/ruff/settings/#lintisort
83+
[lint.isort]
84+
lines-after-imports = 2 # https://docs.astral.sh/ruff/settings/#lint_isort_lines-after-imports
85+
86+
87+
[lint.per-file-ignores]
88+
"docs/conf.py" = [
89+
"INP001", # File `conf.py` is part of an implicit namespace package. Add an `__init__.py`.
90+
"A001", # Variable `copyright` is shadowing a Python builtin
91+
"PTH118", # `os.path.join()` should be replaced by `Path` with `/` operator
92+
"PTH100", # `os.path.abspath()` should be replaced by `Path.resolve()`
6693
]
6794

6895
"setup.py" = ["PTH123"]
69-
"src/easyconfig/yaml/from_model.py" = ["PLR0911"] # PLR0911 Too many return statements (7 > 6)
7096

97+
"tests/*" = [
98+
"ANN", # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
7199

100+
# https://docs.astral.sh/ruff/rules/#flake8-bandit-s
101+
"S101", # Use of assert detected
72102

73-
[lint.isort]
74-
# https://docs.astral.sh/ruff/settings/#isort-lines-after-imports
75-
lines-after-imports = 2
103+
# https://docs.astral.sh/ruff/rules/#refactor-r
104+
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
105+
"PLR0913", # Too many arguments in function definition ({c_args} > {max_args})
106+
]

docs/class_reference.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ Subscription
2222

2323
.. autoclass:: easyconfig.config_objs.ConfigObjSubscription
2424
:members:
25+
26+
27+
PreProcess
28+
======================================
29+
30+
.. autoclass:: easyconfig.pre_process.PreProcess
31+
:members:

docs/requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Packages required to build the documentation
2-
sphinx == 7.2.6
3-
sphinx-autodoc-typehints == 1.25.2
4-
sphinx_rtd_theme == 2.0.0
5-
sphinx-exec-code == 0.12
2+
sphinx == 8.1.3
3+
sphinx-autodoc-typehints == 2.5.0
4+
sphinx_rtd_theme == 3.0.2
5+
sphinx-exec-code == 0.14

docs/usage.rst

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ Nested example with the convenience base classes from easyconfig.
7777
# ------------ hide: stop -------------
7878

7979

80-
Description and comments
80+
Default file generation
8181
--------------------------------------
8282
It's possible to specify a description through the pydantic ``Field``.
8383
The description will be created as a comment in the .yml file.
84-
Note that the comments will be aligned properly
84+
Note that the comments will be aligned properly.
85+
With the ``in_file`` argument it's possible to skip entries from appearing in the default file
86+
(e.g. for advanced settings). When added manually to the file these values will still be loaded as expected.
8587

8688
.. exec_code::
8789
:language_output: yaml
@@ -94,6 +96,7 @@ Note that the comments will be aligned properly
9496
class MySimpleAppConfig(AppBaseModel):
9597
retries: int = Field(5, description='Amount of retries on error')
9698
url: str = Field('localhost', description='Url used for connection')
99+
advanced: str = Field('something advanced', in_file=False)
97100
port: int = 443
98101

99102

@@ -125,7 +128,7 @@ yaml file
125128

126129
.. exec_code::
127130
:language_output: yaml
128-
:hide_code:
131+
:hide:
129132

130133
a = """
131134
env_var: "${MY_USER}"
@@ -145,7 +148,7 @@ yaml file
145148

146149
.. exec_code::
147150
:language_output: yaml
148-
:hide_code:
151+
:hide:
149152
:caption_output: After expansion
150153

151154

@@ -222,3 +225,46 @@ This is especially useful feature if the application allows dynamic reloading of
222225
# This will trigger the callback
223226
CONFIG.load_config_file('/my/configuration/file.yml')
224227
# ------------ skip: stop -------------
228+
229+
230+
231+
Preprocessing
232+
--------------------------------------
233+
With preprocessing it's possible to introduce changes in a non-breaking way
234+
235+
236+
.. exec_code::
237+
:language_output: yaml
238+
239+
from pydantic import Field
240+
from easyconfig import AppBaseModel, BaseModel, create_app_config
241+
242+
243+
class HttpConfig(BaseModel):
244+
url: str = 'localhost'
245+
port: int = 443
246+
retries: int = 3
247+
timeout: int = 0
248+
249+
250+
class MySimpleAppConfig(AppBaseModel):
251+
http: HttpConfig = HttpConfig()
252+
253+
254+
CONFIG = create_app_config(MySimpleAppConfig())
255+
256+
# Setup preprocessing, these are the migration steps from the old format
257+
preprocess = CONFIG.load_preprocess
258+
preprocess.rename_entry(['server'], 'http')
259+
preprocess.move_entry(['wait time'], ['http', 'timeout'])
260+
preprocess.set_log_func(print) # This should normally be logger.info or logger.debug
261+
262+
# Load some old legacy format where http was still named server
263+
CONFIG.load_config_dict({
264+
'server': { # this entry will be renamed to http
265+
'retries': 5
266+
},
267+
'wait time': 10 # this entry will be moved to http.timeout
268+
})
269+
270+
print(f'timeout: {CONFIG.http.timeout}')

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ That way the users can have some guidance how to change the program behaviour.
4040
It's possible to use environment variable or files for expansion. Easyconfig will load all values
4141

4242
# Changelog
43+
#### 0.4.0 (2024-01-10)
44+
- Minimum required python version is now 3.10
45+
- Added preprocessor to so it's possible to move and deprecate configuration entries
46+
- Added property to get the loaded configuration file
47+
- Many fixes
48+
- Updated CI and code linters
49+
4350
#### 0.3.2 (2024-01-10)
4451
- Updated CI and code linters
4552

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
-r requirements_setup.txt
33

44
# testing dependencies
5-
pytest == 7.4.4
6-
pre-commit == 3.5.0
5+
pre-commit == 4.0.1
6+
pytest == 8.3.4
77

88
# linter
9-
ruff == 0.1.11
9+
ruff == 0.8.2
10+
pur == 7.3.2

0 commit comments

Comments
 (0)