python-simpleconf 0.7.0__tar.gz → 0.7.1__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.7.0 → python_simpleconf-0.7.1}/PKG-INFO +3 -3
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/pyproject.toml +5 -5
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/__init__.py +1 -1
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/config.py +38 -8
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/LICENSE +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/README.md +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/caster.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/exceptions.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/__init__.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/dict.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/env.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/ini.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/json.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/osenv.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/toml.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/loaders/yaml.py +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/py.typed +0 -0
- {python_simpleconf-0.7.0 → python_simpleconf-0.7.1}/simpleconf/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: python-simpleconf
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.1
|
|
4
4
|
Summary: Simple configuration management with python.
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: pwwang
|
|
@@ -18,9 +18,9 @@ Provides-Extra: env
|
|
|
18
18
|
Provides-Extra: ini
|
|
19
19
|
Provides-Extra: toml
|
|
20
20
|
Provides-Extra: yaml
|
|
21
|
-
Requires-Dist: diot (>=0.3.
|
|
21
|
+
Requires-Dist: diot (>=0.3.2,<0.4.0)
|
|
22
22
|
Requires-Dist: iniconfig (>=2.0,<3.0) ; extra == "ini" or extra == "all"
|
|
23
|
-
Requires-Dist: python-dotenv (>=1.
|
|
23
|
+
Requires-Dist: python-dotenv (>=1.1,<2.0) ; extra == "env" or extra == "all"
|
|
24
24
|
Requires-Dist: pyyaml (>=6,<7) ; extra == "yaml" or extra == "all"
|
|
25
25
|
Requires-Dist: rtoml (>=0.12,<0.13) ; (sys_platform == "linux") and (extra == "toml" or extra == "all")
|
|
26
26
|
Requires-Dist: tomli (>=2.0,<3.0) ; (sys_platform != "linux") and (extra == "toml" or extra == "all")
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = [ "poetry>=
|
|
2
|
+
requires = [ "poetry>=2",]
|
|
3
3
|
build-backend = "poetry.masonry.api"
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "python-simpleconf"
|
|
7
|
-
version = "0.7.
|
|
7
|
+
version = "0.7.1"
|
|
8
8
|
description = "Simple configuration management with python."
|
|
9
9
|
authors = [ "pwwang <pwwang@pwwang.com>",]
|
|
10
10
|
license = "MIT"
|
|
@@ -17,8 +17,8 @@ packages = [
|
|
|
17
17
|
|
|
18
18
|
[tool.poetry.dependencies]
|
|
19
19
|
python = "^3.9"
|
|
20
|
-
diot = "^0.3.
|
|
21
|
-
python-dotenv = { version="^1.
|
|
20
|
+
diot = "^0.3.2"
|
|
21
|
+
python-dotenv = { version="^1.1", optional = true}
|
|
22
22
|
pyyaml = { version="^6", optional = true}
|
|
23
23
|
# Use rtoml only when the wheel is available (linux)
|
|
24
24
|
rtoml = {version = "^0.12", optional = true, platform = "linux"}
|
|
@@ -32,7 +32,7 @@ yaml = [ "pyyaml"]
|
|
|
32
32
|
toml = [ "rtoml", "tomli"]
|
|
33
33
|
all = [ "iniconfig", "python-dotenv", "pyyaml", "rtoml", "tomli"]
|
|
34
34
|
|
|
35
|
-
[tool.poetry.dev
|
|
35
|
+
[tool.poetry.group.dev.dependencies]
|
|
36
36
|
pytest = "^8"
|
|
37
37
|
pytest-cov = "^6"
|
|
38
38
|
|
|
@@ -87,6 +87,8 @@ class ProfileConfig:
|
|
|
87
87
|
*configs: Any,
|
|
88
88
|
loader: LoaderType | Sequence[LoaderType] = None,
|
|
89
89
|
ignore_nonexist: bool = False,
|
|
90
|
+
base: str = "default",
|
|
91
|
+
allow_missing_base: bool = False,
|
|
90
92
|
) -> Diot:
|
|
91
93
|
"""Load the configuration from the files, or other configurations
|
|
92
94
|
|
|
@@ -98,6 +100,10 @@ class ProfileConfig:
|
|
|
98
100
|
same length as configs.
|
|
99
101
|
ignore_nonexist: Whether to ignore non-existent files
|
|
100
102
|
Otherwise, will raise errors
|
|
103
|
+
base: The default profile to use after loading
|
|
104
|
+
allow_missing_base: Whether to allow missing base profile
|
|
105
|
+
If False, will raise errors when the base profile is not found
|
|
106
|
+
in the loaded profiles.
|
|
101
107
|
"""
|
|
102
108
|
if not isinstance(loader, Sequence) or isinstance(loader, str):
|
|
103
109
|
loader = [loader] * len(configs)
|
|
@@ -132,7 +138,12 @@ class ProfileConfig:
|
|
|
132
138
|
pool.setdefault(profile, Diot())
|
|
133
139
|
pool[profile].update_recursively(value)
|
|
134
140
|
|
|
135
|
-
|
|
141
|
+
if base and base not in pool and not allow_missing_base:
|
|
142
|
+
raise ValueError(f"Base profile '{base}' not found")
|
|
143
|
+
|
|
144
|
+
if base and base in pool:
|
|
145
|
+
ProfileConfig.use_profile(out, base, base=base)
|
|
146
|
+
|
|
136
147
|
return out
|
|
137
148
|
|
|
138
149
|
@staticmethod
|
|
@@ -140,6 +151,8 @@ class ProfileConfig:
|
|
|
140
151
|
conf: Any,
|
|
141
152
|
loader: str | Loader | None = None,
|
|
142
153
|
ignore_nonexist: bool = False,
|
|
154
|
+
base: str = "default",
|
|
155
|
+
allow_missing_base: bool = False,
|
|
143
156
|
) -> Diot:
|
|
144
157
|
"""Load the configuration from the file
|
|
145
158
|
|
|
@@ -148,6 +161,7 @@ class ProfileConfig:
|
|
|
148
161
|
loader: The loader to use. Will detect from conf by default
|
|
149
162
|
ignore_nonexist: Whether to ignore non-existent files
|
|
150
163
|
Otherwise, will raise errors
|
|
164
|
+
base: The default profile to use after loading
|
|
151
165
|
|
|
152
166
|
Returns:
|
|
153
167
|
A Diot object with the loaded configuration
|
|
@@ -175,7 +189,12 @@ class ProfileConfig:
|
|
|
175
189
|
pool.setdefault(profile, Diot())
|
|
176
190
|
pool[profile].update_recursively(value)
|
|
177
191
|
|
|
178
|
-
|
|
192
|
+
if base and base not in pool and not allow_missing_base:
|
|
193
|
+
raise ValueError(f"Base profile '{base}' not found")
|
|
194
|
+
|
|
195
|
+
if base and base in pool:
|
|
196
|
+
ProfileConfig.use_profile(out, base, base=base)
|
|
197
|
+
|
|
179
198
|
return out
|
|
180
199
|
|
|
181
200
|
@staticmethod
|
|
@@ -184,24 +203,35 @@ class ProfileConfig:
|
|
|
184
203
|
profile: str,
|
|
185
204
|
base: str = "default",
|
|
186
205
|
copy: bool = False,
|
|
206
|
+
allow_missing_base: bool = False,
|
|
187
207
|
) -> Diot:
|
|
188
208
|
"""Switch the configuration to the given profile, based on the
|
|
189
|
-
|
|
209
|
+
base profile.
|
|
190
210
|
|
|
191
211
|
Args:
|
|
192
212
|
conf: The configuration object by the `load` function
|
|
193
213
|
profile: The profile to use
|
|
194
|
-
|
|
214
|
+
base: The base profile.
|
|
215
|
+
If it does not exist, no base profile will be used.
|
|
216
|
+
copy: Whether to return a new configuration object
|
|
217
|
+
If False, the given configuration object will be updated
|
|
218
|
+
in-place.
|
|
219
|
+
allow_missing_base: Whether to allow missing base profile
|
|
220
|
+
If False, will raise errors when the base profile is not found
|
|
221
|
+
in the loaded profiles.
|
|
195
222
|
|
|
196
223
|
Returns:
|
|
197
224
|
The configuration object with the switched profile if copy is True
|
|
198
225
|
Otherwise None (updated in-place)
|
|
199
226
|
"""
|
|
200
227
|
pool = conf[POOL_KEY]
|
|
228
|
+
if base and base not in pool and not allow_missing_base:
|
|
229
|
+
raise ValueError(f"Base profile '{base}' not found")
|
|
230
|
+
|
|
201
231
|
if copy:
|
|
202
232
|
out = Diot({POOL_KEY: pool, META_KEY: conf[META_KEY].copy()})
|
|
203
|
-
if base is not None:
|
|
204
|
-
out.update_recursively(pool
|
|
233
|
+
if base is not None and base != profile:
|
|
234
|
+
out.update_recursively(pool.get(base, {}))
|
|
205
235
|
out[META_KEY]["current_profile"] = profile
|
|
206
236
|
out[META_KEY]["base_profile"] = base
|
|
207
237
|
out.update_recursively(pool[profile])
|
|
@@ -213,8 +243,8 @@ class ProfileConfig:
|
|
|
213
243
|
continue
|
|
214
244
|
del conf[key]
|
|
215
245
|
|
|
216
|
-
if base is not None:
|
|
217
|
-
conf.update_recursively(pool
|
|
246
|
+
if base is not None and base != profile:
|
|
247
|
+
conf.update_recursively(pool.get(base, {}))
|
|
218
248
|
conf.update_recursively(pool[profile])
|
|
219
249
|
conf[META_KEY]["current_profile"] = profile
|
|
220
250
|
conf[META_KEY]["base_profile"] = base
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|