Skip to content

Commit 45debcc

Browse files
authored
Merge pull request #11600 from hroncok/no_two_change_roots
2 parents 9aa422d + f7589d6 commit 45debcc

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

news/c1da841b-9024-4448-9ae1-6e4a5a5952f0.trivial.rst

Whitespace-only changes.

tests/functional/test_install.py

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,39 +1145,6 @@ 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-
11811148
@pytest.mark.usefixtures("with_wheel")
11821149
def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -> None:
11831150
"""
@@ -1196,8 +1163,11 @@ def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -
11961163
normal_install_path = os.fspath(
11971164
script.base_path / script.site_packages / "simple-1.0.dist-info"
11981165
)
1166+
# use a function borrowed from distutils
1167+
# to change the root exactly how the --root option does it
1168+
from pip._internal.locations.base import change_root
11991169

1200-
root_path = _change_root(os.path.join(script.scratch, "root"), normal_install_path)
1170+
root_path = change_root(os.path.join(script.scratch, "root"), normal_install_path)
12011171
result.did_create(root_path)
12021172

12031173
# Should show find-links location in output

0 commit comments

Comments
 (0)