yi-config-starter 0.1.3__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 +21 -15
- {yi_config_starter-0.1.3.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.1.3.dist-info/RECORD +0 -7
- {yi_config_starter-0.1.3.dist-info → yi_config_starter-0.2.1.dist-info}/WHEEL +0 -0
- {yi_config_starter-0.1.3.dist-info → yi_config_starter-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {yi_config_starter-0.1.3.dist-info → yi_config_starter-0.2.1.dist-info}/top_level.txt +0 -0
yi_config_starter/__init__.py
CHANGED
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import logging
|
|
7
7
|
import os
|
|
8
|
+
import re
|
|
8
9
|
import sys
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
from threading import RLock
|
|
@@ -166,8 +167,10 @@ class ApplicationConfiguration:
|
|
|
166
167
|
{{separator}} -> os.sep
|
|
167
168
|
{{APPDATA}} -> Windows %APPDATA% or "~/.config" fallback
|
|
168
169
|
{{XDG_CONFIG}} -> $XDG_CONFIG_HOME or "~/.config"
|
|
169
|
-
{{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)
|
|
170
171
|
You can pass extra_placeholders to override or add tokens.
|
|
172
|
+
|
|
173
|
+
After replacements, raises ValueError if any unresolved {{...}} placeholders remain.
|
|
171
174
|
"""
|
|
172
175
|
# base mapping
|
|
173
176
|
appdata = os.environ.get("APPDATA") or str(Path.home() / ".config")
|
|
@@ -189,20 +192,23 @@ class ApplicationConfiguration:
|
|
|
189
192
|
for k, v in mapping.items():
|
|
190
193
|
text = text.replace(f"{{{{{k}}}}}", v)
|
|
191
194
|
|
|
192
|
-
# Replace {{ENV:NAME}} tokens
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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)
|
|
202
|
+
|
|
203
|
+
# Fail fast if any unresolved placeholders remain.
|
|
204
|
+
# We consider anything shaped like {{...}} to be a placeholder at this stage.
|
|
205
|
+
unresolved = {m.group(1).strip() for m in re.finditer(r"\{\{([^{}]+)}}", text)}
|
|
206
|
+
if unresolved:
|
|
207
|
+
names = ", ".join(sorted(unresolved))
|
|
208
|
+
raise ValueError(
|
|
209
|
+
f"Unresolved placeholders in config after preprocessing: {names}. "
|
|
210
|
+
f"Define them via built-ins, extra_placeholders, or environment variables using {{ENV:NAME}}."
|
|
211
|
+
)
|
|
206
212
|
|
|
207
213
|
return text
|
|
208
214
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: yi-config-starter
|
|
3
|
-
Version: 0.1
|
|
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=BLo5vO4l2d1CERyNxrNNG3JeRbe8T24IC_3Us4b3se8,211
|
|
2
|
-
yi_config_starter/config_starter.py,sha256=vlL9BdFA-XX5tssH8rRwxR4_Tod_hMrcBTUMbbqHzpY,8872
|
|
3
|
-
yi_config_starter-0.1.3.dist-info/licenses/LICENSE,sha256=eiNb74NQUNWxg1y2zfb3vtFX4nj-H5bfJU1kBzcJQK0,1071
|
|
4
|
-
yi_config_starter-0.1.3.dist-info/METADATA,sha256=tuDNVGdljoADtcaOBTnK9Q1BeVX_V_tHxEIH9L69SDc,4626
|
|
5
|
-
yi_config_starter-0.1.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
yi_config_starter-0.1.3.dist-info/top_level.txt,sha256=EVuzCCMDDGlEOePW0nBaNZARp2rpRZEW9v29OmJms0U,18
|
|
7
|
-
yi_config_starter-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|