aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-03-15 15:31:09 -0400
committerJason R. Coombs <jaraco@jaraco.com>2020-03-15 15:31:09 -0400
commita323a4962eef39b6af7c5d07cdeb88bb0c307ce4 (patch)
tree6b32398f9e7e30e3119b2dcfe1720ffd1a60c27f /setuptools
parent24fa288a98a14e6ec57b996b151a48203322c936 (diff)
downloadexternal_python_setuptools-a323a4962eef39b6af7c5d07cdeb88bb0c307ce4.tar.gz
external_python_setuptools-a323a4962eef39b6af7c5d07cdeb88bb0c307ce4.tar.bz2
external_python_setuptools-a323a4962eef39b6af7c5d07cdeb88bb0c307ce4.zip
Extract method for normalization, allowing for bypass when the version is wrapped in 'sic'. Fixes #308.
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/__init__.py4
-rw-r--r--setuptools/dist.py28
2 files changed, 21 insertions, 11 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index 4485852f..811f3fd2 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -224,5 +224,9 @@ def findall(dir=os.curdir):
return list(files)
+class sic(str):
+ """Treat this string as-is (https://en.wikipedia.org/wiki/Sic)"""
+
+
# Apply monkey patches
monkey.patch_all()
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 0f71dd98..a2f8ea0d 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -30,6 +30,7 @@ from setuptools.extern.six.moves import map, filter, filterfalse
from . import SetuptoolsDeprecationWarning
+import setuptools
from setuptools import windows_support
from setuptools.monkey import get_unpatched
from setuptools.config import parse_configuration
@@ -438,10 +439,23 @@ class Distribution(_Distribution):
value = default() if default else None
setattr(self.metadata, option, value)
- self.metadata.version = self._validate_version(self.metadata.version)
+ self.metadata.version = self._normalize_version(
+ self._validate_version(self.metadata.version))
self._finalize_requires()
@staticmethod
+ def _normalize_version(version):
+ if isinstance(version, setuptools.sic) or version is None:
+ return version
+
+ normalized = str(packaging.version.Version(version))
+ if version != normalized:
+ tmpl = "Normalizing '{version}' to '{normalized}'"
+ warnings.warn(tmpl.format(**locals()))
+ return normalized
+ return version
+
+ @staticmethod
def _validate_version(version):
if isinstance(version, numbers.Number):
# Some people apparently take "version number" too literally :)
@@ -449,16 +463,7 @@ class Distribution(_Distribution):
if version is not None:
try:
- ver = packaging.version.Version(version)
- normalized_version = str(ver)
- if version != normalized_version:
- warnings.warn(
- "Normalizing '%s' to '%s'" % (
- version,
- normalized_version,
- )
- )
- version = normalized_version
+ packaging.version.Version(version)
except (packaging.version.InvalidVersion, TypeError):
warnings.warn(
"The version specified (%r) is an invalid version, this "
@@ -466,6 +471,7 @@ class Distribution(_Distribution):
"setuptools, pip, and PyPI. Please see PEP 440 for more "
"details." % version
)
+ return setuptools.sic(version)
return version
def _finalize_requires(self):