Skip to content

Commit 4a014f9

Browse files
committed
Replace distutils with sysconfig on Python 3.12+
1 parent 56f8b38 commit 4a014f9

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

tests/functional/test_build_env.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
from textwrap import dedent
34
from typing import Optional
45

@@ -203,6 +204,31 @@ def test_build_env_overlay_prefix_has_priority(script: PipTestEnvironment) -> No
203204
assert result.stdout.strip() == "2.0", str(result)
204205

205206

207+
if sys.version_info < (3, 12):
208+
BUILD_ENV_ERROR_DEBUG_CODE = r"""
209+
from distutils.sysconfig import get_python_lib
210+
print(
211+
f'imported `pkg` from `{pkg.__file__}`',
212+
file=sys.stderr)
213+
print('system sites:\n ' + '\n '.join(sorted({
214+
get_python_lib(plat_specific=0),
215+
get_python_lib(plat_specific=1),
216+
})), file=sys.stderr)
217+
"""
218+
else:
219+
BUILD_ENV_ERROR_DEBUG_CODE = r"""
220+
from sysconfig import get_paths
221+
paths = get_paths()
222+
print(
223+
f'imported `pkg` from `{pkg.__file__}`',
224+
file=sys.stderr)
225+
print('system sites:\n ' + '\n '.join(sorted({
226+
paths['platlib'],
227+
paths['purelib'],
228+
})), file=sys.stderr)
229+
"""
230+
231+
206232
@pytest.mark.usefixtures("enable_user_site")
207233
def test_build_env_isolation(script: PipTestEnvironment) -> None:
208234
# Create dummy `pkg` wheel.
@@ -231,26 +257,17 @@ def test_build_env_isolation(script: PipTestEnvironment) -> None:
231257
run_with_build_env(
232258
script,
233259
"",
234-
r"""
235-
from distutils.sysconfig import get_python_lib
260+
f"""
236261
import sys
237262
238263
try:
239264
import pkg
240265
except ImportError:
241266
pass
242267
else:
243-
print(
244-
f'imported `pkg` from `{pkg.__file__}`',
245-
file=sys.stderr)
246-
print('system sites:\n ' + '\n '.join(sorted({
247-
get_python_lib(plat_specific=0),
248-
get_python_lib(plat_specific=1),
249-
})), file=sys.stderr)
250-
print('sys.path:\n ' + '\n '.join(sys.path), file=sys.stderr)
268+
{BUILD_ENV_ERROR_DEBUG_CODE}
269+
print('sys.path:\\n ' + '\\n '.join(sys.path), file=sys.stderr)
251270
sys.exit(1)
252-
"""
253-
f"""
254271
# second check: direct check of exclusion of system site packages
255272
import os
256273

0 commit comments

Comments
 (0)