Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using setuptools shim of distutils #2305

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/uv-interpreter/src/get_interpreter_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ def expand_path(path: str) -> str:
"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
Expand Down Expand Up @@ -317,6 +330,19 @@ def get_distutils_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
Expand Down