Commit e20e85ed authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #2255 from pypa/bugfix/2232-adopt-distutils-default

Re-enable distutils patch by default.
parents 8d508965 3d404fd3
......@@ -37,7 +37,7 @@ def enabled():
"""
Allow selection of distutils by environment variable.
"""
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
return which == 'local'
......@@ -66,12 +66,14 @@ def do_override():
class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None):
if path is not None or fullname != "distutils":
return None
if path is not None:
return
return self.get_distutils_spec()
method_name = 'spec_for_{fullname}'.format(**locals())
method = getattr(self, method_name, lambda: None)
return method()
def get_distutils_spec(self):
def spec_for_distutils(self):
import importlib.util
class DistutilsLoader(importlib.util.abc.Loader):
......@@ -84,6 +86,14 @@ class DistutilsMetaFinder:
return importlib.util.spec_from_loader('distutils', DistutilsLoader())
def spec_for_pip(self):
"""
Ensure stdlib distutils when running under pip.
See pypa/pip#8761 for rationale.
"""
clear_distutils()
self.spec_for_distutils = lambda: None
DISTUTILS_FINDER = DistutilsMetaFinder()
......
Once again, Setuptools overrides the stdlib distutils on import. For environments or invocations where this behavior is undesirable, users are provided with a temporary escape hatch. If the environment variable ``SETUPTOOLS_USE_DISTUTILS`` is set to ``stdlib``, Setuptools will fall back to the legacy behavior. Use of this escape hatch is discouraged, but it is provided to ease the transition while proper fixes for edge cases can be addressed.
......@@ -99,7 +99,8 @@ class install_with_pth(install):
_pth_name = 'distutils-precedence'
_pth_contents = textwrap.dedent("""
import os
enabled = os.environ.get('SETUPTOOLS_USE_DISTUTILS') == 'local'
var = 'SETUPTOOLS_USE_DISTUTILS'
enabled = os.environ.get(var, 'local') == 'local'
enabled and __import__('_distutils_hack').add_shim()
""").lstrip().replace('\n', '; ')
......
......@@ -48,15 +48,15 @@ def test_distutils_stdlib(venv):
"""
Ensure stdlib distutils is used when appropriate.
"""
assert venv.name not in find_distutils(venv, env=dict()).split(os.sep)
env = dict(SETUPTOOLS_USE_DISTUTILS='stdlib')
assert venv.name not in find_distutils(venv, env=env).split(os.sep)
def test_distutils_local_with_setuptools(venv):
"""
Ensure local distutils is used when appropriate.
"""
env = dict(SETUPTOOLS_USE_DISTUTILS='local')
loc = find_distutils(venv, imports='setuptools, distutils', env=env)
loc = find_distutils(venv, imports='setuptools, distutils', env=dict())
assert venv.name in loc.split(os.sep)
......@@ -66,5 +66,4 @@ def test_distutils_local(venv):
Even without importing, the setuptools-local copy of distutils is
preferred.
"""
env = dict(SETUPTOOLS_USE_DISTUTILS='local')
assert venv.name in find_distutils(venv, env=env).split(os.sep)
assert venv.name in find_distutils(venv, env=dict()).split(os.sep)
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