Skip to content

Commit 44bd8fd

Browse files
authored
Replace forbidden chars in local version label (#11)
When putting a branch name after the + it may often contain characters that are outside of what's allowed by PEP 440. Replace them by '.' as needed Recent pip versions are particularly stringent.
1 parent c26dbcd commit 44bd8fd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

setuptools_git_versioning.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import subprocess
34

45
from setuptools.dist import Distribution
@@ -179,4 +180,9 @@ def version_from_git(template=DEFAULT_TEMPLATE,
179180
else:
180181
t = template
181182

182-
return t.format(sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha)
183+
version = t.format(sha=full_sha[:8], tag=tag, ccount=ccount, branch=branch, full_sha=full_sha)
184+
185+
# Ensure local version label only contains permitted characters
186+
public, sep, local = version.partition('+')
187+
local_sanitized = re.sub(r'[^a-zA-Z0-9.]', '.', local)
188+
return public + sep + local_sanitized

0 commit comments

Comments
 (0)