From f7589d6ec0024f310b9643805201495ffb44b0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 16 Nov 2022 13:28:17 +0100 Subject: [PATCH] Don't maintain 2 copies of change_root The change_root function was added twice: In ae324d17033253626725330c6635c0089927fbf5 and in 36a9b365234a0e6608e9304f560d68df7bf85038 --- ...1b-9024-4448-9ae1-6e4a5a5952f0.trivial.rst | 0 tests/functional/test_install.py | 38 ++----------------- 2 files changed, 4 insertions(+), 34 deletions(-) create mode 100644 news/c1da841b-9024-4448-9ae1-6e4a5a5952f0.trivial.rst diff --git a/news/c1da841b-9024-4448-9ae1-6e4a5a5952f0.trivial.rst b/news/c1da841b-9024-4448-9ae1-6e4a5a5952f0.trivial.rst new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index f611372685f..6131a4054d6 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -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: """ @@ -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