mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Disable the distutils setuptools shim during interpreter query (#10819)
Addresses https://github.com/astral-sh/uv/issues/4204#issuecomment-2604983670 Original context in https://github.com/astral-sh/uv/issues/2302
This commit is contained in:
parent
96e3ed5603
commit
399086d28f
2 changed files with 26 additions and 26 deletions
21
.github/workflows/ci.yml
vendored
21
.github/workflows/ci.yml
vendored
|
@ -691,17 +691,9 @@ jobs:
|
||||||
- name: "Prepare binary"
|
- name: "Prepare binary"
|
||||||
run: chmod +x ./uv
|
run: chmod +x ./uv
|
||||||
|
|
||||||
- name: "Create a virtual environment"
|
- name: "Check missing distutils"
|
||||||
run: |
|
run: |
|
||||||
./uv venv -p 3.9 --python-preference only-system
|
./uv venv -p 3.9 --python-preference only-system -v 2>&1 | tee log.txt || true
|
||||||
|
|
||||||
- name: "Check version"
|
|
||||||
run: |
|
|
||||||
.venv/bin/python --version
|
|
||||||
|
|
||||||
- name: "Check install missing distutils"
|
|
||||||
run: |
|
|
||||||
./uv pip install -v anyio 2>&1 | tee log.txt || true
|
|
||||||
# We should report that distutils is missing
|
# We should report that distutils is missing
|
||||||
grep 'Python installation is missing `distutils`' log.txt
|
grep 'Python installation is missing `distutils`' log.txt
|
||||||
|
|
||||||
|
@ -709,10 +701,17 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install python3.9-distutils
|
sudo apt-get install python3.9-distutils
|
||||||
|
|
||||||
|
- name: "Create a virtualenv"
|
||||||
|
run: |
|
||||||
|
./uv venv -p 3.9 --python-preference only-system -v
|
||||||
|
|
||||||
|
- name: "Check version"
|
||||||
|
run: |
|
||||||
|
.venv/bin/python --version
|
||||||
|
|
||||||
- name: "Check install"
|
- name: "Check install"
|
||||||
run: |
|
run: |
|
||||||
./uv pip install -v anyio
|
./uv pip install -v anyio
|
||||||
# Now the install should succeed
|
|
||||||
|
|
||||||
integration-test-free-threaded-linux:
|
integration-test-free-threaded-linux:
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
|
|
|
@ -176,6 +176,9 @@ def get_virtualenv():
|
||||||
"data": expand_path(sysconfig_paths["data"]),
|
"data": expand_path(sysconfig_paths["data"]),
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
|
# Use distutils primarily because that's what pip does.
|
||||||
|
# https://github.com/pypa/pip/blob/ae5fff36b0aad6e5e0037884927eaa29163c0611/src/pip/_internal/locations/__init__.py#L249
|
||||||
|
|
||||||
# Disable the use of the setuptools shim, if it's injected. Per pip:
|
# 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
|
# > If pip's going to use distutils, it should not be using the copy that setuptools
|
||||||
|
@ -189,8 +192,6 @@ def get_virtualenv():
|
||||||
except (ImportError, AttributeError):
|
except (ImportError, AttributeError):
|
||||||
pass
|
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
|
import warnings
|
||||||
|
|
||||||
with warnings.catch_warnings(): # disable warning for PEP-632
|
with warnings.catch_warnings(): # disable warning for PEP-632
|
||||||
|
@ -337,19 +338,6 @@ def get_scheme(use_sysconfig_scheme: bool):
|
||||||
Based on (with default arguments):
|
Based on (with default arguments):
|
||||||
https://github.com/pypa/pip/blob/ae5fff36b0aad6e5e0037884927eaa29163c0611/src/pip/_internal/locations/_distutils.py#L115
|
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
|
import warnings
|
||||||
|
|
||||||
with warnings.catch_warnings(): # disable warning for PEP-632
|
with warnings.catch_warnings(): # disable warning for PEP-632
|
||||||
|
@ -575,6 +563,19 @@ def main() -> None:
|
||||||
# If we're not using sysconfig, make sure distutils is available.
|
# If we're not using sysconfig, make sure distutils is available.
|
||||||
if not use_sysconfig_scheme:
|
if not use_sysconfig_scheme:
|
||||||
try:
|
try:
|
||||||
|
# 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 distutils.dist
|
import distutils.dist
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# We require distutils, but it's not installed; this is fairly
|
# We require distutils, but it's not installed; this is fairly
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue