small-toolkit 0.1.2__tar.gz → 0.1.3__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.
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/PKG-INFO +1 -1
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/pyproject.toml +1 -1
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/small_toolkit/cli.py +7 -8
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/tests/test_cli.py +15 -3
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/.github/workflows/publish-test.yml +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/.github/workflows/publish.yml +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/.gitignore +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/README.md +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/small_toolkit/__init__.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/small_toolkit/logs.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/small_toolkit/outputs.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/small_toolkit/table.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/tests/test_logs.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/tests/test_outputs.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/tests/test_table.py +0 -0
- {small_toolkit-0.1.2 → small_toolkit-0.1.3}/uv.lock +0 -0
|
@@ -116,10 +116,11 @@ def resolve_env_var(env: str, base_name: str) -> str | None:
|
|
|
116
116
|
|
|
117
117
|
1. ``{base_name}_LIST`` — 分号分隔的 ``env=value`` 格式(最高优先级)
|
|
118
118
|
2. ``{base_name}_{ENV}`` — 单环境变量
|
|
119
|
-
3. ``{base_name}`` —
|
|
119
|
+
3. ``{base_name}`` — 原生变量名(任何环境都回退)
|
|
120
120
|
|
|
121
|
-
任一来源有值(含空字符串)即返回,全缺失返回 ``None
|
|
122
|
-
|
|
121
|
+
任一来源有值(含空字符串)即返回,全缺失返回 ``None``。三层对所有环境一致:
|
|
122
|
+
``tst`` / ``uat`` 在没有 ``_LIST`` 条目、也没有 ``_{ENV}`` 后缀变量时同样回退到原生名,
|
|
123
|
+
便于变量整合后只保留裸名的场景。
|
|
123
124
|
|
|
124
125
|
例(值由外部注入,本库不读写凭据)::
|
|
125
126
|
|
|
@@ -140,8 +141,6 @@ def resolve_env_var(env: str, base_name: str) -> str | None:
|
|
|
140
141
|
env_val = os.environ.get(f"{base_name}_{env.upper()}", "").strip()
|
|
141
142
|
if env_val:
|
|
142
143
|
return env_val
|
|
143
|
-
# 3.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return fallback or None
|
|
147
|
-
return None
|
|
144
|
+
# 3. 回退原生变量(所有环境统一)
|
|
145
|
+
fallback = os.environ.get(base_name, "").strip()
|
|
146
|
+
return fallback or None
|
|
@@ -98,11 +98,23 @@ def test_resolve_env_var_list_key_is_case_insensitive(monkeypatch):
|
|
|
98
98
|
assert resolve_env_var("uat", "TOOLKIT_TEST_URL") == "c:8030"
|
|
99
99
|
|
|
100
100
|
|
|
101
|
-
def
|
|
101
|
+
def test_resolve_env_var_falls_back_to_native_for_any_env(monkeypatch):
|
|
102
102
|
monkeypatch.setenv("TOOLKIT_TEST_URL", "native")
|
|
103
|
+
|
|
103
104
|
assert resolve_env_var("prod", "TOOLKIT_TEST_URL") == "native"
|
|
104
|
-
# 非 prod
|
|
105
|
-
assert resolve_env_var("
|
|
105
|
+
# 非 prod 环境同样回退原生变量
|
|
106
|
+
assert resolve_env_var("tst", "TOOLKIT_TEST_URL") == "native"
|
|
107
|
+
assert resolve_env_var("uat", "TOOLKIT_TEST_URL") == "native"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_resolve_env_var_list_and_suffix_win_over_native(monkeypatch):
|
|
111
|
+
monkeypatch.setenv("TOOLKIT_TEST_URL", "native")
|
|
112
|
+
monkeypatch.setenv("TOOLKIT_TEST_URL_TST", "single")
|
|
113
|
+
|
|
114
|
+
assert resolve_env_var("tst", "TOOLKIT_TEST_URL") == "single"
|
|
115
|
+
|
|
116
|
+
monkeypatch.setenv("TOOLKIT_TEST_URL_LIST", "tst=listed")
|
|
117
|
+
assert resolve_env_var("tst", "TOOLKIT_TEST_URL") == "listed"
|
|
106
118
|
|
|
107
119
|
|
|
108
120
|
def test_resolve_env_var_missing_returns_none(monkeypatch):
|
|
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
|