Skip to content

Commit 36a9b36

Browse files
authored
Merge pull request #11522 from hroncok/no_tests_disutils
2 parents ff207cf + fe7948a commit 36a9b36

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

news/7d576457-c1fe-4d64-88a4-f775a2f6995d.trivial.rst

Whitespace-only changes.

tests/functional/test_install.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import distutils
21
import os
32
import re
43
import ssl
54
import sys
5+
import sysconfig
66
import textwrap
77
from os.path import curdir, join, pardir
88
from pathlib import Path
@@ -1145,6 +1145,39 @@ def main(): pass
11451145
assert "--no-warn-script-location" not in result.stderr, str(result)
11461146

11471147

1148+
def _change_root(new_root: str, pathname: str) -> str:
1149+
"""
1150+
Adapted from distutils.
1151+
1152+
Return 'pathname' with 'new_root' prepended. If 'pathname' is
1153+
relative, this is equivalent to "os.path.join(new_root,pathname)".
1154+
Otherwise, it requires making 'pathname' relative and then joining the
1155+
two, which is tricky on DOS/Windows and Mac OS.
1156+
"""
1157+
try:
1158+
from distutils.util import change_root
1159+
except ImportError:
1160+
pass
1161+
else:
1162+
return change_root(new_root, pathname)
1163+
1164+
if os.name == "posix":
1165+
if not os.path.isabs(pathname):
1166+
return os.path.join(new_root, pathname)
1167+
else:
1168+
return os.path.join(new_root, pathname[1:])
1169+
1170+
elif os.name == "nt":
1171+
drive, path = os.path.splitdrive(pathname)
1172+
if path[0] == "\\":
1173+
path = path[1:]
1174+
return os.path.join(new_root, path)
1175+
1176+
else:
1177+
# distutils raise DistutilsPlatformError here
1178+
raise RuntimeError(f"nothing known about platform '{os.name}'")
1179+
1180+
11481181
@pytest.mark.usefixtures("with_wheel")
11491182
def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -> None:
11501183
"""
@@ -1163,10 +1196,8 @@ def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -
11631196
normal_install_path = os.fspath(
11641197
script.base_path / script.site_packages / "simple-1.0.dist-info"
11651198
)
1166-
# use distutils to change the root exactly how the --root option does it
1167-
from distutils.util import change_root
11681199

1169-
root_path = change_root(os.path.join(script.scratch, "root"), normal_install_path)
1200+
root_path = _change_root(os.path.join(script.scratch, "root"), normal_install_path)
11701201
result.did_create(root_path)
11711202

11721203
# Should show find-links location in output
@@ -1195,7 +1226,7 @@ def test_install_package_with_prefix(
11951226

11961227
rel_prefix_path = script.scratch / "prefix"
11971228
install_path = join(
1198-
distutils.sysconfig.get_python_lib(prefix=rel_prefix_path),
1229+
sysconfig.get_path("purelib", vars={"base": rel_prefix_path}),
11991230
# we still test for egg-info because no-binary implies setup.py install
12001231
f"simple-1.0-py{pyversion}.egg-info",
12011232
)
@@ -1217,7 +1248,7 @@ def _test_install_editable_with_prefix(
12171248
"prefix", "lib", f"python{pyversion}", "site-packages"
12181249
)
12191250
else:
1220-
site_packages = distutils.sysconfig.get_python_lib(prefix="prefix")
1251+
site_packages = sysconfig.get_path("purelib", vars={"base": "prefix"})
12211252

12221253
# make sure target path is in PYTHONPATH
12231254
pythonpath = script.scratch_path / site_packages

tests/functional/test_install_wheel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import base64
22
import csv
3-
import distutils
43
import hashlib
54
import os
65
import shutil
6+
import sysconfig
77
from pathlib import Path
88
from typing import Any
99

@@ -284,7 +284,9 @@ def test_install_wheel_with_prefix(
284284
"--find-links",
285285
tmpdir,
286286
)
287-
lib = distutils.sysconfig.get_python_lib(prefix=os.path.join("scratch", "prefix"))
287+
lib = sysconfig.get_path(
288+
"purelib", vars={"base": os.path.join("scratch", "prefix")}
289+
)
288290
result.did_create(lib)
289291

290292

0 commit comments

Comments
 (0)