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(): ...@@ -37,7 +37,7 @@ def enabled():
""" """
Allow selection of distutils by environment variable. 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' return which == 'local'
...@@ -66,12 +66,14 @@ def do_override(): ...@@ -66,12 +66,14 @@ def do_override():
class DistutilsMetaFinder: class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None): def find_spec(self, fullname, path, target=None):
if path is not None or fullname != "distutils": if path is not None:
return 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 import importlib.util
class DistutilsLoader(importlib.util.abc.Loader): class DistutilsLoader(importlib.util.abc.Loader):
...@@ -84,6 +86,14 @@ class DistutilsMetaFinder: ...@@ -84,6 +86,14 @@ class DistutilsMetaFinder:
return importlib.util.spec_from_loader('distutils', DistutilsLoader()) 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() 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): ...@@ -99,7 +99,8 @@ class install_with_pth(install):
_pth_name = 'distutils-precedence' _pth_name = 'distutils-precedence'
_pth_contents = textwrap.dedent(""" _pth_contents = textwrap.dedent("""
import os 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() enabled and __import__('_distutils_hack').add_shim()
""").lstrip().replace('\n', '; ') """).lstrip().replace('\n', '; ')
......
...@@ -48,15 +48,15 @@ def test_distutils_stdlib(venv): ...@@ -48,15 +48,15 @@ def test_distutils_stdlib(venv):
""" """
Ensure stdlib distutils is used when appropriate. 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): def test_distutils_local_with_setuptools(venv):
""" """
Ensure local distutils is used when appropriate. Ensure local distutils is used when appropriate.
""" """
env = dict(SETUPTOOLS_USE_DISTUTILS='local') loc = find_distutils(venv, imports='setuptools, distutils', env=dict())
loc = find_distutils(venv, imports='setuptools, distutils', env=env)
assert venv.name in loc.split(os.sep) assert venv.name in loc.split(os.sep)
...@@ -66,5 +66,4 @@ def test_distutils_local(venv): ...@@ -66,5 +66,4 @@ def test_distutils_local(venv):
Even without importing, the setuptools-local copy of distutils is Even without importing, the setuptools-local copy of distutils is
preferred. preferred.
""" """
env = dict(SETUPTOOLS_USE_DISTUTILS='local') assert venv.name in find_distutils(venv, env=dict()).split(os.sep)
assert venv.name in find_distutils(venv, env=env).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