Skip to content

Commit

Permalink
Fix multiple substitutions replace
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Sep 21, 2021
1 parent 2903a24 commit 9ca6740
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions setuptools_git_versioning.py
Expand Up @@ -142,9 +142,9 @@ def subst_env_variables(template): # type: (str) -> str
value = os.environ.get(var)

if value:
template = ENV_VARS_REGEXP.sub(value, template)
template, _ = ENV_VARS_REGEXP.subn(value, template, count=1)
else:
template = ENV_VARS_REGEXP.sub("{" + (default or "UNKNOWN") + "}", template)
template, _ = ENV_VARS_REGEXP.subn("{" + (default or "UNKNOWN") + "}", template, count=1)

return template

Expand All @@ -153,8 +153,8 @@ def subst_timestamp(template): # type: (str) -> str
if "{timestamp" in template:
now = datetime.now()
for fmt in TIMESTAMP_REGEXP.findall(template):
result = now.strftime(fmt)
template = TIMESTAMP_REGEXP.sub(result, template)
result = now.strftime(fmt or "%s")
template, _ = TIMESTAMP_REGEXP.subn(result, template, count=1)

return template

Expand Down

0 comments on commit 9ca6740

Please sign in to comment.