Commit e3714224 authored by Jason R. Coombs's avatar Jason R. Coombs

Consolidate distutils importing hacks into _distutils_importer package....

Consolidate distutils importing hacks into _distutils_importer package. Generate distutils-precedence.pth inline.
parent 85a0a902
...@@ -13,5 +13,4 @@ include launcher.c ...@@ -13,5 +13,4 @@ include launcher.c
include msvc-build-launcher.cmd include msvc-build-launcher.cmd
include pytest.ini include pytest.ini
include tox.ini include tox.ini
include distutils_precedence.pth
exclude pyproject.toml # Temporary workaround for #1644. exclude pyproject.toml # Temporary workaround for #1644.
"""
Ensure that the local copy of distutils is preferred over stdlib.
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
for more motivation.
"""
import sys import sys
import os
def enabled():
"""
Allow selection of distutils by environment variable.
"""
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
return which == 'local'
class DistutilsMetaFinder: class DistutilsMetaFinder:
...@@ -34,6 +50,3 @@ def remove_shim(): ...@@ -34,6 +50,3 @@ def remove_shim():
sys.path.remove(DISTUTILS_FINDER) sys.path.remove(DISTUTILS_FINDER)
except ValueError: except ValueError:
pass pass
add_shim()
from . import enabled, add_shim
if enabled():
add_shim()
"""
Ensure that the local copy of distutils is preferred over stdlib.
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
for more motivation.
"""
import sys import sys
import re import re
import os
import importlib import importlib
import warnings import warnings
from . import enabled
is_pypy = '__pypy__' in sys.builtin_module_names is_pypy = '__pypy__' in sys.builtin_module_names
...@@ -37,14 +31,6 @@ def clear_distutils(): ...@@ -37,14 +31,6 @@ def clear_distutils():
del sys.modules[name] del sys.modules[name]
def enabled():
"""
Allow selection of distutils by environment variable.
"""
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
return which == 'local'
def ensure_local_distutils(): def ensure_local_distutils():
clear_distutils() clear_distutils()
distutils = importlib.import_module('setuptools._distutils') distutils = importlib.import_module('setuptools._distutils')
......
...@@ -15,7 +15,7 @@ collect_ignore = [ ...@@ -15,7 +15,7 @@ collect_ignore = [
'tests/manual_test.py', 'tests/manual_test.py',
'setuptools/tests/mod_with_constant.py', 'setuptools/tests/mod_with_constant.py',
'setuptools/_distutils', 'setuptools/_distutils',
'setuptools/distutils_patch.py', '_distutils_importer',
] ]
......
import os; (os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib') == 'local' and __import__('_distutils_importer'))
...@@ -94,12 +94,8 @@ class install_with_pth(install): ...@@ -94,12 +94,8 @@ class install_with_pth(install):
def initialize_options(self): def initialize_options(self):
install.initialize_options(self) install.initialize_options(self)
self.extra_path = (
name = 'distutils_precedence' 'distutils-precedence', 'import _distutils_importer.install')
with open(os.path.join(here, name + '.pth'), 'rt') as f:
contents = f.read()
self.extra_path = (name, contents)
def finalize_options(self): def finalize_options(self):
install.finalize_options(self) install.finalize_options(self)
......
...@@ -5,8 +5,7 @@ import functools ...@@ -5,8 +5,7 @@ import functools
import os import os
import re import re
# Disabled for now due to: #2228, #2230 import _distutils_importer.override # noqa: F401
import setuptools.distutils_patch # noqa: F401
import distutils.core import distutils.core
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsOptionError
......
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