summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-12 11:42:59 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-12-12 11:44:59 -0500
commite65aa0ac5a66b19ee2442a0f072c453330c5726b (patch)
tree21bbee56bc856620ee90c10925f94c17a5fa2c42
parent3aa9e83db97fd70ee643890c270b895324b049bd (diff)
parent92082ee42c80b4a087053118e493cfa07084d867 (diff)
downloadpython-setuptools-git-debt/deprecate-version.tar.gz
Merge with pypa/distutils@92082ee42c.debt/deprecate-version
-rw-r--r--changelog.d/2925.change.rst1
-rw-r--r--setuptools/_distutils/command/build_ext.py4
-rw-r--r--setuptools/_distutils/cygwinccompiler.py8
-rw-r--r--setuptools/_distutils/tests/test_version.py8
-rw-r--r--setuptools/_distutils/version.py28
-rw-r--r--setuptools/_distutils/versionpredicate.py7
6 files changed, 42 insertions, 14 deletions
diff --git a/changelog.d/2925.change.rst b/changelog.d/2925.change.rst
new file mode 100644
index 00000000..c28f29cd
--- /dev/null
+++ b/changelog.d/2925.change.rst
@@ -0,0 +1 @@
+Merge with pypa/distutils@92082ee42c including introduction of deprecation warning on Version classes.
diff --git a/setuptools/_distutils/command/build_ext.py b/setuptools/_distutils/command/build_ext.py
index 22628baf..181671bf 100644
--- a/setuptools/_distutils/command/build_ext.py
+++ b/setuptools/_distutils/command/build_ext.py
@@ -202,9 +202,7 @@ class build_ext(Command):
# Append the source distribution include and library directories,
# this allows distutils on windows to work in the source tree
self.include_dirs.append(os.path.dirname(get_config_h_filename()))
- _sys_home = getattr(sys, '_home', None)
- if _sys_home:
- self.library_dirs.append(_sys_home)
+ self.library_dirs.append(sys.base_exec_prefix)
# Use the .lib files for the correct architecture
if self.plat_name == 'win32':
diff --git a/setuptools/_distutils/cygwinccompiler.py b/setuptools/_distutils/cygwinccompiler.py
index f80ca622..ad6cc44b 100644
--- a/setuptools/_distutils/cygwinccompiler.py
+++ b/setuptools/_distutils/cygwinccompiler.py
@@ -53,6 +53,7 @@ import copy
from subprocess import Popen, PIPE, check_output
import re
+import distutils.version
from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file
from distutils.errors import (DistutilsExecError, CCompilerError,
@@ -405,9 +406,10 @@ def _find_exe_version(cmd):
result = RE_VERSION.search(out_string)
if result is None:
return None
- # LooseVersion works with strings
- # so we need to decode our bytes
- return LooseVersion(result.group(1).decode())
+ # LooseVersion works with strings; decode
+ ver_str = result.group(1).decode()
+ with distutils.version.suppress_known_deprecation():
+ return LooseVersion(ver_str)
def get_versions():
""" Try to find out the versions of gcc, ld and dllwrap.
diff --git a/setuptools/_distutils/tests/test_version.py b/setuptools/_distutils/tests/test_version.py
index 8671cd2f..d50cca1f 100644
--- a/setuptools/_distutils/tests/test_version.py
+++ b/setuptools/_distutils/tests/test_version.py
@@ -1,11 +1,19 @@
"""Tests for distutils.version."""
import unittest
+import distutils
from distutils.version import LooseVersion
from distutils.version import StrictVersion
from test.support import run_unittest
class VersionTestCase(unittest.TestCase):
+ def setUp(self):
+ self.ctx = distutils.version.suppress_known_deprecation()
+ self.ctx.__enter__()
+
+ def tearDown(self):
+ self.ctx.__exit__(None, None, None)
+
def test_prerelease(self):
version = StrictVersion('1.2.3a1')
self.assertEqual(version.version, (1, 2, 3))
diff --git a/setuptools/_distutils/version.py b/setuptools/_distutils/version.py
index c33bebae..35e181db 100644
--- a/setuptools/_distutils/version.py
+++ b/setuptools/_distutils/version.py
@@ -27,6 +27,20 @@ Every version number class implements the following interface:
"""
import re
+import warnings
+import contextlib
+
+
+@contextlib.contextmanager
+def suppress_known_deprecation():
+ with warnings.catch_warnings(record=True) as ctx:
+ warnings.filterwarnings(
+ action='default',
+ category=DeprecationWarning,
+ message="distutils Version classes are deprecated.",
+ )
+ yield ctx
+
class Version:
"""Abstract base class for version numbering classes. Just provides
@@ -36,6 +50,12 @@ class Version:
"""
def __init__ (self, vstring=None):
+ warnings.warn(
+ "distutils Version classes are deprecated. "
+ "Use packaging.version instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
if vstring:
self.parse(vstring)
@@ -165,7 +185,8 @@ class StrictVersion (Version):
def _cmp (self, other):
if isinstance(other, str):
- other = StrictVersion(other)
+ with suppress_known_deprecation():
+ other = StrictVersion(other)
elif not isinstance(other, StrictVersion):
return NotImplemented
@@ -301,11 +322,6 @@ class LooseVersion (Version):
component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)
- def __init__ (self, vstring=None):
- if vstring:
- self.parse(vstring)
-
-
def parse (self, vstring):
# I've given up on thinking I can reconstruct the version string
# from the parsed tuple -- so I just store the string here for
diff --git a/setuptools/_distutils/versionpredicate.py b/setuptools/_distutils/versionpredicate.py
index 062c98f2..55f25d91 100644
--- a/setuptools/_distutils/versionpredicate.py
+++ b/setuptools/_distutils/versionpredicate.py
@@ -23,7 +23,9 @@ def splitUp(pred):
if not res:
raise ValueError("bad package restriction syntax: %r" % pred)
comp, verStr = res.groups()
- return (comp, distutils.version.StrictVersion(verStr))
+ with distutils.version.suppress_known_deprecation():
+ other = distutils.version.StrictVersion(verStr)
+ return (comp, other)
compmap = {"<": operator.lt, "<=": operator.le, "==": operator.eq,
">": operator.gt, ">=": operator.ge, "!=": operator.ne}
@@ -162,5 +164,6 @@ def split_provision(value):
raise ValueError("illegal provides specification: %r" % value)
ver = m.group(2) or None
if ver:
- ver = distutils.version.StrictVersion(ver)
+ with distutils.version.suppress_known_deprecation():
+ ver = distutils.version.StrictVersion(ver)
return m.group(1), ver