|
3 | 3 | # Authors:
|
4 | 4 | # - Arjan Verwer
|
5 | 5 | # - Peter Odding <peter.odding@paylogic.com>
|
6 |
| -# Last Change: July 28, 2020 |
| 6 | +# Last Change: August 4, 2020 |
7 | 7 | # URL: https://py2deb.readthedocs.io
|
8 | 8 |
|
9 | 9 | """The :mod:`py2deb.utils` module contains miscellaneous code."""
|
@@ -363,19 +363,31 @@ def normalize_package_version(python_package_version, prerelease_workaround=True
|
363 | 363 | the identifier 'c' is translated into 'rc'. Refer to `issue #8
|
364 | 364 | <https://github.com/paylogic/py2deb/issues/8>`_ for details.
|
365 | 365 | """
|
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('-') |
368 | 374 | if prerelease_workaround:
|
369 | 375 | # 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) |
371 | 377 | # 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 |
379 | 391 |
|
380 | 392 |
|
381 | 393 | def package_names_match(a, b):
|
|
0 commit comments