Skip to content

Commit cad4e92

Browse files
committed
Allow to ignore env variable substitution default value
1 parent 9d0d7d8 commit cad4e92

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,9 @@ You can use these substitutions in `template`, `dev_template` or `dirty_template
498498
499499
- `{env:SOMEVAR}`: Value of environment variable `SOMEVAR`. Examples:
500500
501-
- You can pass default value using `{env:SOMEVAR:default}` syntax. Default value for missing variables is `UNKNOWN`.
501+
- You can pass default value using `{env:SOMEVAR:default}` syntax.
502+
503+
- Default value for missing variables is `UNKNOWN`. If you need to just skip the substitution, use `{env:SOMEVAR:IGNORE}` syntax.
502504
503505
- It is possible to pass another substitution instead of a default value using `{env:SOMEVAR:{subst}}` syntax, e.g. `{env:BUILD_NUMBER:{ccount}}`.
504506

setuptools_git_versioning.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ def read_version_from_file(path): # type: (Union[str, os.PathLike]) -> str
139139
def subst_env_variables(template): # type: (str) -> str
140140
if "{env" in template:
141141
for var, default in ENV_VARS_REGEXP.findall(template):
142-
value = os.environ.get(var, default or "UNKNOWN")
142+
if default.upper() == "IGNORE":
143+
default = ""
144+
elif not default:
145+
default = "UNKNOWN"
146+
147+
value = os.environ.get(var, default)
143148
template, _ = ENV_VARS_REGEXP.subn(value, template, count=1)
144149

145150
return template

0 commit comments

Comments
 (0)