Commit 28e1b5ab authored by Paul Ganssle's avatar Paul Ganssle

Use .pth file to import distutils from setuptools

parent 37d81f4c
......@@ -13,4 +13,5 @@ include launcher.c
include msvc-build-launcher.cmd
include pytest.ini
include tox.ini
include distutils_precedence.pth
exclude pyproject.toml # Temporary workaround for #1644.
import sys
here = os.path.dirname(__file__)
NEW_DISTUTILS_LOCATION = os.path.join(here, 'distutils-shim-package')
sys.path.insert(0, NEW_DISTUTILS_LOCATION)
import setuptools.distutils_patch
from distutils import *
import os; (os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib') == 'local' and __import__('_distutils_importer'))
......@@ -7,6 +7,7 @@ import os
import sys
import setuptools
from setuptools.command.install import install
here = os.path.dirname(__file__)
......@@ -49,6 +50,7 @@ def _gen_console_scripts():
package_data = dict(
setuptools=['script (dev).tmpl', 'script.tmpl', 'site-patch.py'],
_distutils_importer=['distutils-shim-package/distutils/__init__.py'],
)
force_windows_specific_files = (
......@@ -81,8 +83,38 @@ def pypi_link(pkg_filename):
return '/'.join(parts)
class install_with_pth(install):
"""
Custom install command to install a .pth file for distutils patching.
This is necessary because there's no standard way to install a `.pth` file
alongside your package (and there probably shouldn't be one), but we need
to do this in order to give precedence higher precedence to our version of
`distutils` than the standard library.
"""
def initialize_options(self):
install.initialize_options(self)
name = 'distutils_precedence'
with open(os.path.join(here, name + '.pth'), 'rt') as f:
contents = f.read()
self.extra_path = (name, contents)
def finalize_options(self):
install.finalize_options(self)
install_suffix = os.path.relpath(self.install_lib,
self.install_libbase)
if install_suffix == self.extra_path[1]:
self.install_lib = self.install_libbase
setup_params = dict(
src_root=None,
cmdclass={'install': install_with_pth},
package_data=package_data,
entry_points={
"distutils.commands": [
......
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