@@ -1145,39 +1145,6 @@ def main(): pass
1145
1145
assert "--no-warn-script-location" not in result .stderr , str (result )
1146
1146
1147
1147
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
-
1181
1148
@pytest .mark .usefixtures ("with_wheel" )
1182
1149
def test_install_package_with_root (script : PipTestEnvironment , data : TestData ) -> None :
1183
1150
"""
@@ -1196,8 +1163,11 @@ def test_install_package_with_root(script: PipTestEnvironment, data: TestData) -
1196
1163
normal_install_path = os .fspath (
1197
1164
script .base_path / script .site_packages / "simple-1.0.dist-info"
1198
1165
)
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
1199
1169
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 )
1201
1171
result .did_create (root_path )
1202
1172
1203
1173
# Should show find-links location in output
0 commit comments