python-simpleconf 0.9.1__tar.gz → 0.9.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_simpleconf-0.9.3/.coveragerc +6 -0
- python_simpleconf-0.9.3/.github/workflows/build.yml +82 -0
- python_simpleconf-0.9.3/.gitignore +110 -0
- python_simpleconf-0.9.3/.pre-commit-config.yaml +36 -0
- python_simpleconf-0.9.3/Makefile +36 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/PKG-INFO +74 -24
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/README.md +54 -0
- python_simpleconf-0.9.3/docs/CHANGELOG.md +15 -0
- python_simpleconf-0.9.3/pyproject.toml +69 -0
- python_simpleconf-0.9.3/setup.py +14 -0
- python_simpleconf-0.9.3/simpleconf/__init__.py +5 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/config.py +7 -1
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/__init__.py +5 -3
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/dict.py +1 -1
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/env.py +18 -9
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/ini.py +2 -2
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/utils.py +62 -0
- python_simpleconf-0.9.3/tests/__init__.py +0 -0
- python_simpleconf-0.9.3/tests/fixt_simpleconf.py +206 -0
- python_simpleconf-0.9.3/tests/test_caster.py +100 -0
- python_simpleconf-0.9.3/tests/test_config.py +357 -0
- python_simpleconf-0.9.3/tests/test_loaders.py +532 -0
- python_simpleconf-0.9.3/tests/test_utils.py +182 -0
- python_simpleconf-0.9.3/tox.ini +6 -0
- python_simpleconf-0.9.3/uv.lock +2586 -0
- python_simpleconf-0.9.1/pyproject.toml +0 -61
- python_simpleconf-0.9.1/simpleconf/__init__.py +0 -3
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/LICENSE +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/caster.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/exceptions.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/json.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/osenv.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/toml.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/loaders/yaml.py +0 -0
- {python_simpleconf-0.9.1 → python_simpleconf-0.9.3}/simpleconf/py.typed +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
name: Build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: [3.9, "3.10", 3.11, 3.12]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@v5
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
python-version: ${{ matrix.python-version }}
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: uv sync --all-extras
|
|
26
|
+
- name: Run flake8
|
|
27
|
+
run: uv run flake8 simpleconf
|
|
28
|
+
- name: Test with pytest
|
|
29
|
+
run: uv run pytest tests/ --junitxml=junit/test-results-ubuntu-${{ matrix.python-version }}.xml
|
|
30
|
+
- name: Upload pytest test results
|
|
31
|
+
uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: pytest-results-ubuntu-${{ matrix.python-version }}
|
|
34
|
+
path: junit/test-results-ubuntu-${{ matrix.python-version }}.xml
|
|
35
|
+
# Use always() to always run this step to publish test results when there are test failures
|
|
36
|
+
if: ${{ always() }}
|
|
37
|
+
- name: Run codacy-coverage-reporter
|
|
38
|
+
uses: codacy/codacy-coverage-reporter-action@master
|
|
39
|
+
if: matrix.python-version == 3.12
|
|
40
|
+
with:
|
|
41
|
+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
|
42
|
+
coverage-reports: cov.xml
|
|
43
|
+
|
|
44
|
+
build-windows:
|
|
45
|
+
runs-on: windows-latest
|
|
46
|
+
strategy:
|
|
47
|
+
fail-fast: false
|
|
48
|
+
matrix:
|
|
49
|
+
python-version: [3.9, "3.10", 3.11, 3.12]
|
|
50
|
+
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v6
|
|
53
|
+
- name: Install uv
|
|
54
|
+
uses: astral-sh/setup-uv@v5
|
|
55
|
+
with:
|
|
56
|
+
enable-cache: true
|
|
57
|
+
python-version: ${{ matrix.python-version }}
|
|
58
|
+
- name: Install dependencies
|
|
59
|
+
run: uv sync --all-extras
|
|
60
|
+
- name: Run flake8
|
|
61
|
+
run: uv run flake8 simpleconf
|
|
62
|
+
- name: Test with pytest
|
|
63
|
+
run: uv run pytest tests/ --junitxml=junit/test-results-windows-${{ matrix.python-version }}.xml
|
|
64
|
+
- name: Upload pytest test results
|
|
65
|
+
uses: actions/upload-artifact@v4
|
|
66
|
+
with:
|
|
67
|
+
name: pytest-results-windows-${{ matrix.python-version }}
|
|
68
|
+
path: junit/test-results-windows-${{ matrix.python-version }}.xml
|
|
69
|
+
# Use always() to always run this step to publish test results when there are test failures
|
|
70
|
+
if: ${{ always() }}
|
|
71
|
+
|
|
72
|
+
deploy:
|
|
73
|
+
needs: [build, build-windows]
|
|
74
|
+
runs-on: ubuntu-latest
|
|
75
|
+
if: github.event_name == 'release'
|
|
76
|
+
steps:
|
|
77
|
+
- uses: actions/checkout@v6
|
|
78
|
+
- name: Install uv
|
|
79
|
+
uses: astral-sh/setup-uv@v5
|
|
80
|
+
- name: Publish to PyPI
|
|
81
|
+
run: uv build && uv publish --token ${{ secrets.PYPI_PASSWORD }}
|
|
82
|
+
if: success()
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
MANIFEST
|
|
27
|
+
|
|
28
|
+
# PyInstaller
|
|
29
|
+
# Usually these files are written by a python script from a template
|
|
30
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
cov.xml
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
.hypothesis/
|
|
49
|
+
.pytest_cache/
|
|
50
|
+
|
|
51
|
+
# Translations
|
|
52
|
+
*.mo
|
|
53
|
+
*.pot
|
|
54
|
+
|
|
55
|
+
# Django stuff:
|
|
56
|
+
*.log
|
|
57
|
+
local_settings.py
|
|
58
|
+
db.sqlite3
|
|
59
|
+
|
|
60
|
+
# Flask stuff:
|
|
61
|
+
instance/
|
|
62
|
+
.webassets-cache
|
|
63
|
+
|
|
64
|
+
# Scrapy stuff:
|
|
65
|
+
.scrapy
|
|
66
|
+
|
|
67
|
+
# Sphinx documentation
|
|
68
|
+
docs/_build/
|
|
69
|
+
|
|
70
|
+
# PyBuilder
|
|
71
|
+
target/
|
|
72
|
+
|
|
73
|
+
# Jupyter Notebook
|
|
74
|
+
.ipynb_checkpoints
|
|
75
|
+
|
|
76
|
+
# pyenv
|
|
77
|
+
.python-version
|
|
78
|
+
|
|
79
|
+
# celery beat schedule file
|
|
80
|
+
celerybeat-schedule
|
|
81
|
+
|
|
82
|
+
# SageMath parsed files
|
|
83
|
+
*.sage.py
|
|
84
|
+
|
|
85
|
+
# Environments
|
|
86
|
+
.env
|
|
87
|
+
.venv
|
|
88
|
+
env/
|
|
89
|
+
venv/
|
|
90
|
+
ENV/
|
|
91
|
+
env.bak/
|
|
92
|
+
venv.bak/
|
|
93
|
+
|
|
94
|
+
# Spyder project settings
|
|
95
|
+
.spyderproject
|
|
96
|
+
.spyproject
|
|
97
|
+
|
|
98
|
+
# Rope project settings
|
|
99
|
+
.ropeproject
|
|
100
|
+
|
|
101
|
+
# mkdocs documentation
|
|
102
|
+
/site
|
|
103
|
+
|
|
104
|
+
# mypy
|
|
105
|
+
.mypy_cache/
|
|
106
|
+
|
|
107
|
+
*.bak
|
|
108
|
+
|
|
109
|
+
.vscode/
|
|
110
|
+
debug.ipynb
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
fail_fast: true
|
|
2
|
+
repos:
|
|
3
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
4
|
+
rev: 5df1a4bf6f04a1ed3a643167b38d502575e29aef
|
|
5
|
+
hooks:
|
|
6
|
+
- id: trailing-whitespace
|
|
7
|
+
- id: end-of-file-fixer
|
|
8
|
+
- id: check-yaml
|
|
9
|
+
exclude: 'mkdocs.yml'
|
|
10
|
+
- repo: local
|
|
11
|
+
hooks:
|
|
12
|
+
- id: flake8
|
|
13
|
+
name: Run flake8
|
|
14
|
+
files: ^simpleconf/.+\.py$
|
|
15
|
+
pass_filenames: true
|
|
16
|
+
entry: flake8
|
|
17
|
+
types: [python]
|
|
18
|
+
language: system
|
|
19
|
+
- id: versionchecker
|
|
20
|
+
name: Check version agreement in pyproject and __version__
|
|
21
|
+
entry: bash -c
|
|
22
|
+
language: system
|
|
23
|
+
args:
|
|
24
|
+
- get_ver() { echo $(egrep "^__version|^version" $1 | cut -d= -f2 | sed 's/\"\| //g'); };
|
|
25
|
+
v1=`get_ver pyproject.toml`;
|
|
26
|
+
v2=`get_ver simpleconf/__init__.py`;
|
|
27
|
+
if [[ $v1 == $v2 ]]; then exit 0; else exit 1; fi
|
|
28
|
+
pass_filenames: false
|
|
29
|
+
files: ^pyproject\.toml|simpleconf/__init__\.py$
|
|
30
|
+
- id: pytest
|
|
31
|
+
name: Run pytest
|
|
32
|
+
entry: pytest
|
|
33
|
+
language: system
|
|
34
|
+
args: [tests/]
|
|
35
|
+
pass_filenames: false
|
|
36
|
+
files: ^tests/.+$|simpleconf/.+\.py$
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
SHELL=/bin/bash
|
|
2
|
+
|
|
3
|
+
version:
|
|
4
|
+
@if [ -z "$(word 2,$(MAKECMDGOALS))" ]; then \
|
|
5
|
+
CURRENT_VERSION=$$(grep '^__version__' simpleconf/__init__.py | sed 's/__version__ = "\(.*\)"/\1/'); \
|
|
6
|
+
MAJOR=$$(echo $$CURRENT_VERSION | cut -d. -f1); \
|
|
7
|
+
MINOR=$$(echo $$CURRENT_VERSION | cut -d. -f2); \
|
|
8
|
+
PATCH=$$(echo $$CURRENT_VERSION | cut -d. -f3); \
|
|
9
|
+
NEW_PATCH=$$((PATCH + 1)); \
|
|
10
|
+
NEW_VERSION="$$MAJOR.$$MINOR.$$NEW_PATCH"; \
|
|
11
|
+
else \
|
|
12
|
+
NEW_VERSION="$(word 2,$(MAKECMDGOALS))"; \
|
|
13
|
+
fi; \
|
|
14
|
+
echo "Updating version to $$NEW_VERSION"; \
|
|
15
|
+
sed -i "s/^version = .*/version = \"$$NEW_VERSION\"/" pyproject.toml; \
|
|
16
|
+
sed -i "s/^__version__ = .*/__version__ = \"$$NEW_VERSION\"/" simpleconf/__init__.py; \
|
|
17
|
+
LAST_TAG=$$(git describe --tags --abbrev=0 2>/dev/null || echo ""); \
|
|
18
|
+
if [ -z "$$LAST_TAG" ]; then \
|
|
19
|
+
COMMITS=$$(git log --pretty=format:"- %s" HEAD); \
|
|
20
|
+
else \
|
|
21
|
+
COMMITS=$$(git log --pretty=format:"- %s" $$LAST_TAG..HEAD); \
|
|
22
|
+
fi; \
|
|
23
|
+
if [ -n "$$COMMITS" ]; then \
|
|
24
|
+
printf "\n## %s\n\n%s\n\n" "$$NEW_VERSION" "$$COMMITS" | cat - <(tail -n +3 docs/CHANGELOG.md) > docs/CHANGELOG.md.tmp; \
|
|
25
|
+
head -n 2 docs/CHANGELOG.md > docs/CHANGELOG.md.new; \
|
|
26
|
+
cat docs/CHANGELOG.md.tmp >> docs/CHANGELOG.md.new; \
|
|
27
|
+
mv docs/CHANGELOG.md.new docs/CHANGELOG.md; \
|
|
28
|
+
rm -f docs/CHANGELOG.md.tmp; \
|
|
29
|
+
fi; \
|
|
30
|
+
echo "Version updated to $$NEW_VERSION";
|
|
31
|
+
|
|
32
|
+
# Catch-all rule to ignore version number argument
|
|
33
|
+
%:
|
|
34
|
+
@:
|
|
35
|
+
|
|
36
|
+
.PHONY: version
|
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-simpleconf
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.3
|
|
4
4
|
Summary: Simple configuration management with python.
|
|
5
|
+
Project-URL: Homepage, https://github.com/pwwang/simpleconf
|
|
6
|
+
Project-URL: Repository, https://github.com/pwwang/simpleconf
|
|
7
|
+
Author-email: pwwang <pwwang@pwwang.com>
|
|
5
8
|
License: MIT
|
|
6
9
|
License-File: LICENSE
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Requires-
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: diot<0.4,>=0.3.3
|
|
12
|
+
Requires-Dist: panpath<0.5,>=0.4.8
|
|
18
13
|
Provides-Extra: all
|
|
14
|
+
Requires-Dist: iniconfig<3,>=2.0; extra == 'all'
|
|
15
|
+
Requires-Dist: python-dotenv<2,>=1.1; extra == 'all'
|
|
16
|
+
Requires-Dist: pyyaml<7,>=6; extra == 'all'
|
|
17
|
+
Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux') and extra == 'all'
|
|
18
|
+
Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'all'
|
|
19
19
|
Provides-Extra: async
|
|
20
|
+
Requires-Dist: aiofiles>=23.0.0; extra == 'async'
|
|
20
21
|
Provides-Extra: env
|
|
22
|
+
Requires-Dist: python-dotenv<2,>=1.1; extra == 'env'
|
|
21
23
|
Provides-Extra: ini
|
|
24
|
+
Requires-Dist: iniconfig<3,>=2.0; extra == 'ini'
|
|
22
25
|
Provides-Extra: jinja2
|
|
26
|
+
Requires-Dist: jinja2<4,>=3.0; extra == 'jinja2'
|
|
23
27
|
Provides-Extra: liquid
|
|
28
|
+
Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquid'
|
|
24
29
|
Provides-Extra: liquidpy
|
|
30
|
+
Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquidpy'
|
|
25
31
|
Provides-Extra: toml
|
|
32
|
+
Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux') and extra == 'toml'
|
|
33
|
+
Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'toml'
|
|
26
34
|
Provides-Extra: yaml
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist: diot (>=0.3.2,<0.4.0)
|
|
29
|
-
Requires-Dist: iniconfig (>=2.0,<3.0) ; extra == "ini" or extra == "all"
|
|
30
|
-
Requires-Dist: jinja2 (>=3.0,<4.0) ; extra == "jinja2"
|
|
31
|
-
Requires-Dist: liquidpy (>=0.8,<0.9) ; extra == "liquid" or extra == "liquidpy"
|
|
32
|
-
Requires-Dist: panpath (>=0.4.8,<0.5.0)
|
|
33
|
-
Requires-Dist: python-dotenv (>=1.1,<2.0) ; extra == "env" or extra == "all"
|
|
34
|
-
Requires-Dist: pyyaml (>=6,<7) ; extra == "yaml" or extra == "all"
|
|
35
|
-
Requires-Dist: rtoml (>=0.12,<0.13) ; (sys_platform == "linux") and (extra == "toml" or extra == "all")
|
|
36
|
-
Requires-Dist: tomli (>=2.0,<3.0) ; (sys_platform != "linux") and (extra == "toml" or extra == "all")
|
|
37
|
-
Project-URL: Homepage, https://github.com/pwwang/simpleconf
|
|
38
|
-
Project-URL: Repository, https://github.com/pwwang/simpleconf
|
|
35
|
+
Requires-Dist: pyyaml<7,>=6; extra == 'yaml'
|
|
39
36
|
Description-Content-Type: text/markdown
|
|
40
37
|
|
|
41
38
|
# simpleconf
|
|
@@ -350,4 +347,57 @@ conf = Config.load('config.liq.toml')
|
|
|
350
347
|
# conf.section1.a == 1
|
|
351
348
|
# conf.section2.a == 2
|
|
352
349
|
```
|
|
350
|
+
#### Loader directive in the first line
|
|
351
|
+
|
|
352
|
+
Instead of using a special file extension, you can embed a loader directive in the **first line** of a configuration file as a comment. This allows a plain `config.toml` to be processed by the Liquid engine without renaming the file.
|
|
353
|
+
|
|
354
|
+
The directive format is:
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
# simpleconf-loader: <loader>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Supported comment prefixes: `#`, `;`, `//` (case-insensitive).
|
|
361
|
+
|
|
362
|
+
The `<loader>` value can be:
|
|
363
|
+
|
|
364
|
+
| Value | Meaning |
|
|
365
|
+
|---|---|
|
|
366
|
+
| `liq` or `liquid` | Use the Liquid loader for this file's format |
|
|
367
|
+
| `j2`, `jinja`, or `jinja2` | Use the Jinja2 loader for this file's format |
|
|
368
|
+
| A full extension (e.g. `toml.liq`) | Use the exact loader specified |
|
|
369
|
+
|
|
370
|
+
**Example — Liquid in a plain `.toml` file:**
|
|
371
|
+
|
|
372
|
+
`config.toml`
|
|
373
|
+
```toml
|
|
374
|
+
# simpleconf-loader: liq
|
|
375
|
+
{% set x = 10 %}
|
|
376
|
+
[default]
|
|
377
|
+
a = {{ 1 + 1 }}
|
|
378
|
+
b = {{ x + 2 }}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
```python
|
|
382
|
+
from simpleconf import Config
|
|
383
|
+
|
|
384
|
+
conf = Config.load('config.toml')
|
|
385
|
+
# conf.default.a == 2
|
|
386
|
+
# conf.default.b == 12
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**Example — Jinja2 in a plain `.yaml` file:**
|
|
390
|
+
|
|
391
|
+
`config.yaml`
|
|
392
|
+
```yaml
|
|
393
|
+
# simpleconf-loader: j2
|
|
394
|
+
default:
|
|
395
|
+
a: {{ 1 + 1 }}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
```python
|
|
399
|
+
from simpleconf import Config
|
|
353
400
|
|
|
401
|
+
conf = Config.load('config.yaml')
|
|
402
|
+
# conf.default.a == 2
|
|
403
|
+
```
|
|
@@ -310,3 +310,57 @@ conf = Config.load('config.liq.toml')
|
|
|
310
310
|
# conf.section1.a == 1
|
|
311
311
|
# conf.section2.a == 2
|
|
312
312
|
```
|
|
313
|
+
#### Loader directive in the first line
|
|
314
|
+
|
|
315
|
+
Instead of using a special file extension, you can embed a loader directive in the **first line** of a configuration file as a comment. This allows a plain `config.toml` to be processed by the Liquid engine without renaming the file.
|
|
316
|
+
|
|
317
|
+
The directive format is:
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
# simpleconf-loader: <loader>
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Supported comment prefixes: `#`, `;`, `//` (case-insensitive).
|
|
324
|
+
|
|
325
|
+
The `<loader>` value can be:
|
|
326
|
+
|
|
327
|
+
| Value | Meaning |
|
|
328
|
+
|---|---|
|
|
329
|
+
| `liq` or `liquid` | Use the Liquid loader for this file's format |
|
|
330
|
+
| `j2`, `jinja`, or `jinja2` | Use the Jinja2 loader for this file's format |
|
|
331
|
+
| A full extension (e.g. `toml.liq`) | Use the exact loader specified |
|
|
332
|
+
|
|
333
|
+
**Example — Liquid in a plain `.toml` file:**
|
|
334
|
+
|
|
335
|
+
`config.toml`
|
|
336
|
+
```toml
|
|
337
|
+
# simpleconf-loader: liq
|
|
338
|
+
{% set x = 10 %}
|
|
339
|
+
[default]
|
|
340
|
+
a = {{ 1 + 1 }}
|
|
341
|
+
b = {{ x + 2 }}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
from simpleconf import Config
|
|
346
|
+
|
|
347
|
+
conf = Config.load('config.toml')
|
|
348
|
+
# conf.default.a == 2
|
|
349
|
+
# conf.default.b == 12
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**Example — Jinja2 in a plain `.yaml` file:**
|
|
353
|
+
|
|
354
|
+
`config.yaml`
|
|
355
|
+
```yaml
|
|
356
|
+
# simpleconf-loader: j2
|
|
357
|
+
default:
|
|
358
|
+
a: {{ 1 + 1 }}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
```python
|
|
362
|
+
from simpleconf import Config
|
|
363
|
+
|
|
364
|
+
conf = Config.load('config.yaml')
|
|
365
|
+
# conf.default.a == 2
|
|
366
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## 0.9.3
|
|
5
|
+
|
|
6
|
+
- style: handle bytes content and ensure safe casting in loaders
|
|
7
|
+
- chore: migrate from Poetry to Hatch for build system and dependency management
|
|
8
|
+
|
|
9
|
+
## 0.9.2
|
|
10
|
+
|
|
11
|
+
- feat: add Makefile for version management and changelog updates
|
|
12
|
+
- feat: implement loader directive detection for config files
|
|
13
|
+
- fix: add __all__ declaration for public API in __init__.py
|
|
14
|
+
- chore: update diot to 0.3.3 (implement #2)
|
|
15
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "python-simpleconf"
|
|
7
|
+
version = "0.9.3"
|
|
8
|
+
description = "Simple configuration management with python."
|
|
9
|
+
authors = [{name = "pwwang", email = "pwwang@pwwang.com"}]
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"diot>=0.3.3,<0.4",
|
|
15
|
+
"panpath>=0.4.8,<0.5",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
Homepage = "https://github.com/pwwang/simpleconf"
|
|
20
|
+
Repository = "https://github.com/pwwang/simpleconf"
|
|
21
|
+
|
|
22
|
+
[project.optional-dependencies]
|
|
23
|
+
ini = ["iniconfig>=2.0,<3"]
|
|
24
|
+
env = ["python-dotenv>=1.1,<2"]
|
|
25
|
+
yaml = ["pyyaml>=6,<7"]
|
|
26
|
+
# Use rtoml only when the wheel is available (linux)
|
|
27
|
+
toml = [
|
|
28
|
+
"rtoml>=0.12,<0.13; sys_platform == 'linux'",
|
|
29
|
+
"tomli>=2.0,<3; sys_platform != 'linux'",
|
|
30
|
+
]
|
|
31
|
+
async = ["aiofiles>=23.0.0"]
|
|
32
|
+
jinja2 = ["jinja2>=3.0,<4"]
|
|
33
|
+
liquid = ["liquidpy>=0.8,<0.9"]
|
|
34
|
+
liquidpy = ["liquidpy>=0.8,<0.9"]
|
|
35
|
+
all = [
|
|
36
|
+
"iniconfig>=2.0,<3",
|
|
37
|
+
"python-dotenv>=1.1,<2",
|
|
38
|
+
"pyyaml>=6,<7",
|
|
39
|
+
"rtoml>=0.12,<0.13; sys_platform == 'linux'",
|
|
40
|
+
"tomli>=2.0,<3; sys_platform != 'linux'",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["simpleconf"]
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"pytest>=8",
|
|
49
|
+
"pytest-cov>=6",
|
|
50
|
+
"pytest-asyncio>=1",
|
|
51
|
+
"backports-asyncio-runner>=1.1.0; python_version < '3.11'",
|
|
52
|
+
"liquidpy>=0.8,<0.9",
|
|
53
|
+
"panpath[all-async]>=0.4.10",
|
|
54
|
+
"flake8>=7.3.0",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
addopts = "-vv --cov=simpleconf --cov-report xml:cov.xml --cov-report term-missing"
|
|
59
|
+
filterwarnings = [
|
|
60
|
+
"error"
|
|
61
|
+
]
|
|
62
|
+
console_output_style = "progress"
|
|
63
|
+
junit_family = "xunit1"
|
|
64
|
+
asyncio_mode = "auto"
|
|
65
|
+
|
|
66
|
+
[tool.black]
|
|
67
|
+
line-length = 88
|
|
68
|
+
target-version = ['py39', 'py310', 'py311', 'py312']
|
|
69
|
+
include = '\.pyi?$'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
This will not be included in the distribution.
|
|
4
|
+
The distribution is managed by uv
|
|
5
|
+
This file is kept only for
|
|
6
|
+
1. Github to index the dependents
|
|
7
|
+
2. pip install -e .
|
|
8
|
+
Do NOT use this to install this package, unless you handled the dependencies
|
|
9
|
+
by your self:
|
|
10
|
+
pip install git+https://...
|
|
11
|
+
"""
|
|
12
|
+
from setuptools import setup
|
|
13
|
+
|
|
14
|
+
setup(name="python-simpleconf")
|
|
@@ -5,7 +5,7 @@ from typing import Any, List, Generator, Union, Sequence
|
|
|
5
5
|
|
|
6
6
|
from diot import Diot
|
|
7
7
|
|
|
8
|
-
from .utils import config_to_ext, get_loader, POOL_KEY, META_KEY
|
|
8
|
+
from .utils import config_to_ext, detect_loader_directive, get_loader, POOL_KEY, META_KEY
|
|
9
9
|
from .loaders import Loader
|
|
10
10
|
|
|
11
11
|
LoaderType = Union[str, Loader, None]
|
|
@@ -116,6 +116,7 @@ class Config:
|
|
|
116
116
|
raise ValueError("'loader' must be specified for stream")
|
|
117
117
|
|
|
118
118
|
ext = config_to_ext(config)
|
|
119
|
+
ext = detect_loader_directive(config, ext)
|
|
119
120
|
loader = get_loader(ext)
|
|
120
121
|
else:
|
|
121
122
|
loader = get_loader(loader)
|
|
@@ -145,6 +146,7 @@ class Config:
|
|
|
145
146
|
raise ValueError("'loader' must be specified for stream")
|
|
146
147
|
|
|
147
148
|
ext = config_to_ext(config)
|
|
149
|
+
ext = detect_loader_directive(config, ext)
|
|
148
150
|
loader = get_loader(ext)
|
|
149
151
|
else:
|
|
150
152
|
loader = get_loader(loader)
|
|
@@ -202,6 +204,7 @@ class ProfileConfig:
|
|
|
202
204
|
|
|
203
205
|
if lder is None:
|
|
204
206
|
ext = config_to_ext(conf)
|
|
207
|
+
ext = detect_loader_directive(conf, ext)
|
|
205
208
|
lder = get_loader(ext)
|
|
206
209
|
else:
|
|
207
210
|
lder = get_loader(lder)
|
|
@@ -271,6 +274,7 @@ class ProfileConfig:
|
|
|
271
274
|
|
|
272
275
|
if lder is None:
|
|
273
276
|
ext = config_to_ext(conf)
|
|
277
|
+
ext = detect_loader_directive(conf, ext)
|
|
274
278
|
lder = get_loader(ext)
|
|
275
279
|
else:
|
|
276
280
|
lder = get_loader(lder)
|
|
@@ -323,6 +327,7 @@ class ProfileConfig:
|
|
|
323
327
|
raise ValueError("'loader' must be specified for stream")
|
|
324
328
|
|
|
325
329
|
ext = config_to_ext(conf)
|
|
330
|
+
ext = detect_loader_directive(conf, ext)
|
|
326
331
|
loader = get_loader(ext)
|
|
327
332
|
else:
|
|
328
333
|
loader = get_loader(loader)
|
|
@@ -378,6 +383,7 @@ class ProfileConfig:
|
|
|
378
383
|
raise ValueError("'loader' must be specified for stream")
|
|
379
384
|
|
|
380
385
|
ext = config_to_ext(conf)
|
|
386
|
+
ext = detect_loader_directive(conf, ext)
|
|
381
387
|
loader = get_loader(ext)
|
|
382
388
|
else:
|
|
383
389
|
loader = get_loader(loader)
|
|
@@ -148,7 +148,7 @@ class J2ModifierMixin(LoaderModifierMixin):
|
|
|
148
148
|
def _modifier(self, content: str | bytes) -> str | bytes:
|
|
149
149
|
"""Modify the content of the configuration file before loading"""
|
|
150
150
|
from jinja2 import Template
|
|
151
|
-
return Template(content).render()
|
|
151
|
+
return Template(content).render() # type: ignore
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
class LiqModifierMixin(LoaderModifierMixin):
|
|
@@ -156,5 +156,7 @@ class LiqModifierMixin(LoaderModifierMixin):
|
|
|
156
156
|
|
|
157
157
|
def _modifier(self, content: str | bytes) -> str | bytes:
|
|
158
158
|
"""Modify the content of the configuration file before loading"""
|
|
159
|
-
from liquid import Liquid
|
|
160
|
-
|
|
159
|
+
from liquid import Liquid # type: ignore[import]
|
|
160
|
+
str_content = content.decode() if isinstance(content, bytes) else content
|
|
161
|
+
liq = Liquid(str_content, from_file=False, mode="wild") # type: ignore
|
|
162
|
+
return liq.render()
|