Skip to content

Commit 46c40cd

Browse files
committed
Merged pull request #22: Don't normalize local version labels
2 parents f4316e5 + 1f68010 commit 46c40cd

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

py2deb/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ def test_version_reformatting(self):
161161
assert normalize_package_version('1.0b2') == '1.0~b2'
162162
assert normalize_package_version('1.0c2') == '1.0~rc2'
163163
assert normalize_package_version('1.0rc2') == '1.0~rc2'
164+
# Do not modify local version labels
165+
assert normalize_package_version('1.0+a2') == '1.0+a2'
166+
assert normalize_package_version('1.0+b2') == '1.0+b2'
167+
assert normalize_package_version('1.0+c2') == '1.0+c2'
168+
assert normalize_package_version('1.0+65c43') == '1.0+65c43'
164169
# New versus old behavior (the option to control backwards compatibility was added in release 2.1).
165170
assert normalize_package_version('1.0a2', prerelease_workaround=True) == '1.0~a2'
166171
assert normalize_package_version('1.0a2', prerelease_workaround=False) == '1.0a2'

py2deb/utils.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Authors:
44
# - Arjan Verwer
55
# - Peter Odding <peter.odding@paylogic.com>
6-
# Last Change: July 28, 2020
6+
# Last Change: August 4, 2020
77
# URL: https://py2deb.readthedocs.io
88

99
"""The :mod:`py2deb.utils` module contains miscellaneous code."""
@@ -363,19 +363,31 @@ def normalize_package_version(python_package_version, prerelease_workaround=True
363363
the identifier 'c' is translated into 'rc'. Refer to `issue #8
364364
<https://github.com/paylogic/py2deb/issues/8>`_ for details.
365365
"""
366-
# Lowercase and remove invalid characters from the version string.
367-
version = re.sub('[^a-z0-9.+]+', '-', python_package_version.lower()).strip('-')
366+
# We need to avoid normalizing "local version labels" (naming from PEP 440)
367+
# because these may contain strings such as SCM hashes that should not be
368+
# altered, so we split the version string into the "public version
369+
# identifier" and "local version label" and only apply normalization to the
370+
# "public version identifier".
371+
public_version, delimiter, local_version = python_package_version.partition('+')
372+
# Lowercase and remove invalid characters from the "public version identifier".
373+
public_version = re.sub('[^a-z0-9.+]+', '-', public_version.lower()).strip('-')
368374
if prerelease_workaround:
369375
# Translate the PEP 440 pre-release identifier 'c' to 'rc'.
370-
version = re.sub(r'(\d)c(\d)', r'\1rc\2', version)
376+
public_version = re.sub(r'(\d)c(\d)', r'\1rc\2', public_version)
371377
# Replicate the intended ordering of PEP 440 pre-release versions (a, b, rc).
372-
version = re.sub(r'(\d)(a|b|rc)(\d)', r'\1~\2\3', version)
373-
# Make sure the "Debian revision" contains a digit.
374-
components = version.split('-')
375-
if len(components) > 1 and not re.search('[0-9]', components[-1]):
376-
components.append('1')
377-
version = '-'.join(components)
378-
return version
378+
public_version = re.sub(r'(\d)(a|b|rc)(\d)', r'\1~\2\3', public_version)
379+
# Restore the local version label (without any normalization).
380+
if local_version:
381+
public_version = public_version + '+' + local_version
382+
# Make sure the "Debian revision" contains a digit. If we don't find one we
383+
# add it ourselves, to prevent dpkg and apt from aborting (!) as soon as
384+
# they see an invalid Debian revision...
385+
if '-' in public_version:
386+
components = public_version.split('-')
387+
if len(components) > 1 and not re.search('[0-9]', components[-1]):
388+
components.append('1')
389+
public_version = '-'.join(components)
390+
return public_version
379391

380392

381393
def package_names_match(a, b):

0 commit comments

Comments
 (0)