summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-21 16:52:41 +0200
committerGeorg Brandl <georg@python.org>2014-09-21 16:52:41 +0200
commit675ee673d9e982a4b975d36630ff3af5ddceccd6 (patch)
treed9d8d787a291c5fe4bfb7601ab86d12f144abcd6
parent30ea7238214a183ccf01c5d6faad7d518c56bbf3 (diff)
downloadsphinx-675ee673d9e982a4b975d36630ff3af5ddceccd6.tar.gz
Fix a few missing Unicode/bytes filename problems.
-rw-r--r--sphinx/builders/changes.py3
-rw-r--r--sphinx/directives/code.py3
-rw-r--r--sphinx/environment.py6
-rw-r--r--sphinx/util/__init__.py11
-rw-r--r--sphinx/util/osutil.py6
5 files changed, 21 insertions, 8 deletions
diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py
index aa947c96..069d0ce6 100644
--- a/sphinx/builders/changes.py
+++ b/sphinx/builders/changes.py
@@ -130,6 +130,9 @@ class ChangesBuilder(Builder):
self.env.config.source_encoding)
try:
lines = f.readlines()
+ except UnicodeDecodeError:
+ self.warn('could not read %r for changelog creation' % docname)
+ continue
finally:
f.close()
targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html'
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index 6ea525b0..543383da 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -47,7 +47,6 @@ class Highlight(Directive):
linenothreshold=linenothreshold)]
-
def dedent_lines(lines, dedent):
if not dedent:
return lines
@@ -93,7 +92,7 @@ class CodeBlock(Directive):
return [document.reporter.warning(str(err), line=self.lineno)]
else:
hl_lines = None
-
+
if 'dedent' in self.options:
lines = code.split('\n')
lines = dedent_lines(lines, self.options['dedent'])
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 635845b8..648e2256 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -39,7 +39,7 @@ from sphinx import addnodes
from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \
FilenameUniqDict
from sphinx.util.nodes import clean_astext, make_refnode, WarningStream
-from sphinx.util.osutil import SEP, find_catalog_files
+from sphinx.util.osutil import SEP, find_catalog_files, getcwd, fs_encoding
from sphinx.util.matching import compile_matchers
from sphinx.util.websupport import is_commentable
from sphinx.errors import SphinxError, ExtensionError
@@ -774,7 +774,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:
@@ -782,6 +782,8 @@ class BuildEnvironment:
for dep in deps.list:
# the dependency path is relative to the working dir, so get
# one relative to the srcdir
+ if isinstance(dep, bytes):
+ dep = dep.decode(fs_encoding)
relpath = relative_path(frompath,
path.normpath(path.join(cwd, dep)))
self.dependencies.setdefault(docname, set()).add(relpath)
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 3a4334e7..56cd3888 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -31,13 +31,14 @@ import jinja2
import sphinx
from sphinx.errors import PycodeError
from sphinx.util.console import strip_colors
+from sphinx.util.osutil import fs_encoding
# import other utilities; partly for backwards compatibility, so don't
# prune unused ones indiscriminately
from sphinx.util.osutil import SEP, os_path, relative_uri, ensuredir, walk, \
- mtimes_of_files, movefile, copyfile, copytimes, make_filename, ustrftime
+ mtimes_of_files, movefile, copyfile, copytimes, make_filename, ustrftime
from sphinx.util.nodes import nested_parse_with_titles, split_explicit_title, \
- explicit_title_re, caption_ref_re
+ explicit_title_re, caption_ref_re
from sphinx.util.matching import patfilter
# Generally useful regular expressions.
@@ -200,10 +201,12 @@ def save_traceback(app):
last_msgs)).encode('utf-8'))
if app is not None:
for extname, extmod in iteritems(app._extensions):
+ modfile = getattr(extmod, '__file__', 'unknown')
+ if isinstance(modfile, bytes):
+ modfile = modfile.decode(fs_encoding, 'replace')
os.write(fd, ('# %s (%s) from %s\n' % (
extname, app._extension_versions[extname],
- getattr(extmod, '__file__', 'unknown'))
- ).encode('utf-8'))
+ modfile)).encode('utf-8'))
os.write(fd, exc.encode('utf-8'))
os.close(fd)
return path
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 9b5f58b7..58ee31b7 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -194,3 +194,9 @@ def abspath(pathdir):
if isinstance(pathdir, bytes):
pathdir = pathdir.decode(fs_encoding)
return pathdir
+
+
+def getcwd():
+ if hasattr(os, 'getcwdu'):
+ return os.getcwdu()
+ return os.getcwd()