mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Avoid using setuptools shim of distutils (#2305)
## Summary It turns out that setuptools includes a shim to patch distutils. I'll admit that I don't fully understand why or how it's different, but this is the trick `pip` uses to ensure that it gets the "original" distutils. We actually use distutils in two places: once for the system Python scheme, and once for virtual environments. In virtualenv, they _do_ use the patched distutils, so this could deviate in ways I don't understand. Closes #2302.
This commit is contained in:
parent
10c4effbd3
commit
ff62fe2c0b
1 changed files with 26 additions and 0 deletions
|
@ -169,6 +169,19 @@ def get_virtualenv():
|
|||
"data": expand_path(sysconfig_paths["data"]),
|
||||
}
|
||||
else:
|
||||
# Disable the use of the setuptools shim, if it's injected. Per pip:
|
||||
#
|
||||
# > If pip's going to use distutils, it should not be using the copy that setuptools
|
||||
# > might have injected into the environment. This is done by removing the injected
|
||||
# > shim, if it's injected.
|
||||
#
|
||||
# > See https://github.com/pypa/pip/issues/8761 for the original discussion and
|
||||
# > rationale for why this is done within pip.
|
||||
try:
|
||||
__import__("_distutils_hack").remove_shim()
|
||||
except (ImportError, AttributeError):
|
||||
pass
|
||||
|
||||
# Use distutils primarily because that's what pip does.
|
||||
# https://github.com/pypa/pip/blob/ae5fff36b0aad6e5e0037884927eaa29163c0611/src/pip/_internal/locations/__init__.py#L249
|
||||
import warnings
|
||||
|
@ -317,6 +330,19 @@ def get_scheme():
|
|||
Based on (with default arguments):
|
||||
https://github.com/pypa/pip/blob/ae5fff36b0aad6e5e0037884927eaa29163c0611/src/pip/_internal/locations/_distutils.py#L115
|
||||
"""
|
||||
# Disable the use of the setuptools shim, if it's injected. Per pip:
|
||||
#
|
||||
# > If pip's going to use distutils, it should not be using the copy that setuptools
|
||||
# > might have injected into the environment. This is done by removing the injected
|
||||
# > shim, if it's injected.
|
||||
#
|
||||
# > See https://github.com/pypa/pip/issues/8761 for the original discussion and
|
||||
# > rationale for why this is done within pip.
|
||||
try:
|
||||
__import__("_distutils_hack").remove_shim()
|
||||
except (ImportError, AttributeError):
|
||||
pass
|
||||
|
||||
import warnings
|
||||
|
||||
with warnings.catch_warnings(): # disable warning for PEP-632
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue