aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-03-20 21:44:43 -0400
committerGitHub <noreply@github.com>2020-03-20 21:44:43 -0400
commit060445bfb557a1d0f6b726716dafa6bacaa44c34 (patch)
tree93a45cc5aca5dd98a3074af3e0f9ab6fdc6b0997
parentb8c2ae517db14b03dfba263aa66707ca67ecee8f (diff)
parent8356ff3c6816d2a075098421252e096955d1fdbd (diff)
downloadexternal_python_setuptools-060445bfb557a1d0f6b726716dafa6bacaa44c34.tar.gz
external_python_setuptools-060445bfb557a1d0f6b726716dafa6bacaa44c34.tar.bz2
external_python_setuptools-060445bfb557a1d0f6b726716dafa6bacaa44c34.zip
Merge pull request #2026 from pypa/feature/308-bypass-normalization
Add 'sic' function to bypass version number normalization
-rw-r--r--changelog.d/308.change.rst1
-rw-r--r--setuptools/__init__.py4
-rw-r--r--setuptools/dist.py28
-rw-r--r--setuptools/tests/test_dist.py5
4 files changed, 27 insertions, 11 deletions
diff --git a/changelog.d/308.change.rst b/changelog.d/308.change.rst
new file mode 100644
index 00000000..5806d80e
--- /dev/null
+++ b/changelog.d/308.change.rst
@@ -0,0 +1 @@
+Allow version number normalization to be bypassed by wrapping in a 'setuptools.sic()' call.
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):
diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py
index a9837b16..531ea1b4 100644
--- a/setuptools/tests/test_dist.py
+++ b/setuptools/tests/test_dist.py
@@ -12,6 +12,7 @@ from setuptools.dist import (
check_package_data,
DistDeprecationWarning,
)
+from setuptools import sic
from setuptools import Distribution
from setuptools.extern.six.moves.urllib.request import pathname2url
from setuptools.extern.six.moves.urllib_parse import urljoin
@@ -133,6 +134,10 @@ def __read_test_cases():
name='foo',
version='1.0.0',
)),
+ ('Bypass normalized version', dict(
+ name='foo',
+ version=sic('1.0.0a'),
+ )),
]
return test_cases