diff options
| author | Christian Heimes <christian@python.org> | 2022-01-07 00:17:15 +0100 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2022-01-08 11:55:35 -0500 |
| commit | 804b106a8c97efa2944b92918f120c636ecb6818 (patch) | |
| tree | 6a1aceb4d433f51046f6d94e559017416940c918 /_distutils_hack | |
| parent | f39c0631e5269c33b3544004439f8480a41fcd02 (diff) | |
| download | python-setuptools-git-804b106a8c97efa2944b92918f120c636ecb6818.tar.gz | |
Use internal warnings API and _TrivialRe hack to install filter
Diffstat (limited to '_distutils_hack')
| -rw-r--r-- | _distutils_hack/__init__.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index 47ea70d4..d324763d 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -1,14 +1,29 @@ # don't import any costly modules import sys import os +import warnings is_pypy = '__pypy__' in sys.builtin_module_names -import warnings -warnings.filterwarnings('ignore', - r'.+ distutils\b.+ deprecated', - DeprecationWarning) + +class _TrivialRe: + def __init__(self, *patterns): + self._patterns = patterns + + def match(self, string): + return all(pat in string for pat in self._patterns) + + +# warnings.filterwarnings() imports the re module +warnings._add_filter( + 'ignore', + _TrivialRe("distutils", "deprecated"), + DeprecationWarning, + None, + 0, + append=False +) def warn_distutils_present(): @@ -18,7 +33,6 @@ def warn_distutils_present(): # PyPy for 3.6 unconditionally imports distutils, so bypass the warning # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250 return - import warnings warnings.warn( "Distutils was imported before Setuptools, but importing Setuptools " "also replaces the `distutils` module in `sys.modules`. This may lead " @@ -31,7 +45,6 @@ def warn_distutils_present(): def clear_distutils(): if 'distutils' not in sys.modules: return - import warnings warnings.warn("Setuptools is replacing distutils.") mods = [ name for name in sys.modules |
