|
12 | 12 | import re
|
13 | 13 | import sys
|
14 | 14 | import sysconfig
|
| 15 | +import warnings |
15 | 16 | from collections import OrderedDict, namedtuple
|
16 |
| -from distutils import dist |
17 |
| -from distutils.command.install import SCHEME_KEYS |
18 | 17 | from string import digits
|
19 | 18 |
|
20 | 19 | VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"])
|
@@ -118,10 +117,28 @@ def _fast_get_system_executable(self):
|
118 | 117 | # note we must choose the original and not the pure executable as shim scripts might throw us off
|
119 | 118 | return self.original_executable
|
120 | 119 |
|
| 120 | + def install_path(self, key): |
| 121 | + result = self.distutils_install.get(key) |
| 122 | + if result is None: # use sysconfig if distutils is unavailable |
| 123 | + # set prefixes to empty => result is relative from cwd |
| 124 | + prefixes = self.prefix, self.exec_prefix, self.base_prefix, self.base_exec_prefix |
| 125 | + config_var = {k: "" if v in prefixes else v for k, v in self.sysconfig_vars} |
| 126 | + result = self.sysconfig_path(key, config_var=config_var).lstrip(os.sep) |
| 127 | + return result |
| 128 | + |
121 | 129 | @staticmethod
|
122 | 130 | def _distutils_install():
|
123 |
| - # follow https://github.com/pypa/pip/blob/main/src/pip/_internal/locations.py#L95 |
| 131 | + # use distutils primarily because that's what pip does |
| 132 | + # https://github.com/pypa/pip/blob/main/src/pip/_internal/locations.py#L95 |
124 | 133 | # note here we don't import Distribution directly to allow setuptools to patch it
|
| 134 | + with warnings.catch_warnings(): # disable warning for PEP-632 |
| 135 | + warnings.simplefilter("ignore") |
| 136 | + try: |
| 137 | + from distutils import dist |
| 138 | + from distutils.command.install import SCHEME_KEYS |
| 139 | + except ImportError: # if removed or not installed ignore |
| 140 | + return {} |
| 141 | + |
125 | 142 | d = dist.Distribution({"script_args": "--no-user-cfg"}) # conf files not parsed so they do not hijack paths
|
126 | 143 | if hasattr(sys, "_framework"):
|
127 | 144 | sys._framework = None # disable macOS static paths for framework
|
@@ -177,7 +194,7 @@ def system_include(self):
|
177 | 194 | )
|
178 | 195 | if not os.path.exists(path): # some broken packaging don't respect the sysconfig, fallback to distutils path
|
179 | 196 | # the pattern include the distribution name too at the end, remove that via the parent call
|
180 |
| - fallback = os.path.join(self.prefix, os.path.dirname(self.distutils_install["headers"])) |
| 197 | + fallback = os.path.join(self.prefix, os.path.dirname(self.install_path("headers"))) |
181 | 198 | if os.path.exists(fallback):
|
182 | 199 | path = fallback
|
183 | 200 | return path
|
|
0 commit comments