Commits

Takayuki Shimizukawa committed 6770d21

* fix for Python2.5: test failed by using os.path.relpath that introduced at Python-2.6.

  • Participants
  • Parent commits f05fa4e

Comments (0)

Files changed (2)

File sphinx/util/osutil.py

 
 
 def safe_relpath(path, start=None):
+    from sphinx.util.pycompat import relpath
     try:
-        return os.path.relpath(path, start)
+        return relpath(path, start)
     except ValueError:
         return path
 

File sphinx/util/pycompat.py

     except ImportError:
         from itertools import izip_longest as zip_longest
 
+    import os
+    relpath = os.path.relpath
+    del os
+
 else:
     # Python < 2.6
     from itertools import izip, repeat, chain
         except IndexError:
             pass
 
+    from os.path import curdir
+    def relpath(path, start=curdir):
+        """Return a relative version of a path"""
+        from os.path import sep, abspath, commonprefix, join, pardir
+
+        if not path:
+            raise ValueError("no path specified")
+
+        start_list = abspath(start).split(sep)
+        path_list = abspath(path).split(sep)
+
+        # Work out how much of the filepath is shared by start and path.
+        i = len(commonprefix([start_list, path_list]))
+
+        rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+        if not rel_list:
+            return curdir
+        return join(*rel_list)
+    del curdir
+
 
 # ------------------------------------------------------------------------------
 # Missing builtins and codecs in Python < 2.5