Skip to content

Commit a494597

Browse files
authored
Merge pull request #2256 from pypa/bugfix/2230-warn-distutils-present
Warn the user when distutils is present
2 parents 6ecd778 + 36df1d7 commit a494597

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

changelog.d/2230.change.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now warn the user when setuptools is imported after distutils modules have been loaded (exempting PyPy for 3.6), directing the users of packages to import setuptools first.

setuptools/distutils_patch.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,26 @@
1212
import warnings
1313

1414

15+
is_pypy = '__pypy__' in sys.builtin_module_names
16+
17+
18+
def warn_distutils_present():
19+
if 'distutils' not in sys.modules:
20+
return
21+
if is_pypy and sys.version_info < (3, 7):
22+
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
23+
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
24+
return
25+
warnings.warn(
26+
"Distutils was imported before Setuptools. This usage is discouraged "
27+
"and may exhibit undesirable behaviors or errors. Please use "
28+
"Setuptools' objects directly or at least import Setuptools first.")
29+
30+
1531
def clear_distutils():
1632
if 'distutils' not in sys.modules:
1733
return
18-
warnings.warn("Setuptools is replacing distutils")
34+
warnings.warn("Setuptools is replacing distutils.")
1935
mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
2036
for name in mods:
2137
del sys.modules[name]
@@ -40,5 +56,6 @@ def ensure_local_distutils():
4056
assert '_distutils' in core.__file__, core.__file__
4157

4258

59+
warn_distutils_present()
4360
if enabled():
4461
ensure_local_distutils()

0 commit comments

Comments
 (0)