Skip to content

Commit

Permalink
Merge pull request #11600 from hroncok/no_two_change_roots
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Nov 16, 2022
2 parents 9aa422d + f7589d6 commit 45debcc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
Empty file.
38 changes: 4 additions & 34 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,39 +1145,6 @@ def main(): pass
assert "--no-warn-script-location" not in result.stderr, str(result)


def _change_root(new_root: str, pathname: str) -> str:
"""
Adapted from distutils.
Return 'pathname' with 'new_root' prepended. If 'pathname' is
relative, this is equivalent to "os.path.join(new_root,pathname)".
Otherwise, it requires making 'pathname' relative and then joining the
two, which is tricky on DOS/Windows and Mac OS.
"""
try:
from distutils.util import change_root
except ImportError:
pass
else:
return change_root(new_root, pathname)

if os.name == "posix":
if not os.path.isabs(pathname):
return os.path.join(new_root, pathname)
else:
return os.path.join(new_root, pathname[1:])

elif os.name == "nt":
drive, path = os.path.splitdrive(pathname)
if path[0] == "\\":
path = path[1:]
return os.path.join(new_root, path)

else:
# distutils raise DistutilsPlatformError here
raise RuntimeError(f"nothing known about platform '{os.name}'")


@pytest.mark.usefixtures("with_wheel")
def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -> None:
"""
Expand All @@ -1196,8 +1163,11 @@ def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -
normal_install_path = os.fspath(
script.base_path / script.site_packages / "simple-1.0.dist-info"
)
# use a function borrowed from distutils
# to change the root exactly how the --root option does it
from pip._internal.locations.base import change_root

root_path = _change_root(os.path.join(script.scratch, "root"), normal_install_path)
root_path = change_root(os.path.join(script.scratch, "root"), normal_install_path)
result.did_create(root_path)

# Should show find-links location in output
Expand Down

0 comments on commit 45debcc

Please sign in to comment.