Factor out docname path joining into an utility function.

This commit is contained in:
Georg Brandl 2008-12-28 19:11:32 +01:00
parent 7433721617
commit 377b461b1c
2 changed files with 9 additions and 5 deletions

View File

@ -8,14 +8,13 @@
""" """
import re import re
import posixpath
from docutils import nodes from docutils import nodes
from docutils.parsers.rst import directives from docutils.parsers.rst import directives
from sphinx import addnodes from sphinx import addnodes
from sphinx.locale import pairindextypes from sphinx.locale import pairindextypes
from sphinx.util import patfilter, ws_re, caption_ref_re from sphinx.util import patfilter, ws_re, caption_ref_re, docname_join
from sphinx.util.compat import make_admonition from sphinx.util.compat import make_admonition
@ -25,7 +24,6 @@ def toctree_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine): content_offset, block_text, state, state_machine):
env = state.document.settings.env env = state.document.settings.env
suffix = env.config.source_suffix suffix = env.config.source_suffix
dirname = posixpath.dirname(env.docname)
glob = 'glob' in options glob = 'glob' in options
ret = [] ret = []
@ -49,14 +47,14 @@ def toctree_directive(name, arguments, options, content, lineno,
if docname.endswith(suffix): if docname.endswith(suffix):
docname = docname[:-len(suffix)] docname = docname[:-len(suffix)]
# absolutize filenames # absolutize filenames
docname = posixpath.normpath(posixpath.join(dirname, docname)) docname = docname_join(env.docname, docname)
if docname not in env.found_docs: if docname not in env.found_docs:
ret.append(state.document.reporter.warning( ret.append(state.document.reporter.warning(
'toctree references unknown document %r' % docname, line=lineno)) 'toctree references unknown document %r' % docname, line=lineno))
else: else:
includefiles.append(docname) includefiles.append(docname)
else: else:
patname = posixpath.normpath(posixpath.join(dirname, entry)) patname = docname_join(env.docname, entry)
docnames = sorted(patfilter(all_docnames, patname)) docnames = sorted(patfilter(all_docnames, patname))
for docname in docnames: for docname in docnames:
all_docnames.remove(docname) # don't include it again all_docnames.remove(docname) # don't include it again

View File

@ -15,6 +15,7 @@ import sys
import time import time
import fnmatch import fnmatch
import tempfile import tempfile
import posixpath
import traceback import traceback
from os import path from os import path
@ -48,6 +49,11 @@ def relative_uri(base, to):
return ('..' + SEP) * (len(b2)-1) + SEP.join(t2) return ('..' + SEP) * (len(b2)-1) + SEP.join(t2)
def docname_join(basedocname, docname):
return posixpath.normpath(
posixpath.join('/' + basedocname, '..', docname))[1:]
def ensuredir(path): def ensuredir(path):
"""Ensure that a path exists.""" """Ensure that a path exists."""
try: try: