From 58be2f19b3aeeabf4d9a3d10be84824508c0fda2 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Sat, 28 Sep 2013 12:51:20 +0000 Subject: [PATCH] When Sphinx couldn't decode multibyte filename, now Sphinx notices UnicodeError and continuing if possible instead of raise exception. Closes #703 --- CHANGES | 2 ++ sphinx/cmdline.py | 7 ++++++- sphinx/util/osutil.py | 9 ++++++++- tests/test_build.py | 11 +++++++++-- tests/test_quickstart.py | 9 +++++++-- tests/test_setup_command.py | 11 +++++++++-- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index e6ffc750d..8167b517f 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,8 @@ Bugs fixed named target. * A wrong conditoin check break search feature on first page that is usually index.rst. This issue was introduced at 1.2b1 +* #703: When Sphinx couldn't decode multibyte filename, now Sphinx notices + UnicodeError and continuing if possible instead of raise exception. Release 1.2 beta2 (released Sep 17, 2013) diff --git a/sphinx/cmdline.py b/sphinx/cmdline.py index 43c33378c..a9dc9fc85 100644 --- a/sphinx/cmdline.py +++ b/sphinx/cmdline.py @@ -22,7 +22,7 @@ from sphinx.errors import SphinxError from sphinx.application import Sphinx from sphinx.util import Tee, format_exception_cut_frames, save_traceback from sphinx.util.console import red, nocolor, color_terminal -from sphinx.util.osutil import abspath +from sphinx.util.osutil import abspath, fs_encoding from sphinx.util.pycompat import terminal_safe, bytes @@ -112,6 +112,11 @@ def main(argv): except IndexError: usage(argv, 'Error: Insufficient arguments.') return 1 + except UnicodeError: + print >>sys.stderr, ( + 'Error: Multibyte filename did not support on this filesystem ' + 'encoding: %s' % fs_encoding) + return 1 filenames = args[2:] err = 0 diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index f37c10222..3128b9c78 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -77,7 +77,14 @@ def walk(top, topdown=True, followlinks=False): dirs, nondirs = [], [] for name in names: - if path.isdir(path.join(top, name)): + try: + fullpath = path.join(top, name) + except UnicodeError: + print >>sys.stderr, ( + '%s:: ERROR: multibyte filename did not support on this filesystem ' + 'encoding %r, skipped.' % (name, fs_encoding)) + continue + if path.isdir(fullpath): dirs.append(name) else: nondirs.append(name) diff --git a/tests/test_build.py b/tests/test_build.py index b172184b1..4f6ba259e 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for details. """ -from util import with_app, test_root, path +from util import with_app, test_root, path, SkipTest from textwrap import dedent @@ -76,7 +76,14 @@ def test_pseudoxml(app): def test_multibyte_path(app): srcdir = path(app.srcdir) mb_name = u'\u65e5\u672c\u8a9e' - (srcdir / mb_name).makedirs() + try: + (srcdir / mb_name).makedirs() + except UnicodeEncodeError: + from path import FILESYSTEMENCODING + raise SkipTest( + 'multibyte filename did not support on this filesystem encoding: ' + '%s', FILESYSTEMENCODING) + (srcdir / mb_name / (mb_name + '.txt')).write_text(dedent(""" multi byte file name page ========================== diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 5d814ee56..55ede6e3c 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -14,7 +14,7 @@ import time from StringIO import StringIO import tempfile -from util import raises, with_tempdir, with_app +from util import raises, with_tempdir, with_app, SkipTest from sphinx import application from sphinx import quickstart as qs @@ -114,7 +114,12 @@ def test_do_prompt_with_multibyte(): 'Q1': u'\u30c9\u30a4\u30c4', } qs.term_input = mock_raw_input(answers) - qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c') + try: + qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c') + except UnicodeEncodeError: + raise SkipTest( + 'multibyte console input did not support on this encoding: %s', + qs.TERM_ENCODING) assert d['k1'] == u'\u30c9\u30a4\u30c4' diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index 23b2b4b79..6f0050d68 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -15,7 +15,7 @@ import subprocess from functools import wraps import tempfile -from util import with_tempdir, test_roots +from util import with_tempdir, test_roots, SkipTest from path import path from textwrap import dedent @@ -62,7 +62,14 @@ def test_build_sphinx(pkgroot, proc): def test_build_sphinx_with_multibyte_path(pkgroot, proc): mb_name = u'\u65e5\u672c\u8a9e' srcdir = (pkgroot / 'doc') - (srcdir / mb_name).makedirs() + try: + (srcdir / mb_name).makedirs() + except UnicodeEncodeError: + from path import FILESYSTEMENCODING + raise SkipTest( + 'multibyte filename did not support on this filesystem encoding: ' + '%s', FILESYSTEMENCODING) + (srcdir / mb_name / (mb_name + '.txt')).write_text(dedent(""" multi byte file name page ==========================