yi-config-starter 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
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.
- yi_config_starter/__init__.py +1 -1
- yi_config_starter/config_starter.py +8 -15
- {yi_config_starter-0.2.0.dist-info → yi_config_starter-0.2.1.dist-info}/METADATA +9 -5
- yi_config_starter-0.2.1.dist-info/RECORD +7 -0
- yi_config_starter-0.2.0.dist-info/RECORD +0 -7
- {yi_config_starter-0.2.0.dist-info → yi_config_starter-0.2.1.dist-info}/WHEEL +0 -0
- {yi_config_starter-0.2.0.dist-info → yi_config_starter-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {yi_config_starter-0.2.0.dist-info → yi_config_starter-0.2.1.dist-info}/top_level.txt +0 -0
yi_config_starter/__init__.py
CHANGED
|
@@ -167,7 +167,7 @@ class ApplicationConfiguration:
|
|
|
167
167
|
{{separator}} -> os.sep
|
|
168
168
|
{{APPDATA}} -> Windows %APPDATA% or "~/.config" fallback
|
|
169
169
|
{{XDG_CONFIG}} -> $XDG_CONFIG_HOME or "~/.config"
|
|
170
|
-
{{ENV:VAR_NAME}} -> value of environment variable VAR_NAME (empty if missing)
|
|
170
|
+
{{ENV:VAR_NAME}} -> value of environment variable VAR_NAME (empty if missing) (case-insensitive ENV)
|
|
171
171
|
You can pass extra_placeholders to override or add tokens.
|
|
172
172
|
|
|
173
173
|
After replacements, raises ValueError if any unresolved {{...}} placeholders remain.
|
|
@@ -192,20 +192,13 @@ class ApplicationConfiguration:
|
|
|
192
192
|
for k, v in mapping.items():
|
|
193
193
|
text = text.replace(f"{{{{{k}}}}}", v)
|
|
194
194
|
|
|
195
|
-
# Replace {{ENV:NAME}} tokens
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
j = text.find("}}", i + 6)
|
|
203
|
-
if j == -1:
|
|
204
|
-
break # unmatched; let YAML error out naturally
|
|
205
|
-
env_key = text[i + 6: j].strip() # after "ENV:"
|
|
206
|
-
env_val = os.environ.get(env_key, "")
|
|
207
|
-
text = text[:i] + env_val + text[j + 2:]
|
|
208
|
-
start = i + len(env_val)
|
|
195
|
+
# Replace {{ENV:NAME}} tokens (case-insensitive ENV)
|
|
196
|
+
def _env_repl(match: re.Match) -> str:
|
|
197
|
+
env_key = match.group(1).strip()
|
|
198
|
+
return os.environ.get(env_key, "")
|
|
199
|
+
|
|
200
|
+
# Examples matched: {{ENV:PATH}}, {{env:Path}}, {{ Env : PATH }}
|
|
201
|
+
text = re.sub(r"\{\{\s*env\s*:\s*([^{}]+?)\s*}}", _env_repl, text, flags=re.IGNORECASE)
|
|
209
202
|
|
|
210
203
|
# Fail fast if any unresolved placeholders remain.
|
|
211
204
|
# We consider anything shaped like {{...}} to be a placeholder at this stage.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: yi-config-starter
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Config starter for my local projects
|
|
5
5
|
Author: Yunus Indori
|
|
6
6
|
License: MIT License
|
|
@@ -100,20 +100,25 @@ Before parsing YAML, placeholders in the configuration file are substituted.
|
|
|
100
100
|
| Placeholder | Description |
|
|
101
101
|
| ------------------ | ---------------------------------------------- |
|
|
102
102
|
| `{{HOME}}` | User home directory |
|
|
103
|
-
| `{{separator}}` | OS path separator (`/` or
|
|
103
|
+
| `{{separator}}` | OS path separator (`/` or `\\`) |
|
|
104
104
|
| `{{APPDATA}}` | Windows `%APPDATA%` or fallback to `~/.config` |
|
|
105
105
|
| `{{XDG_CONFIG}}` | `$XDG_CONFIG_HOME` or `~/.config` |
|
|
106
|
-
| `{{ENV:VAR_NAME}}` | Value of environment variable `VAR_NAME`
|
|
106
|
+
| `{{ENV:VAR_NAME}}` | Value of environment variable `VAR_NAME` (case-insensitive: `ENV`/`env`) |
|
|
107
107
|
|
|
108
108
|
Custom placeholders may be supplied via `extra_placeholders`.
|
|
109
109
|
|
|
110
|
+
### Unresolved placeholders
|
|
111
|
+
|
|
112
|
+
After preprocessing, if any `{{...}}` placeholders remain unresolved, a `ValueError` is raised listing **all** unresolved placeholder names.
|
|
113
|
+
|
|
110
114
|
### Example
|
|
111
115
|
|
|
112
116
|
```yaml
|
|
113
117
|
paths:
|
|
114
118
|
data_dir: "{{HOME}}{{separator}}data"
|
|
115
119
|
cache_dir: "{{XDG_CONFIG}}{{separator}}my-app{{separator}}cache"
|
|
116
|
-
|
|
120
|
+
# ENV token is case-insensitive, so {{env:...}} also works:
|
|
121
|
+
api_key: "{{env:MY_API_KEY}}"
|
|
117
122
|
```
|
|
118
123
|
|
|
119
124
|
---
|
|
@@ -164,4 +169,3 @@ Defined in:
|
|
|
164
169
|
## License
|
|
165
170
|
|
|
166
171
|
MIT License — see the `LICENSE` file.
|
|
167
|
-
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
yi_config_starter/__init__.py,sha256=_2q1IdbQh1KBA2rULxO5U73TQJbSvgQmC0jrkE84RWA,211
|
|
2
|
+
yi_config_starter/config_starter.py,sha256=MSwg4etZeVmUaC9XM0orsoHqcXnE6Lz2LCs1SIH3pUg,9347
|
|
3
|
+
yi_config_starter-0.2.1.dist-info/licenses/LICENSE,sha256=eiNb74NQUNWxg1y2zfb3vtFX4nj-H5bfJU1kBzcJQK0,1071
|
|
4
|
+
yi_config_starter-0.2.1.dist-info/METADATA,sha256=z7n7KxLnvUO-ZwFzLTC5J_XAs5QXFyXVjSL13SJe_Cg,4885
|
|
5
|
+
yi_config_starter-0.2.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
yi_config_starter-0.2.1.dist-info/top_level.txt,sha256=EVuzCCMDDGlEOePW0nBaNZARp2rpRZEW9v29OmJms0U,18
|
|
7
|
+
yi_config_starter-0.2.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
yi_config_starter/__init__.py,sha256=qk-S5AsIwsqcjIxfWCxyhmDQkNKwUequbFaCiU_ll9s,211
|
|
2
|
-
yi_config_starter/config_starter.py,sha256=r5-thEc4YIuU8x5I455ZL-0MyiYs6h5I_-g-SZy-E0s,9522
|
|
3
|
-
yi_config_starter-0.2.0.dist-info/licenses/LICENSE,sha256=eiNb74NQUNWxg1y2zfb3vtFX4nj-H5bfJU1kBzcJQK0,1071
|
|
4
|
-
yi_config_starter-0.2.0.dist-info/METADATA,sha256=nFPRiA24ak8By2HOvIX9uj9sVA2quXtuf5St023PIoM,4626
|
|
5
|
-
yi_config_starter-0.2.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
yi_config_starter-0.2.0.dist-info/top_level.txt,sha256=EVuzCCMDDGlEOePW0nBaNZARp2rpRZEW9v29OmJms0U,18
|
|
7
|
-
yi_config_starter-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|