1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
From 1ed69d8e50d34a111c7b42951863e13d9cef1930 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 21 Sep 2021 21:18:50 +0200
Subject: [PATCH 094/N] distutils: msys convert_path fix and root hack
---
Lib/distutils/command/install.py | 3 ++-
Lib/distutils/util.py | 26 ++++++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index c611252..f8c42c7 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -342,7 +342,8 @@ class install(Command):
# 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',
'userbase', 'usersite')
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 7b2e1e0..75a369d 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -131,6 +131,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 ()
@@ -141,6 +148,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):
@@ -150,9 +161,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)
--
2.33.0
|