Skip to content

Commit 7f0a450

Browse files
committed
MNT: remove Python 2.7 copy of relpath
Matplotlib now depends on Python 2.6, which has relpath
1 parent d160d6c commit 7f0a450

File tree

1 file changed

+1
-61
lines changed

1 file changed

+1
-61
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
from six.moves import xrange
135135

136136
import sys, os, shutil, io, re, textwrap
137+
from os.path import relpath
137138
import traceback
138139

139140
if not six.PY3:
@@ -168,67 +169,6 @@ def format_template(template, **kw):
168169

169170
__version__ = 2
170171

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-
232172
#------------------------------------------------------------------------------
233173
# Registration hook
234174
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)