os.path.relpath() in gettext builder

LRN avatarLRN created an issue

This line:

# generate "#: file1:line1\n#: file2:line2 ..."
pofile.write(u"#: %s\n" % "\n#: ".join("%s:%s" %
    (path.relpath(source, self.outdir), line)
    for source, line, _ in positions))

in sphinx/builders/gettext.py

Throws an exception on W32:

  File "%PYTHONPATH%\lib\ntpath.py", line 512, in relpath
    % (path_prefix, start_prefix))
ValueError: path is on drive %DRIVE1%:, start on drive %DRIVE2%:

because `source' is absolute path, and self.outdir is also an absolute path (even if sphinx-build was invoked with relative paths for source and output directories), and they could be (and are, in my case) on different drives.

If being able to express source path as relative to self.outdir is a requirement, then i simply don't know how this is going to be fixed. Otherwise, you can catch ValueError here (sticking to better-to-ask-forgiveness-than-to-ask-permission line) and output source path as-is.

Comments (2)

  1. LRN

    The reason why this is happening is that sphinx doc refers to a number of messages (for ext.pot and web.pot) that come not from its own documentation rst file, but from sphinx itself, for example:

    %PYTHONPATH%\lib\site-packages\sphinx-1.1predev_20110917-py2.7.egg\sphinx\domains\__init__.py:docstring of sphinx.domains.Domain:1
    

    These references might (and do) point to the drive different from the one where documentation rst files are located

    I've made a quick hack (as described in my previous post), and was able to build the .pot files successfully. Looking at them, i see now that these paths are put in comments for translatable messages. I am not familiar enough with gettext toolset to be able to claim that these paths will never be read by any piece of software, and that they are there only for translator's convenience, but from my experience it is so. That makes my hack a viable fix, that could be applied to the tip (sorry, don't have any patches for you, too lazy for that).

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.