diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-09-04 10:22:54 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-09-04 10:22:54 -0400 |
commit | fc4d9828768ceebd2f9337481450c88376c013e9 (patch) | |
tree | 6dff622c50739ca19fdfbecf1008a42589d37b57 /setup.py | |
parent | 7bb73a477de24069002516eb6eb1d755bed9d65b (diff) | |
parent | 03d36b9edb53e266a0b4b836e1e3178f989a0781 (diff) | |
download | python-setuptools-git-feature/implicit-bootstrap.tar.gz |
Merge branch 'master' into feature/implicit-bootstrapfeature/implicit-bootstrap
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -5,9 +5,11 @@ Distutils setup file, used to install or test 'setuptools' import os import sys +import textwrap -import setuptools import bootstrap +import setuptools +from setuptools.command.install import install here = os.path.dirname(__file__) @@ -71,8 +73,48 @@ 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 hack is necessary because there's no standard way to install behavior + on startup (and it's debatable if there should be one). This hack (ab)uses + the `extra_path` behavior in Setuptools to install a `.pth` file with + implicit behavior on startup to give higher precedence to the local version + of `distutils` over the version from the standard library. + + Please do not replicate this behavior. + """ + + _pth_name = 'distutils-precedence' + _pth_contents = textwrap.dedent(""" + import os + var = 'SETUPTOOLS_USE_DISTUTILS' + enabled = os.environ.get(var, 'stdlib') == 'local' + enabled and __import__('_distutils_hack').add_shim() + """).lstrip().replace('\n', '; ') + + def initialize_options(self): + install.initialize_options(self) + self.extra_path = self._pth_name, self._pth_contents + + def finalize_options(self): + install.finalize_options(self) + self._restore_install_lib() + + def _restore_install_lib(self): + """ + Undo secondary effect of `extra_path` adding to `install_lib` + """ + suffix = os.path.relpath(self.install_lib, self.install_libbase) + + if suffix.strip() == self._pth_contents.strip(): + 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": [ @@ -81,7 +123,6 @@ setup_params = dict( ], "setuptools.finalize_distribution_options": [ "parent_finalize = setuptools.dist:_Distribution.finalize_options", - "features = setuptools.dist:Distribution._finalize_feature_opts", "keywords = setuptools.dist:Distribution._finalize_setup_keywords", "2to3_doctests = " "setuptools.dist:Distribution._finalize_2to3_doctests", |