Commits

Georg Brandl  committed af18efd

Fix #765: on Windows, relpath() does not always succeed.

  • Participants
  • Parent commits f6f7f2e

Comments (0)

Files changed (2)

File sphinx/builders/gettext.py

 from datetime import datetime
 from collections import defaultdict
 
-from docutils import nodes
-
 from sphinx.builders import Builder
 from sphinx.util.nodes import extract_messages
-from sphinx.util.osutil import SEP, copyfile
+from sphinx.util.osutil import SEP, safe_relpath
 from sphinx.util.console import darkgreen
 
 POHEADER = ur"""
 
                     # generate "#: file1:line1\n#: file2:line2 ..."
                     pofile.write(u"#: %s\n" % "\n#: ".join("%s:%s" %
-                        (path.relpath(source, self.outdir), line)
+                        (safe_relpath(source, self.outdir), line)
                         for source, line, _ in positions))
                     # generate "# uuid1\n# uuid2\n ..."
                     pofile.write(u"# %s\n" % "\n# ".join(uid for _, _, uid

File sphinx/util/osutil.py

                 .decode('utf-8')
 else:
     ustrftime = time.strftime
+
+
+def safe_relpath(path, start=None):
+    try:
+        return os.path.relpath(path, start)
+    except ValueError:
+        return path