@@ -132,6 +132,13 @@ def convert_path (pathname):
132
132
paths .remove ('.' )
133
133
if not paths :
134
134
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 ] += '\\ '
135
142
return os .path .join (* paths )
136
143
137
144
# convert_path ()
@@ -142,6 +149,10 @@ def change_root (new_root, pathname):
142
149
relative, this is equivalent to "os.path.join(new_root,pathname)".
143
150
Otherwise, it requires making 'pathname' relative and then joining the
144
151
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.
145
156
"""
146
157
if os .name == 'posix' :
147
158
if not os .path .isabs (pathname ):
@@ -151,9 +162,20 @@ def change_root (new_root, pathname):
151
162
152
163
elif os .name == 'nt' :
153
164
(drive , path ) = os .path .splitdrive (pathname )
154
- if path [0 ] == ' \\ ' :
165
+ if path [0 ] == os . sep :
155
166
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 )
157
179
158
180
else :
159
181
raise DistutilsPlatformError ("nothing known about platform '%s'" % os .name )
0 commit comments