Skip to content

Commit

Permalink
Bug fix: Support PEP 440 pre-release versions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Aug 7, 2017
1 parent 53ba60c commit 56b4848
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion py2deb/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automated tests for the `py2deb' package.
#
# Author: Peter Odding <[email protected]>
# Last Change: May 22, 2017
# Last Change: August 7, 2017
# URL: https://py2deb.readthedocs.io

"""
Expand Down Expand Up @@ -142,6 +142,11 @@ def test_version_reformatting(self):
"""Test reformatting of Python version strings."""
assert normalize_package_version('1.5_42') == '1.5-42'
assert normalize_package_version('1.5-whatever') == '1.5-whatever-1'
# PEP 440 pre-release versions.
assert normalize_package_version('1.0a2') == '1.0~a2'
assert normalize_package_version('1.0b2') == '1.0~b2'
assert normalize_package_version('1.0c2') == '1.0~rc2'
assert normalize_package_version('1.0rc2') == '1.0~rc2'

def test_conversion_of_simple_package(self):
"""
Expand Down
20 changes: 15 additions & 5 deletions py2deb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Authors:
# - Arjan Verwer
# - Peter Odding <[email protected]>
# Last Change: May 22, 2017
# Last Change: August 8, 2017
# URL: https://py2deb.readthedocs.io

"""The :mod:`py2deb.utils` module contains miscellaneous code."""
Expand Down Expand Up @@ -184,14 +184,24 @@ def normalize_package_version(python_package_version):
Reformats Python package versions to comply with the Debian policy manual.
All characters except alphanumerics, dot (``.``) and plus (``+``) are
replaced with dashes (``-``).
The PEP 440 pre-release identifiers 'a', 'b', 'c' and 'rc' are prefixed by
a tilde (``~``) to replicate the intended ordering in Debian versions, also
the identifier 'c' is translated into 'rc'. Refer to `issue #8
<https://github.com/paylogic/py2deb/issues/8>`_ for details.
"""
sanitized_version = re.sub('[^a-z0-9.+]+', '-', python_package_version.lower()).strip('-')
components = sanitized_version.split('-')
# Lowercase and remove invalid characters from the version string.
version = re.sub('[^a-z0-9.+]+', '-', python_package_version.lower()).strip('-')
# Translate the PEP 440 pre-release identifier 'c' to 'rc'.
version = re.sub(r'(\d)c(\d)', r'\1rc\2', version)
# Replicate the intended ordering of PEP 440 pre-release versions (a, b, rc).
version = re.sub(r'(\d)(a|b|rc)(\d)', r'\1~\2\3', version)
# Make sure the "Debian revision" contains a digit.
components = version.split('-')
if len(components) > 1 and not re.search('[0-9]', components[-1]):
components.append('1')
sanitized_version = '-'.join(components)
return sanitized_version
version = '-'.join(components)
return version


def tokenize_version(version_number):
Expand Down

0 comments on commit 56b4848

Please sign in to comment.