summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-12-28 19:11:32 +0100
committerGeorg Brandl <georg@python.org>2008-12-28 19:11:32 +0100
commit21b155b73b985c46f5002b1f040acceaf5308dde (patch)
tree1701defaec44c064494f2e073698d4768075166c
parent38389187caa3491b765bb4efd9f564e595b8329b (diff)
downloadsphinx-21b155b73b985c46f5002b1f040acceaf5308dde.tar.gz
Factor out docname path joining into an utility function.
-rw-r--r--sphinx/directives/other.py8
-rw-r--r--sphinx/util/__init__.py6
2 files changed, 9 insertions, 5 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index 8a4224a9..2aa5a7fb 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -8,14 +8,13 @@
"""
import re
-import posixpath
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx import addnodes
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
@@ -25,7 +24,6 @@ def toctree_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
env = state.document.settings.env
suffix = env.config.source_suffix
- dirname = posixpath.dirname(env.docname)
glob = 'glob' in options
ret = []
@@ -49,14 +47,14 @@ def toctree_directive(name, arguments, options, content, lineno,
if docname.endswith(suffix):
docname = docname[:-len(suffix)]
# absolutize filenames
- docname = posixpath.normpath(posixpath.join(dirname, docname))
+ docname = docname_join(env.docname, docname)
if docname not in env.found_docs:
ret.append(state.document.reporter.warning(
'toctree references unknown document %r' % docname, line=lineno))
else:
includefiles.append(docname)
else:
- patname = posixpath.normpath(posixpath.join(dirname, entry))
+ patname = docname_join(env.docname, entry)
docnames = sorted(patfilter(all_docnames, patname))
for docname in docnames:
all_docnames.remove(docname) # don't include it again
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 04be80d1..1d654134 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -15,6 +15,7 @@ import sys
import time
import fnmatch
import tempfile
+import posixpath
import traceback
from os import path
@@ -48,6 +49,11 @@ def relative_uri(base, to):
return ('..' + SEP) * (len(b2)-1) + SEP.join(t2)
+def docname_join(basedocname, docname):
+ return posixpath.normpath(
+ posixpath.join('/' + basedocname, '..', docname))[1:]
+
+
def ensuredir(path):
"""Ensure that a path exists."""
try: