Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't maintain 2 copies of change_root #11600

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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