diff options
| author | Paul Ganssle <paul@ganssle.io> | 2020-07-13 11:15:26 -0400 |
|---|---|---|
| committer | Paul Ganssle <paul@ganssle.io> | 2020-07-13 15:42:18 -0400 |
| commit | 28e1b5ab2f4d573a91705cdbb025e57023d264b1 (patch) | |
| tree | eae976e74e1fd91d4fc58194507c83b1a23aa169 | |
| parent | 37d81f4ce8f08c4baf44b6ff0f3f1bd3f6b2a127 (diff) | |
| download | external_python_setuptools-28e1b5ab2f4d573a91705cdbb025e57023d264b1.tar.gz external_python_setuptools-28e1b5ab2f4d573a91705cdbb025e57023d264b1.tar.bz2 external_python_setuptools-28e1b5ab2f4d573a91705cdbb025e57023d264b1.zip | |
Use .pth file to import distutils from setuptools
| -rw-r--r-- | MANIFEST.in | 1 | ||||
| -rw-r--r-- | _distutils_importer/__init__.py | 6 | ||||
| -rw-r--r-- | _distutils_importer/distutils-shim-package/distutils/__init__.py | 3 | ||||
| -rw-r--r-- | distutils_precedence.pth | 1 | ||||
| -rwxr-xr-x | setup.py | 32 |
5 files changed, 43 insertions, 0 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index 128ae280..be83a7f3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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. diff --git a/_distutils_importer/__init__.py b/_distutils_importer/__init__.py new file mode 100644 index 00000000..54a825fe --- /dev/null +++ b/_distutils_importer/__init__.py @@ -0,0 +1,6 @@ +import sys + +here = os.path.dirname(__file__) +NEW_DISTUTILS_LOCATION = os.path.join(here, 'distutils-shim-package') + +sys.path.insert(0, NEW_DISTUTILS_LOCATION) diff --git a/_distutils_importer/distutils-shim-package/distutils/__init__.py b/_distutils_importer/distutils-shim-package/distutils/__init__.py new file mode 100644 index 00000000..de098c72 --- /dev/null +++ b/_distutils_importer/distutils-shim-package/distutils/__init__.py @@ -0,0 +1,3 @@ +import setuptools.distutils_patch + +from distutils import * diff --git a/distutils_precedence.pth b/distutils_precedence.pth new file mode 100644 index 00000000..2d9b996a --- /dev/null +++ b/distutils_precedence.pth @@ -0,0 +1 @@ +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": [ |
