BuildDoc shouldn't fail on Unicode paths.

Sub-classes of sphinx.setup_command.BuildDoc may choose to call
finalize_options in their run() method again for various reasons. However,
currently this fails with py2.7 because of http://bugs.python.org/issue19570.

Since it is unlikely that the upstream issue will be solved, a workaround is
to re-implement distutils' Command._ensure_stringlike to support Unicode
strings.
This commit is contained in:
Sascha Peilicke
2013-11-13 15:33:25 +01:00
parent 8b986fe4db
commit 310b4fb806

View File

@@ -14,6 +14,7 @@
import sys
import os
import types
from StringIO import StringIO
from distutils.cmd import Command
@@ -98,6 +99,19 @@ class BuildDoc(Command):
return root
return None
# Overriding distutils' Command._ensure_stringlike which doesn't support
# unicode, causing finalize_options to fail if invoked again. Workaround
# for http://bugs.python.org/issue19570
def _ensure_stringlike(self, option, what, default=None):
val = getattr(self, option)
if val is None:
setattr(self, option, default)
return default
elif not isinstance(val, types.StringTypes):
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
% (option, what, val))
return val
def finalize_options(self):
if self.source_dir is None:
self.source_dir = self._guess_source_dir()