Skip to content

Commit

Permalink
distutils: msys convert_path fix and root hack
Browse files Browse the repository at this point in the history
Co-authored-by: Naveen M K <naveen521kk@gmail.com>
  • Loading branch information
lazka and naveen521kk committed Jul 19, 2023
1 parent 5e82de4 commit c65ce77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Lib/distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ def finalize_options(self):

# Convert directories from Unix /-separated syntax to the local
# convention.
self.convert_paths('lib', 'purelib', 'platlib',
self.convert_paths('base', 'platbase',
'lib', 'purelib', 'platlib',
'scripts', 'data', 'headers')
if HAS_USER_SITE:
self.convert_paths('userbase', 'usersite')
Expand Down
26 changes: 24 additions & 2 deletions Lib/distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ def convert_path (pathname):
paths.remove('.')
if not paths:
return os.curdir
# On Windows, if paths is ['C:','folder','subfolder'] then
# os.path.join(*paths) will return 'C:folder\subfolder' which
# is thus relative to the CWD on that drive. So we work around
# this by adding a \ to path[0]
if (len(paths) > 0 and paths[0].endswith(':') and
sys.platform == "win32" and sys.version.find("GCC") >= 0):
paths[0] += '\\'
return os.path.join(*paths)

# convert_path ()
Expand All @@ -142,6 +149,10 @@ def change_root (new_root, pathname):
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.
If on Windows or OS/2 and both new_root and pathname are on different
drives, raises DistutilsChangeRootError as this is nonsensical,
otherwise use drive which can be in either of new_root or pathname.
"""
if os.name == 'posix':
if not os.path.isabs(pathname):
Expand All @@ -151,9 +162,20 @@ def change_root (new_root, pathname):

elif os.name == 'nt':
(drive, path) = os.path.splitdrive(pathname)
if path[0] == '\\':
if path[0] == os.sep:
path = path[1:]
return os.path.join(new_root, path)
(drive_r, path_r) = os.path.splitdrive(new_root)
if path_r and path_r[0] == os.sep:
path_r = path_r[1:]
drive_used = ''
if len(drive) == 2 and len(drive_r) == 2 and drive != drive_r:
raise DistutilsChangeRootError("root and pathname not on same drive (%s, %s)"
% (drive_r,drive))
elif len(drive_r) == 2:
drive_used = drive_r+os.sep
elif len(drive) == 2:
drive_used = drive+os.sep
return os.path.join(drive_used+path_r, path)

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

0 comments on commit c65ce77

Please sign in to comment.