classification
Title: distutils' Command.ensure_dirname fails on Unicode
Type: behavior Stage:
Components: Distutils Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Drekin, doughellmann, georg.brandl, mriedem, saschpe, vstinner
Priority: normal Keywords: patch

Created on 2013-11-13 13:11 by saschpe, last changed 2016-06-13 19:15 by Drekin.

Files
File name Uploaded Description Edit
distutils-ensure_stringlike-unicode.patch saschpe, 2013-11-13 13:11 Patch fixing the issue review
Messages (5)
msg202741 - (view) Author: Sascha Peilicke (saschpe) Date: 2013-11-13 13:11
Encountered an isssue with Unicode paths when invoking Sphinx' distutils command (i.e. 'setup.py build_sphinx'): 

$ python setup.py build_sphinx
running build_sphinx
error: 'source_dir' must be a directory name (got `doc/source`)

...
(Pdb) l
 96                 for root, dirnames, filenames in os.walk(guess):
 97                     if 'conf.py' in filenames:
 98                         return root
 99             return None
100     
101  ->     def finalize_options(self):
102             if self.source_dir is None:
103                 self.source_dir = self._guess_source_dir()
104                 self.announce('Using source directory %s' % self.source_dir)
105             self.ensure_dirname('source_dir')
106             if self.source_dir is None:
(Pdb) n
> /usr/lib/python2.7/site-packages/sphinx/setup_command.py(102)finalize_options()
-> if self.source_dir is None:
(Pdb) n
> /usr/lib/python2.7/site-packages/sphinx/setup_command.py(105)finalize_options()
-> self.ensure_dirname('source_dir')
(Pdb) s
--Call--
> /usr/lib64/python2.7/distutils/cmd.py(266)ensure_dirname()
-> def ensure_dirname(self, option):
(Pdb) s
...
--Call--
> /usr/lib64/python2.7/distutils/cmd.py(253)_ensure_tested_string()
-> def _ensure_tested_string(self, option, tester,
(Pdb) 
> /usr/lib64/python2.7/distutils/cmd.py(255)_ensure_tested_string()
-> val = self._ensure_stringlike(option, what, default)


Command.ensure_dirname (likewise ensure_filename) fails because _ensure_stringlike only tests for isistance(..., str) rather than isinstance(..., types.StringTypes).
msg202742 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-13 13:13
This is more a feature request than a bug. You should use an encoded path, or upgrade to Python 3 which handles Unicode correctly.
msg202749 - (view) Author: Sascha Peilicke (saschpe) Date: 2013-11-13 13:51
Happens since Sphinx-1.2b3, here's some context: https://bitbucket.org/birkenfeld/sphinx/issue/1142
msg212456 - (view) Author: Matt Riedemann (mriedem) Date: 2014-02-28 16:15
For what it's worth, I'm building openstack docs on master (icehouse-3) for ceilometer, nova, cinder, heat, glance, keystone, and neutron (plus the clients) using sphinx 1.2.1 without this problem (unless I'm just not aware of it?).  Anyway, I came across that from this github change for openstack's global-requirements:

https://github.com/openstack/requirements/commit/0e8862e958813a031fe7398440e8a3866b42a8e4
msg268461 - (view) Author: Adam Bartoš (Drekin) * Date: 2016-06-13 19:15
Recently, I was also hit by this when trying to autoset `sys.argv` to a list of Unicode string (see https://github.com/Drekin/win-unicode-console/issues/20#issuecomment-225638271 ).

It would be nice to have this fixed. It seems to me (I may be wrong) that every occurence of `isinstance(…, str)` is a potential bug in Python 2.7. Either it should be spelled out as `isinstance(…, bytes)` or there should be `isinstance(…, types.StringTypes)` or even `isinstance(…, unicode)`.
History
Date User Action Args
2016-06-13 19:15:17Drekinsetnosy: + Drekin
messages: + msg268461
2014-02-28 16:15:57mriedemsetnosy: + mriedem
messages: + msg212456
2013-12-11 22:32:20doughellmannsetnosy: + doughellmann
2013-11-13 19:47:48ned.deilysetnosy: + georg.brandl
2013-11-13 13:51:55saschpesetmessages: + msg202749
2013-11-13 13:13:27vstinnersetnosy: + vstinner
messages: + msg202742
2013-11-13 13:11:57saschpecreate