Skip to content

Commit c65ce77

Browse files
lazkanaveen521kk
andcommitted
distutils: msys convert_path fix and root hack
Co-authored-by: Naveen M K <[email protected]>
1 parent 5e82de4 commit c65ce77

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Lib/distutils/command/install.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def finalize_options(self):
363363

364364
# Convert directories from Unix /-separated syntax to the local
365365
# convention.
366-
self.convert_paths('lib', 'purelib', 'platlib',
366+
self.convert_paths('base', 'platbase',
367+
'lib', 'purelib', 'platlib',
367368
'scripts', 'data', 'headers')
368369
if HAS_USER_SITE:
369370
self.convert_paths('userbase', 'usersite')

Lib/distutils/util.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ def convert_path (pathname):
132132
paths.remove('.')
133133
if not paths:
134134
return os.curdir
135+
# On Windows, if paths is ['C:','folder','subfolder'] then
136+
# os.path.join(*paths) will return 'C:folder\subfolder' which
137+
# is thus relative to the CWD on that drive. So we work around
138+
# this by adding a \ to path[0]
139+
if (len(paths) > 0 and paths[0].endswith(':') and
140+
sys.platform == "win32" and sys.version.find("GCC") >= 0):
141+
paths[0] += '\\'
135142
return os.path.join(*paths)
136143

137144
# convert_path ()
@@ -142,6 +149,10 @@ def change_root (new_root, pathname):
142149
relative, this is equivalent to "os.path.join(new_root,pathname)".
143150
Otherwise, it requires making 'pathname' relative and then joining the
144151
two, which is tricky on DOS/Windows and Mac OS.
152+
153+
If on Windows or OS/2 and both new_root and pathname are on different
154+
drives, raises DistutilsChangeRootError as this is nonsensical,
155+
otherwise use drive which can be in either of new_root or pathname.
145156
"""
146157
if os.name == 'posix':
147158
if not os.path.isabs(pathname):
@@ -151,9 +162,20 @@ def change_root (new_root, pathname):
151162

152163
elif os.name == 'nt':
153164
(drive, path) = os.path.splitdrive(pathname)
154-
if path[0] == '\\':
165+
if path[0] == os.sep:
155166
path = path[1:]
156-
return os.path.join(new_root, path)
167+
(drive_r, path_r) = os.path.splitdrive(new_root)
168+
if path_r and path_r[0] == os.sep:
169+
path_r = path_r[1:]
170+
drive_used = ''
171+
if len(drive) == 2 and len(drive_r) == 2 and drive != drive_r:
172+
raise DistutilsChangeRootError("root and pathname not on same drive (%s, %s)"
173+
% (drive_r,drive))
174+
elif len(drive_r) == 2:
175+
drive_used = drive_r+os.sep
176+
elif len(drive) == 2:
177+
drive_used = drive+os.sep
178+
return os.path.join(drive_used+path_r, path)
157179

158180
else:
159181
raise DistutilsPlatformError("nothing known about platform '%s'" % os.name)

0 commit comments

Comments
 (0)