Takayuki Shimizukawa avatar Takayuki Shimizukawa committed f8a5495

When Sphinx couldn't decode multibyte filename, now Sphinx notices UnicodeError and continuing if possible instead of raise exception. Closes #703

Comments (0)

Files changed (6)

   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)

sphinx/cmdline.py

 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
 
 
     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

sphinx/util/osutil.py

 
     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)

tests/test_build.py

     :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
 
 
 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
         ==========================

tests/test_quickstart.py

 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
         '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'
 
 

tests/test_setup_command.py

 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
 
 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
         ==========================
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.