Skip to content

Commit

Permalink
Replace distutils with sysconfig on Python 3.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jul 4, 2023
1 parent 56f8b38 commit 4a014f9
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions tests/functional/test_build_env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
from textwrap import dedent
from typing import Optional

Expand Down Expand Up @@ -203,6 +204,31 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
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")
def test_build_env_isolation(script: PipTestEnvironment) -> None:
# Create dummy `pkg` wheel.
Expand Down Expand Up @@ -231,26 +257,17 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
run_with_build_env(
script,
"",
r"""
from distutils.sysconfig import get_python_lib
f"""
import sys
try:
import pkg
except ImportError:
pass
else:
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)
print('sys.path:\n ' + '\n '.join(sys.path), file=sys.stderr)
{BUILD_ENV_ERROR_DEBUG_CODE}
print('sys.path:\\n ' + '\\n '.join(sys.path), file=sys.stderr)
sys.exit(1)
"""
f"""
# second check: direct check of exclusion of system site packages
import os
Expand Down

0 comments on commit 4a014f9

Please sign in to comment.