-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fix: Support PEP 440 pre-release versions (#8)
- Loading branch information
Showing
2 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
""" | ||
|
@@ -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): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.""" | ||
|
@@ -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): | ||
|