mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Replace distutils with sysconfig on Python 3.12+
This commit is contained in:
parent
56f8b38e1e
commit
4a014f953d
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
@ -203,6 +204,31 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
|
||||||
assert result.stdout.strip() == "2.0", str(result)
|
assert result.stdout.strip() == "2.0", str(result)
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info < (3, 12):
|
||||||
|
BUILD_ENV_ERROR_DEBUG_CODE = r"""
|
||||||
|
from distutils.sysconfig import get_python_lib
|
||||||
|
print(
|
||||||
|
f'imported `pkg` from `{pkg.__file__}`',
|
||||||
|
file=sys.stderr)
|
||||||
|
print('system sites:\n ' + '\n '.join(sorted({
|
||||||
|
get_python_lib(plat_specific=0),
|
||||||
|
get_python_lib(plat_specific=1),
|
||||||
|
})), file=sys.stderr)
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
BUILD_ENV_ERROR_DEBUG_CODE = r"""
|
||||||
|
from sysconfig import get_paths
|
||||||
|
paths = get_paths()
|
||||||
|
print(
|
||||||
|
f'imported `pkg` from `{pkg.__file__}`',
|
||||||
|
file=sys.stderr)
|
||||||
|
print('system sites:\n ' + '\n '.join(sorted({
|
||||||
|
paths['platlib'],
|
||||||
|
paths['purelib'],
|
||||||
|
})), file=sys.stderr)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("enable_user_site")
|
@pytest.mark.usefixtures("enable_user_site")
|
||||||
def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
||||||
# Create dummy `pkg` wheel.
|
# Create dummy `pkg` wheel.
|
||||||
|
@ -231,8 +257,7 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
||||||
run_with_build_env(
|
run_with_build_env(
|
||||||
script,
|
script,
|
||||||
"",
|
"",
|
||||||
r"""
|
f"""
|
||||||
from distutils.sysconfig import get_python_lib
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -240,17 +265,9 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print(
|
{BUILD_ENV_ERROR_DEBUG_CODE}
|
||||||
f'imported `pkg` from `{pkg.__file__}`',
|
print('sys.path:\\n ' + '\\n '.join(sys.path), file=sys.stderr)
|
||||||
file=sys.stderr)
|
|
||||||
print('system sites:\n ' + '\n '.join(sorted({
|
|
||||||
get_python_lib(plat_specific=0),
|
|
||||||
get_python_lib(plat_specific=1),
|
|
||||||
})), file=sys.stderr)
|
|
||||||
print('sys.path:\n ' + '\n '.join(sys.path), file=sys.stderr)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
"""
|
|
||||||
f"""
|
|
||||||
# second check: direct check of exclusion of system site packages
|
# second check: direct check of exclusion of system site packages
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue