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 /setup.py | |
| parent | 37d81f4ce8f08c4baf44b6ff0f3f1bd3f6b2a127 (diff) | |
| download | python-setuptools-git-28e1b5ab2f4d573a91705cdbb025e57023d264b1.tar.gz | |
Use .pth file to import distutils from setuptools
Diffstat (limited to 'setup.py')
| -rwxr-xr-x | setup.py | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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": [ |
