Commit 5854b0eb authored by Junhan Huang's avatar Junhan Huang Committed by Paul Ganssle

Add custom deprecation warning classes

`DeprecationWarning` is not visible by default in the latest versions of
CPython, so this switches the deprecation warnings in setuptools and
pkg_resources over to custom classes derived from `Warning` instead.

Fixes issue github issue #159
Co-authored-by: default avatarJunhan Huang <robin.j.huang@gmail.com>
Co-authored-by: default avatarMarton Pono <marci93@gmail.com>
parent 29f9cb08
...@@ -238,6 +238,9 @@ __all__ = [ ...@@ -238,6 +238,9 @@ __all__ = [
'register_finder', 'register_namespace_handler', 'register_loader_type', 'register_finder', 'register_namespace_handler', 'register_loader_type',
'fixup_namespace_packages', 'get_importer', 'fixup_namespace_packages', 'get_importer',
# Warnings
'PkgResourcesDeprecationWarning',
# Deprecated/backward compatibility only # Deprecated/backward compatibility only
'run_main', 'AvailableDistributions', 'run_main', 'AvailableDistributions',
] ]
...@@ -2335,7 +2338,7 @@ class EntryPoint: ...@@ -2335,7 +2338,7 @@ class EntryPoint:
warnings.warn( warnings.warn(
"Parameters to load are deprecated. Call .resolve and " "Parameters to load are deprecated. Call .resolve and "
".require separately.", ".require separately.",
DeprecationWarning, PkgResourcesDeprecationWarning,
stacklevel=2, stacklevel=2,
) )
if require: if require:
...@@ -3158,3 +3161,11 @@ def _initialize_master_working_set(): ...@@ -3158,3 +3161,11 @@ def _initialize_master_working_set():
# match order # match order
list(map(working_set.add_entry, sys.path)) list(map(working_set.add_entry, sys.path))
globals().update(locals()) globals().update(locals())
class PkgResourcesDeprecationWarning(Warning):
"""
Base class for warning about deprecations in ``pkg_resources``
This class is not derived from ``DeprecationWarning``, and as such is
visible by default.
"""
...@@ -8,6 +8,8 @@ import distutils.filelist ...@@ -8,6 +8,8 @@ import distutils.filelist
from distutils.util import convert_path from distutils.util import convert_path
from fnmatch import fnmatchcase from fnmatch import fnmatchcase
from ._deprecation_warning import SetuptoolsDeprecationWarning
from setuptools.extern.six import PY3 from setuptools.extern.six import PY3
from setuptools.extern.six.moves import filter, map from setuptools.extern.six.moves import filter, map
...@@ -22,6 +24,7 @@ __metaclass__ = type ...@@ -22,6 +24,7 @@ __metaclass__ = type
__all__ = [ __all__ = [
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require', 'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
'SetuptoolsDeprecationWarning',
'find_packages' 'find_packages'
] ]
...@@ -188,4 +191,5 @@ def findall(dir=os.curdir): ...@@ -188,4 +191,5 @@ def findall(dir=os.curdir):
return list(files) return list(files)
# Apply monkey patches
monkey.patch_all() monkey.patch_all()
class SetuptoolsDeprecationWarning(Warning):
"""
Base class for warning deprecations in ``setuptools``
This class is not derived from ``DeprecationWarning``, and as such is
visible by default.
"""
...@@ -40,8 +40,11 @@ import subprocess ...@@ -40,8 +40,11 @@ import subprocess
import shlex import shlex
import io import io
from sysconfig import get_config_vars, get_path from sysconfig import get_config_vars, get_path
from setuptools import SetuptoolsDeprecationWarning
from setuptools.extern import six from setuptools.extern import six
from setuptools.extern.six.moves import configparser, map from setuptools.extern.six.moves import configparser, map
...@@ -2077,7 +2080,7 @@ class ScriptWriter: ...@@ -2077,7 +2080,7 @@ class ScriptWriter:
@classmethod @classmethod
def get_script_args(cls, dist, executable=None, wininst=False): def get_script_args(cls, dist, executable=None, wininst=False):
# for backward compatibility # for backward compatibility
warnings.warn("Use get_args", DeprecationWarning) warnings.warn("Use get_args", EasyInstallDeprecationWarning)
writer = (WindowsScriptWriter if wininst else ScriptWriter).best() writer = (WindowsScriptWriter if wininst else ScriptWriter).best()
header = cls.get_script_header("", executable, wininst) header = cls.get_script_header("", executable, wininst)
return writer.get_args(dist, header) return writer.get_args(dist, header)
...@@ -2085,7 +2088,7 @@ class ScriptWriter: ...@@ -2085,7 +2088,7 @@ class ScriptWriter:
@classmethod @classmethod
def get_script_header(cls, script_text, executable=None, wininst=False): def get_script_header(cls, script_text, executable=None, wininst=False):
# for backward compatibility # for backward compatibility
warnings.warn("Use get_header", DeprecationWarning, stacklevel=2) warnings.warn("Use get_header", EasyInstallDeprecationWarning, stacklevel=2)
if wininst: if wininst:
executable = "python.exe" executable = "python.exe"
return cls.get_header(script_text, executable) return cls.get_header(script_text, executable)
...@@ -2120,7 +2123,7 @@ class ScriptWriter: ...@@ -2120,7 +2123,7 @@ class ScriptWriter:
@classmethod @classmethod
def get_writer(cls, force_windows): def get_writer(cls, force_windows):
# for backward compatibility # for backward compatibility
warnings.warn("Use best", DeprecationWarning) warnings.warn("Use best", EasyInstallDeprecationWarning)
return WindowsScriptWriter.best() if force_windows else cls.best() return WindowsScriptWriter.best() if force_windows else cls.best()
@classmethod @classmethod
...@@ -2152,7 +2155,7 @@ class WindowsScriptWriter(ScriptWriter): ...@@ -2152,7 +2155,7 @@ class WindowsScriptWriter(ScriptWriter):
@classmethod @classmethod
def get_writer(cls): def get_writer(cls):
# for backward compatibility # for backward compatibility
warnings.warn("Use best", DeprecationWarning) warnings.warn("Use best", EasyInstallDeprecationWarning)
return cls.best() return cls.best()
@classmethod @classmethod
...@@ -2333,3 +2336,7 @@ def _patch_usage(): ...@@ -2333,3 +2336,7 @@ def _patch_usage():
yield yield
finally: finally:
distutils.core.gen_usage = saved distutils.core.gen_usage = saved
class EasyInstallDeprecationWarning(SetuptoolsDeprecationWarning):
"""Class for warning about deprecations in EasyInstall in SetupTools. Not ignored by default, unlike DeprecationWarning."""
...@@ -31,7 +31,7 @@ import setuptools.unicode_utils as unicode_utils ...@@ -31,7 +31,7 @@ import setuptools.unicode_utils as unicode_utils
from setuptools.glob import glob from setuptools.glob import glob
from setuptools.extern import packaging from setuptools.extern import packaging
from setuptools import SetuptoolsDeprecationWarning
def translate_pattern(glob): def translate_pattern(glob):
""" """
...@@ -696,7 +696,7 @@ def get_pkg_info_revision(): ...@@ -696,7 +696,7 @@ def get_pkg_info_revision():
Get a -r### off of PKG-INFO Version in case this is an sdist of Get a -r### off of PKG-INFO Version in case this is an sdist of
a subversion revision. a subversion revision.
""" """
warnings.warn("get_pkg_info_revision is deprecated.", DeprecationWarning) warnings.warn("get_pkg_info_revision is deprecated.", EggInfoDeprecationWarning)
if os.path.exists('PKG-INFO'): if os.path.exists('PKG-INFO'):
with io.open('PKG-INFO') as f: with io.open('PKG-INFO') as f:
for line in f: for line in f:
...@@ -704,3 +704,7 @@ def get_pkg_info_revision(): ...@@ -704,3 +704,7 @@ def get_pkg_info_revision():
if match: if match:
return int(match.group(1)) return int(match.group(1))
return 0 return 0
class EggInfoDeprecationWarning(SetuptoolsDeprecationWarning):
"""Class for warning about deprecations in eggInfo in setupTools. Not ignored by default, unlike DeprecationWarning."""
...@@ -21,6 +21,8 @@ from setuptools.extern import six ...@@ -21,6 +21,8 @@ from setuptools.extern import six
from setuptools.extern import packaging from setuptools.extern import packaging
from setuptools.extern.six.moves import map, filter, filterfalse from setuptools.extern.six.moves import map, filter, filterfalse
from . import SetuptoolsDeprecationWarning
from setuptools.depends import Require from setuptools.depends import Require
from setuptools import windows_support from setuptools import windows_support
from setuptools.monkey import get_unpatched from setuptools.monkey import get_unpatched
...@@ -33,7 +35,7 @@ __import__('setuptools.extern.packaging.version') ...@@ -33,7 +35,7 @@ __import__('setuptools.extern.packaging.version')
def _get_unpatched(cls): def _get_unpatched(cls):
warnings.warn("Do not call this function", DeprecationWarning) warnings.warn("Do not call this function", DistDeprecationWarning)
return get_unpatched(cls) return get_unpatched(cls)
...@@ -980,7 +982,7 @@ class Feature: ...@@ -980,7 +982,7 @@ class Feature:
"Features are deprecated and will be removed in a future " "Features are deprecated and will be removed in a future "
"version. See https://github.com/pypa/setuptools/issues/65." "version. See https://github.com/pypa/setuptools/issues/65."
) )
warnings.warn(msg, DeprecationWarning, stacklevel=3) warnings.warn(msg, DistDeprecationWarning, stacklevel=3)
def __init__( def __init__(
self, description, standard=False, available=True, self, description, standard=False, available=True,
...@@ -1069,3 +1071,7 @@ class Feature: ...@@ -1069,3 +1071,7 @@ class Feature:
" doesn't contain any packages or modules under %s" " doesn't contain any packages or modules under %s"
% (self.description, item, item) % (self.description, item, item)
) )
class DistDeprecationWarning(SetuptoolsDeprecationWarning):
"""Class for warning about deprecations in dist in setuptools. Not ignored by default, unlike DeprecationWarning."""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment