Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b46ef9

Browse files
committed
Fixed 'change_root() to work at all on Windows, and to work correctly on Unix.
1 parent a76bbd4 commit 4b46ef9

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

Lib/distutils/util.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ def native_path (pathname):
8686

8787

8888
def change_root (new_root, pathname):
89-
9089
"""Return 'pathname' with 'new_root' prepended. If 'pathname' is
9190
relative, this is equivalent to "os.path.join(new_root,pathname)".
9291
Otherwise, it requires making 'pathname' relative and then joining the
93-
two, which is tricky on DOS/Windows and Mac OS."""
94-
95-
if not abspath (pathname):
96-
return os.path.join (new_root, pathname)
97-
98-
elif os.name == 'posix':
99-
return os.path.join (new_root, pathname[1:])
92+
two, which is tricky on DOS/Windows and Mac OS.
93+
"""
94+
if os.name == 'posix':
95+
if not os.path.isabs (pathname):
96+
return os.path.join (new_root, pathname)
97+
else:
98+
return os.path.join (new_root, pathname[1:])
10099

101100
elif os.name == 'nt':
102-
(root_drive, root_path) = os.path.splitdrive (new_root)
103101
(drive, path) = os.path.splitdrive (pathname)
104-
raise RuntimeError, "I give up -- not sure how to do this on Windows"
102+
if path[0] == '\\':
103+
path = path[1:]
104+
return os.path.join (new_root, path)
105105

106106
elif os.name == 'mac':
107107
raise RuntimeError, "no clue how to do this on Mac OS"

0 commit comments

Comments
 (0)