yi-config-starter 0.1.3__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yi-config-starter
3
- Version: 0.1.3
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
- api_key: "{{ENV:MY_API_KEY}}"
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
-
@@ -67,20 +67,25 @@ Before parsing YAML, placeholders in the configuration file are substituted.
67
67
  | Placeholder | Description |
68
68
  | ------------------ | ---------------------------------------------- |
69
69
  | `{{HOME}}` | User home directory |
70
- | `{{separator}}` | OS path separator (`/` or `\`) |
70
+ | `{{separator}}` | OS path separator (`/` or `\\`) |
71
71
  | `{{APPDATA}}` | Windows `%APPDATA%` or fallback to `~/.config` |
72
72
  | `{{XDG_CONFIG}}` | `$XDG_CONFIG_HOME` or `~/.config` |
73
- | `{{ENV:VAR_NAME}}` | Value of environment variable `VAR_NAME` |
73
+ | `{{ENV:VAR_NAME}}` | Value of environment variable `VAR_NAME` (case-insensitive: `ENV`/`env`) |
74
74
 
75
75
  Custom placeholders may be supplied via `extra_placeholders`.
76
76
 
77
+ ### Unresolved placeholders
78
+
79
+ After preprocessing, if any `{{...}}` placeholders remain unresolved, a `ValueError` is raised listing **all** unresolved placeholder names.
80
+
77
81
  ### Example
78
82
 
79
83
  ```yaml
80
84
  paths:
81
85
  data_dir: "{{HOME}}{{separator}}data"
82
86
  cache_dir: "{{XDG_CONFIG}}{{separator}}my-app{{separator}}cache"
83
- api_key: "{{ENV:MY_API_KEY}}"
87
+ # ENV token is case-insensitive, so {{env:...}} also works:
88
+ api_key: "{{env:MY_API_KEY}}"
84
89
  ```
85
90
 
86
91
  ---
@@ -131,4 +136,3 @@ Defined in:
131
136
  ## License
132
137
 
133
138
  MIT License — see the `LICENSE` file.
134
-
@@ -4,5 +4,5 @@ from yi_config_starter.config_starter import ApplicationConfiguration
4
4
 
5
5
  logging.getLogger(__name__).addHandler(logging.NullHandler())
6
6
 
7
- __version__ = "0.1.3"
7
+ __version__ = "0.2.1"
8
8
  __all__ = ["ApplicationConfiguration"]
@@ -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
- # Simple scan to avoid regex: find all occurrences of {{ENV:...}}
194
- start = 0
195
- while True:
196
- i = text.find("{{ENV:", start)
197
- if i == -1:
198
- break
199
- j = text.find("}}", i + 6)
200
- if j == -1:
201
- break # unmatched; let YAML error out naturally
202
- env_key = text[i + 6: j].strip() # after "ENV:"
203
- env_val = os.environ.get(env_key, "")
204
- text = text[:i] + env_val + text[j + 2:]
205
- 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)
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
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
- api_key: "{{ENV:MY_API_KEY}}"
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
-