From 873efc53580b04c4f4a6bfeb9d3164cbb2dfbb7b Mon Sep 17 00:00:00 2001 From: tk0miya Date: Mon, 15 Sep 2014 22:10:13 +0900 Subject: [PATCH] Fix #1512 env.record_dependency crashes on multibyte directories --- sphinx/environment.py | 4 ++-- sphinx/util/pycompat.py | 3 +++ tests/test_env.py | 27 ++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sphinx/environment.py b/sphinx/environment.py index 69a8b57fd..bc3df2c08 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -39,7 +39,7 @@ from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \ from sphinx.util.nodes import clean_astext, make_refnode, WarningStream from sphinx.util.osutil import SEP, fs_encoding, find_catalog_files from sphinx.util.matching import compile_matchers -from sphinx.util.pycompat import class_types +from sphinx.util.pycompat import class_types, getcwd from sphinx.util.compat import docutils_version from sphinx.util.websupport import is_commentable from sphinx.errors import SphinxError, ExtensionError @@ -760,7 +760,7 @@ class BuildEnvironment: def process_dependencies(self, docname, doctree): """Process docutils-generated dependency info.""" - cwd = os.getcwd() + cwd = getcwd() frompath = path.join(path.normpath(self.srcdir), 'dummy') deps = doctree.settings.record_dependencies if not deps: diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 17f8871e8..c4598142f 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -25,6 +25,8 @@ if sys.version_info >= (3, 0): bytes = bytes # prefix for Unicode strings u = '' + # getcwd function + from os import getcwd # StringIO/BytesIO classes from io import StringIO, BytesIO, TextIOWrapper # safely encode a string for printing to the terminal @@ -58,6 +60,7 @@ else: b = str bytes = str u = 'u' + from os import getcwdu as getcwd from StringIO import StringIO BytesIO = StringIO # no need to refactor on 2.x versions diff --git a/tests/test_env.py b/tests/test_env.py index eaaa212f8..c5a091cda 100644 --- a/tests/test_env.py +++ b/tests/test_env.py @@ -8,9 +8,11 @@ :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import os import sys +import tempfile -from util import TestApp, remove_unicode_literals, path +from util import TestApp, test_root, remove_unicode_literals, path from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.builders.latex import LaTeXBuilder @@ -95,6 +97,29 @@ def test_second_update(): assert 'autodoc' not in env.all_docs assert 'autodoc' not in env.found_docs + +def test_record_dependency_on_multibyte_directory(): + app = None + olddir = os.getcwd() + try: + tmproot = path(os.path.abspath(tempfile.mkdtemp())) + tmpdir = tmproot / u'ใƒ†ใ‚นใƒˆ' + test_root.copytree(tmpdir) + os.chdir(tmpdir) + tmpdir = path(os.getcwd()) # for MacOSX; tmpdir is based on symlinks + + app = TestApp(srcdir=tmpdir, freshenv=True) + (app.srcdir / 'test.txt').write_text('.. include:: test.inc') + (app.srcdir / 'test.inc').write_text('hello sphinx') + _, _, it = app.env.update(app.config, app.srcdir, app.doctreedir, app) + list(it) # take all from iterator + finally: + tmproot.rmtree(ignore_errors=True) + os.chdir(olddir) + if app: + app.cleanup() + + def test_object_inventory(): refs = env.domaindata['py']['objects']