diff options
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 |