python-simpleconf 0.9.5__tar.gz → 0.9.7__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.5 → python_simpleconf-0.9.7}/PKG-INFO +17 -5
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/README.md +11 -1
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/docs/CHANGELOG.md +10 -0
- python_simpleconf-0.9.7/docs/logo.png +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/pyproject.toml +5 -2
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/__init__.py +1 -1
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/__init__.py +15 -1
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/test_config.py +15 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/test_loaders.py +40 -0
- python_simpleconf-0.9.7/uv.lock +4215 -0
- python_simpleconf-0.9.5/uv.lock +0 -3077
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/.coveragerc +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/.github/workflows/build.yml +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/.gitignore +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/.pre-commit-config.yaml +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/LICENSE +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/Makefile +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/setup.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/caster.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/config.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/exceptions.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/dict.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/env.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/ini.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/json.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/osenv.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/toml.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/loaders/yaml.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/py.typed +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/simpleconf/utils.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/__init__.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/fixt_simpleconf.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/test_caster.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tests/test_utils.py +0 -0
- {python_simpleconf-0.9.5 → python_simpleconf-0.9.7}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: python-simpleconf
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.7
|
|
4
4
|
Summary: Simple configuration management with python.
|
|
5
5
|
Project-URL: Homepage, https://github.com/pwwang/simpleconf
|
|
6
6
|
Project-URL: Repository, https://github.com/pwwang/simpleconf
|
|
@@ -14,7 +14,8 @@ Provides-Extra: all
|
|
|
14
14
|
Requires-Dist: iniconfig<3,>=2.0; extra == 'all'
|
|
15
15
|
Requires-Dist: python-dotenv<2,>=1.1; extra == 'all'
|
|
16
16
|
Requires-Dist: pyyaml<7,>=6; extra == 'all'
|
|
17
|
-
Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux') and extra == 'all'
|
|
17
|
+
Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux' and python_version < '3.10') and extra == 'all'
|
|
18
|
+
Requires-Dist: rtoml<1,>=0.12; (sys_platform == 'linux' and python_version >= '3.10') and extra == 'all'
|
|
18
19
|
Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'all'
|
|
19
20
|
Provides-Extra: async
|
|
20
21
|
Requires-Dist: aiofiles>=23.0.0; extra == 'async'
|
|
@@ -29,7 +30,8 @@ Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquid'
|
|
|
29
30
|
Provides-Extra: liquidpy
|
|
30
31
|
Requires-Dist: liquidpy<0.9,>=0.8; extra == 'liquidpy'
|
|
31
32
|
Provides-Extra: toml
|
|
32
|
-
Requires-Dist: rtoml<
|
|
33
|
+
Requires-Dist: rtoml<0.13,>=0.12; (sys_platform == 'linux' and python_version < '3.10') and extra == 'toml'
|
|
34
|
+
Requires-Dist: rtoml<1,>=0.12; (sys_platform == 'linux' and python_version >= '3.10') and extra == 'toml'
|
|
33
35
|
Requires-Dist: tomli<3,>=2.0; (sys_platform != 'linux') and extra == 'toml'
|
|
34
36
|
Provides-Extra: yaml
|
|
35
37
|
Requires-Dist: pyyaml<7,>=6; extra == 'yaml'
|
|
@@ -37,7 +39,12 @@ Description-Content-Type: text/markdown
|
|
|
37
39
|
|
|
38
40
|
# simpleconf
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
<div align="center">
|
|
43
|
+
<img src="./docs/logo.png" width="220px" alt="python-simpleconf logo" />
|
|
44
|
+
|
|
45
|
+
<p style="font-weight:bold;">Simple configuration management for Python</p>
|
|
46
|
+
|
|
47
|
+
</div>
|
|
41
48
|
|
|
42
49
|
## Installation
|
|
43
50
|
```shell
|
|
@@ -467,6 +474,9 @@ The `$env:` syntax supports optional modifiers to control the behavior when a va
|
|
|
467
474
|
| `$env:VAR:required` | Explicit form — raises `ValueError` |
|
|
468
475
|
| `$env:VAR:optional-asis` | Keeps the literal `$env:VAR` string unchanged |
|
|
469
476
|
| `$env:VAR:optional-empty` | Resolves to an empty string `""` |
|
|
477
|
+
| `$env:VAR:default:<value>` | Resolves to `<value>` instead |
|
|
478
|
+
|
|
479
|
+
When found, the environment variable's value always wins over the `default`. Default values go through the same casting as env values, so cast prefixes like `@int:` work there too (e.g. `$env:PORT:default:@int:8080` resolves to the integer `8080`). The default value itself may contain colons (e.g. `$env:URL:default:http://localhost:8080`).
|
|
470
480
|
|
|
471
481
|
**Example — using modifiers:**
|
|
472
482
|
|
|
@@ -482,6 +492,7 @@ db:
|
|
|
482
492
|
host: $env:DB_HOST
|
|
483
493
|
port: $env:DB_PORT:optional-asis # keeps "$env:DB_PORT" as-is when not found
|
|
484
494
|
timeout: $env:TIMEOUT:optional-empty # becomes "" when not found
|
|
495
|
+
user: $env:DB_USER:default:admin # becomes "admin" when not found
|
|
485
496
|
```
|
|
486
497
|
|
|
487
498
|
```python
|
|
@@ -491,6 +502,7 @@ conf = Config.load('config.yaml')
|
|
|
491
502
|
# conf.db.host == 'localhost'
|
|
492
503
|
# conf.db.port == '$env:DB_PORT'
|
|
493
504
|
# conf.db.timeout == ''
|
|
505
|
+
# conf.db.user == 'admin'
|
|
494
506
|
```
|
|
495
507
|
|
|
496
508
|
**Example — using `env` in templates:**
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# simpleconf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img src="./docs/logo.png" width="220px" alt="python-simpleconf logo" />
|
|
5
|
+
|
|
6
|
+
<p style="font-weight:bold;">Simple configuration management for Python</p>
|
|
7
|
+
|
|
8
|
+
</div>
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
```shell
|
|
@@ -430,6 +435,9 @@ The `$env:` syntax supports optional modifiers to control the behavior when a va
|
|
|
430
435
|
| `$env:VAR:required` | Explicit form — raises `ValueError` |
|
|
431
436
|
| `$env:VAR:optional-asis` | Keeps the literal `$env:VAR` string unchanged |
|
|
432
437
|
| `$env:VAR:optional-empty` | Resolves to an empty string `""` |
|
|
438
|
+
| `$env:VAR:default:<value>` | Resolves to `<value>` instead |
|
|
439
|
+
|
|
440
|
+
When found, the environment variable's value always wins over the `default`. Default values go through the same casting as env values, so cast prefixes like `@int:` work there too (e.g. `$env:PORT:default:@int:8080` resolves to the integer `8080`). The default value itself may contain colons (e.g. `$env:URL:default:http://localhost:8080`).
|
|
433
441
|
|
|
434
442
|
**Example — using modifiers:**
|
|
435
443
|
|
|
@@ -445,6 +453,7 @@ db:
|
|
|
445
453
|
host: $env:DB_HOST
|
|
446
454
|
port: $env:DB_PORT:optional-asis # keeps "$env:DB_PORT" as-is when not found
|
|
447
455
|
timeout: $env:TIMEOUT:optional-empty # becomes "" when not found
|
|
456
|
+
user: $env:DB_USER:default:admin # becomes "admin" when not found
|
|
448
457
|
```
|
|
449
458
|
|
|
450
459
|
```python
|
|
@@ -454,6 +463,7 @@ conf = Config.load('config.yaml')
|
|
|
454
463
|
# conf.db.host == 'localhost'
|
|
455
464
|
# conf.db.port == '$env:DB_PORT'
|
|
456
465
|
# conf.db.timeout == ''
|
|
466
|
+
# conf.db.user == 'admin'
|
|
457
467
|
```
|
|
458
468
|
|
|
459
469
|
**Example — using `env` in templates:**
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.9.7
|
|
4
|
+
|
|
5
|
+
- chore: update rtoml dependency constraints for Python version compatibility on Linux
|
|
6
|
+
- chore: bump diot to 0.3.6
|
|
7
|
+
- docs: add logo
|
|
8
|
+
|
|
9
|
+
## 0.9.6
|
|
10
|
+
|
|
11
|
+
- feat: add support for default values in environment variable resolution
|
|
12
|
+
|
|
3
13
|
## 0.9.5
|
|
4
14
|
|
|
5
15
|
- fix: fix error for _read_first_lines when file name is too long
|
|
Binary file
|
|
@@ -28,7 +28,8 @@ env = ["python-dotenv>=1.1,<2"]
|
|
|
28
28
|
yaml = ["pyyaml>=6,<7"]
|
|
29
29
|
# Use rtoml only when the wheel is available (linux)
|
|
30
30
|
toml = [
|
|
31
|
-
"rtoml>=0.12,<
|
|
31
|
+
"rtoml>=0.12,<0.13; sys_platform == 'linux' and python_version < '3.10'",
|
|
32
|
+
"rtoml>=0.12,<1; sys_platform == 'linux' and python_version >= '3.10'",
|
|
32
33
|
"tomli>=2.0,<3; sys_platform != 'linux'",
|
|
33
34
|
]
|
|
34
35
|
async = ["aiofiles>=23.0.0"]
|
|
@@ -39,7 +40,8 @@ all = [
|
|
|
39
40
|
"iniconfig>=2.0,<3",
|
|
40
41
|
"python-dotenv>=1.1,<2",
|
|
41
42
|
"pyyaml>=6,<7",
|
|
42
|
-
"rtoml>=0.12,<0.13; sys_platform == 'linux'",
|
|
43
|
+
"rtoml>=0.12,<0.13; sys_platform == 'linux' and python_version < '3.10'",
|
|
44
|
+
"rtoml>=0.12,<1; sys_platform == 'linux' and python_version >= '3.10'",
|
|
43
45
|
"tomli>=2.0,<3; sys_platform != 'linux'",
|
|
44
46
|
]
|
|
45
47
|
|
|
@@ -65,6 +67,7 @@ filterwarnings = [
|
|
|
65
67
|
console_output_style = "progress"
|
|
66
68
|
junit_family = "xunit1"
|
|
67
69
|
asyncio_mode = "auto"
|
|
70
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
68
71
|
|
|
69
72
|
[tool.black]
|
|
70
73
|
line-length = 88
|
|
@@ -73,6 +73,10 @@ class Loader(ABC):
|
|
|
73
73
|
1. ``self.env_vars`` (loaded from ``.env`` file via directive)
|
|
74
74
|
2. ``os.environ`` (system environment variables)
|
|
75
75
|
|
|
76
|
+
``$env:KEY:default:<value>`` falls back to ``<value>`` when the
|
|
77
|
+
variable is not found (modifiers ``required``, ``optional-asis`` and
|
|
78
|
+
``optional-empty`` control the not-found behavior otherwise).
|
|
79
|
+
|
|
76
80
|
Resolved values are re-cast through :attr:`CASTERS`.
|
|
77
81
|
|
|
78
82
|
Returns the mutated Diot for chaining.
|
|
@@ -90,7 +94,13 @@ class Loader(ABC):
|
|
|
90
94
|
return value
|
|
91
95
|
if isinstance(value, str) and value.startswith("$env:"):
|
|
92
96
|
rest = value[5:]
|
|
93
|
-
|
|
97
|
+
default = None
|
|
98
|
+
if ":default:" in rest:
|
|
99
|
+
# $env:VAR:default:<value> — split on first occurrence so
|
|
100
|
+
# the default itself may contain colons
|
|
101
|
+
var_name, _, default = rest.partition(":default:")
|
|
102
|
+
modifier = "required"
|
|
103
|
+
elif ":" in rest:
|
|
94
104
|
var_name, modifier = rest.rsplit(":", 1)
|
|
95
105
|
if modifier not in KNOWN_MODIFIERS:
|
|
96
106
|
# Unknown modifier — treat whole string as var name
|
|
@@ -105,6 +115,10 @@ class Loader(ABC):
|
|
|
105
115
|
if resolved is not None:
|
|
106
116
|
return cast_value(resolved, _ENV_CASTERS)
|
|
107
117
|
|
|
118
|
+
# Not found — use the default value if given
|
|
119
|
+
if default is not None:
|
|
120
|
+
return cast_value(default, _ENV_CASTERS)
|
|
121
|
+
|
|
108
122
|
# Not found — behavior depends on modifier
|
|
109
123
|
if modifier == "optional-empty":
|
|
110
124
|
return ""
|
|
@@ -469,3 +469,18 @@ def test_loadenv_unknown_modifier_falls_back_to_required(tmp_path):
|
|
|
469
469
|
)
|
|
470
470
|
with pytest.raises(ValueError, match="NONEXISTENT:unknown"):
|
|
471
471
|
Config.load(f)
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def test_loadenv_default_used_when_not_found(tmp_path):
|
|
475
|
+
"""$env:NONEXISTENT:default:<value> falls back to <value>."""
|
|
476
|
+
env = tmp_path / ".env"
|
|
477
|
+
env.write_text("A=1\n")
|
|
478
|
+
f = tmp_path / "config.yaml"
|
|
479
|
+
f.write_text(
|
|
480
|
+
"# simpleconf-loadenv\n"
|
|
481
|
+
"a: $env:A:default:x\n"
|
|
482
|
+
"b: $env:NONEXISTENT:default:abc\n"
|
|
483
|
+
)
|
|
484
|
+
config = Config.load(f)
|
|
485
|
+
assert config.a == "1" # found env var wins over the default
|
|
486
|
+
assert config.b == "abc"
|
|
@@ -567,6 +567,46 @@ def test_resolve_env_vars_optional_empty():
|
|
|
567
567
|
assert out.a == ""
|
|
568
568
|
|
|
569
569
|
|
|
570
|
+
def test_resolve_env_vars_default_used_when_not_found():
|
|
571
|
+
"""$env:VAR:default:<value> falls back to <value> when not found."""
|
|
572
|
+
loader = get_loader("dict")
|
|
573
|
+
loader.env_vars = {}
|
|
574
|
+
out = loader._resolve_env_vars(Diot({"a": "$env:X:default:abc"}))
|
|
575
|
+
assert out.a == "abc"
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def test_resolve_env_vars_default_env_wins():
|
|
579
|
+
"""Found env var wins over the default value."""
|
|
580
|
+
loader = get_loader("dict")
|
|
581
|
+
loader.env_vars = {"X": "1"}
|
|
582
|
+
out = loader._resolve_env_vars(Diot({"a": "$env:X:default:abc"}))
|
|
583
|
+
assert out.a == "1"
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def test_resolve_env_vars_default_caster_applied():
|
|
587
|
+
"""Default value is cast like an env var (@int:3 -> int 3)."""
|
|
588
|
+
loader = get_loader("dict")
|
|
589
|
+
loader.env_vars = {}
|
|
590
|
+
out = loader._resolve_env_vars(Diot({"a": "$env:X:default:@int:3"}))
|
|
591
|
+
assert out.a == 3
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
def test_resolve_env_vars_default_with_colons():
|
|
595
|
+
"""Default value itself may contain colons."""
|
|
596
|
+
loader = get_loader("dict")
|
|
597
|
+
loader.env_vars = {}
|
|
598
|
+
out = loader._resolve_env_vars(Diot({"a": "$env:URL:default:http://a:1"}))
|
|
599
|
+
assert out.a == "http://a:1"
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
def test_resolve_env_vars_default_empty():
|
|
603
|
+
"""$env:VAR:default: (empty) resolves to '' when not found."""
|
|
604
|
+
loader = get_loader("dict")
|
|
605
|
+
loader.env_vars = {}
|
|
606
|
+
out = loader._resolve_env_vars(Diot({"a": "$env:X:default:"}))
|
|
607
|
+
assert out.a == ""
|
|
608
|
+
|
|
609
|
+
|
|
570
610
|
def test_resolve_env_vars_recursive():
|
|
571
611
|
"""$env:VAR inside nested dicts resolves correctly."""
|
|
572
612
|
loader = get_loader("dict")
|