diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-12 11:42:59 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-12 11:44:59 -0500 |
commit | e65aa0ac5a66b19ee2442a0f072c453330c5726b (patch) | |
tree | 21bbee56bc856620ee90c10925f94c17a5fa2c42 /setuptools/_distutils/version.py | |
parent | 3aa9e83db97fd70ee643890c270b895324b049bd (diff) | |
parent | 92082ee42c80b4a087053118e493cfa07084d867 (diff) | |
download | python-setuptools-git-e65aa0ac5a66b19ee2442a0f072c453330c5726b.tar.gz |
Merge with pypa/distutils@92082ee42c.debt/deprecate-version
Diffstat (limited to 'setuptools/_distutils/version.py')
-rw-r--r-- | setuptools/_distutils/version.py | 28 |
1 files changed, 22 insertions, 6 deletions
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 |