|
27 | 27 | ENV_VARS_REGEXP = re.compile(r"\{env:(?P<name>[^:}]+):?(?P<default>[^}]+\}*)?\}", re.IGNORECASE | re.UNICODE)
|
28 | 28 | TIMESTAMP_REGEXP = re.compile(r"\{timestamp:?(?P<fmt>[^:}]+)?\}", re.IGNORECASE | re.UNICODE)
|
29 | 29 |
|
| 30 | +# https://github.com/pypa/setuptools/blob/bc39d28bda2a1faee6680ae30e42526b9d775151/setuptools/command/dist_info.py#L108-L131 |
| 31 | +UNSUPPORTED_SYMBOL_REGEXP = re.compile(r"[^\w\d]+", re.IGNORECASE | re.UNICODE) |
| 32 | + |
30 | 33 | LOG_FORMAT = "[%(asctime)s] %(levelname)+8s: %(message)s"
|
31 | 34 | # setuptools v60.2.0 changed default logging level to DEBUG: https://github.com/pypa/setuptools/pull/2974
|
32 | 35 | # to avoid printing information messages to the same output as version number,
|
@@ -447,7 +450,19 @@ def get_version_from_callback(
|
447 | 450 | def sanitize_version(version: str) -> str:
|
448 | 451 | log.log(INFO, "Before sanitization %r", version)
|
449 | 452 |
|
450 |
| - result = str(Version(version)) |
| 453 | + public, sep, local = version.partition("+") |
| 454 | + |
| 455 | + # replace "feature/ABC-123" with "feature.ABC.123" |
| 456 | + sanitized_public = UNSUPPORTED_SYMBOL_REGEXP.sub(".", public) |
| 457 | + sanitized_local = UNSUPPORTED_SYMBOL_REGEXP.sub(".", local) |
| 458 | + |
| 459 | + sanitized_version = sanitized_public + sep + sanitized_local |
| 460 | + sanitized_version = sanitized_version.rstrip(".") |
| 461 | + |
| 462 | + # replace "feature.ABC.123" with "feature.abc.123" |
| 463 | + # drop leading "v" symbol |
| 464 | + # other replacements according to PEP-440, like "-dev" -> ".dev" |
| 465 | + result = str(Version(sanitized_version)) |
451 | 466 | log.log(INFO, "Result %r", result)
|
452 | 467 | return result
|
453 | 468 |
|
|
0 commit comments