|
134 | 134 | from six.moves import xrange
|
135 | 135 |
|
136 | 136 | import sys, os, shutil, io, re, textwrap
|
| 137 | +from os.path import relpath |
137 | 138 | import traceback
|
138 | 139 |
|
139 | 140 | if not six.PY3:
|
@@ -168,67 +169,6 @@ def format_template(template, **kw):
|
168 | 169 |
|
169 | 170 | __version__ = 2
|
170 | 171 |
|
171 |
| -#------------------------------------------------------------------------------ |
172 |
| -# Relative pathnames |
173 |
| -#------------------------------------------------------------------------------ |
174 |
| - |
175 |
| -# os.path.relpath is new in Python 2.6 |
176 |
| -try: |
177 |
| - from os.path import relpath |
178 |
| -except ImportError: |
179 |
| - # Copied from Python 2.7 |
180 |
| - if 'posix' in sys.builtin_module_names: |
181 |
| - def relpath(path, start=os.path.curdir): |
182 |
| - """Return a relative version of a path""" |
183 |
| - from os.path import sep, curdir, join, abspath, commonprefix, \ |
184 |
| - pardir |
185 |
| - |
186 |
| - if not path: |
187 |
| - raise ValueError("no path specified") |
188 |
| - |
189 |
| - start_list = abspath(start).split(sep) |
190 |
| - path_list = abspath(path).split(sep) |
191 |
| - |
192 |
| - # Work out how much of the filepath is shared by start and path. |
193 |
| - i = len(commonprefix([start_list, path_list])) |
194 |
| - |
195 |
| - rel_list = [pardir] * (len(start_list)-i) + path_list[i:] |
196 |
| - if not rel_list: |
197 |
| - return curdir |
198 |
| - return join(*rel_list) |
199 |
| - elif 'nt' in sys.builtin_module_names: |
200 |
| - def relpath(path, start=os.path.curdir): |
201 |
| - """Return a relative version of a path""" |
202 |
| - from os.path import sep, curdir, join, abspath, commonprefix, \ |
203 |
| - pardir, splitunc |
204 |
| - |
205 |
| - if not path: |
206 |
| - raise ValueError("no path specified") |
207 |
| - start_list = abspath(start).split(sep) |
208 |
| - path_list = abspath(path).split(sep) |
209 |
| - if start_list[0].lower() != path_list[0].lower(): |
210 |
| - unc_path, rest = splitunc(path) |
211 |
| - unc_start, rest = splitunc(start) |
212 |
| - if bool(unc_path) ^ bool(unc_start): |
213 |
| - raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" |
214 |
| - % (path, start)) |
215 |
| - else: |
216 |
| - raise ValueError("path is on drive %s, start on drive %s" |
217 |
| - % (path_list[0], start_list[0])) |
218 |
| - # Work out how much of the filepath is shared by start and path. |
219 |
| - for i in range(min(len(start_list), len(path_list))): |
220 |
| - if start_list[i].lower() != path_list[i].lower(): |
221 |
| - break |
222 |
| - else: |
223 |
| - i += 1 |
224 |
| - |
225 |
| - rel_list = [pardir] * (len(start_list)-i) + path_list[i:] |
226 |
| - if not rel_list: |
227 |
| - return curdir |
228 |
| - return join(*rel_list) |
229 |
| - else: |
230 |
| - raise RuntimeError("Unsupported platform (no relpath available!)") |
231 |
| - |
232 | 172 | #------------------------------------------------------------------------------
|
233 | 173 | # Registration hook
|
234 | 174 | #------------------------------------------------------------------------------
|
|
0 commit comments