[issue152] setuptools breaks with from __future__ import unicode_literals in setup.py
![](https://secure.gravatar.com/avatar/b6b8d66de135cfb887e5e02b543cf3d7.jpg?s=120&d=mm&r=g)
New submission from mbogosian: unicode_literals break a bunch of stuff in setuptools. Considering they may become the default at some point, this should be fixed...? I do not know if this is related to issue 78. To reproduce, run the attached setup.py (output below). Comment out the unicode_literals line in setup.py and try it again (everything should work). % DISTUTILS_DEBUG=t python -c 'import setuptools ; print setuptools.__version__' 0.8 % unzip -d foo_test.zip ; cd foo_test ... % DISTUTILS_DEBUG=t python setup.py build options (after parsing config files): options (after parsing command line): option dict for 'aliases' command: {} option dict for 'build' command: {} option dict for 'nosetests' command: {'all_modules': ('setup.cfg', '1'), 'cover_package': ('setup.cfg', 'foo'), 'detailed_errors': ('setup.cfg', '1'), 'verbosity': ('setup.cfg', '2'), 'with_coverage': ('setup.cfg', '1'), 'with_doctest': ('setup.cfg', '1')} running build Distribution.get_command_obj(): creating 'build' command object running build_py Distribution.get_command_obj(): creating 'build_py' command object Traceback (most recent call last): File "setup.py", line 58, in <module> setuptools.setup(**_SETUP_ARGS) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup dist.run_commands() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command cmd_obj.run() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run self.run_command(cmd_name) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command self.distribution.run_command(command) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command cmd_obj.run() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/command/build_py.py", line 89, in run self.build_packages() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_py.py", line 372, in build_packages self.build_module(module, module_file, package) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/command/build_py.py", line 106, in build_module outfile, copied = _build_py.build_module(self, module, module_file, package) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_py.py", line 333, in build_module "'package' must be a string (dot-separated), list, or tuple") TypeError: 'package' must be a string (dot-separated), list, or tuple % DISTUTILS_DEBUG=t python setup.py nosetests options (after parsing config files): options (after parsing command line): option dict for 'aliases' command: {} option dict for 'nosetests' command: {'all_modules': ('setup.cfg', '1'), 'cover_package': ('setup.cfg', 'foo'), 'detailed_errors': ('setup.cfg', '1'), 'verbosity': ('setup.cfg', '2'), 'with_coverage': ('setup.cfg', '1'), 'with_doctest': ('setup.cfg', '1')} running nosetests Distribution.get_command_obj(): creating 'nosetests' command object setting options for 'nosetests' command: with_coverage = 1 (from setup.cfg) verbosity = 2 (from setup.cfg) cover_package = foo (from setup.cfg) all_modules = 1 (from setup.cfg) with_doctest = 1 (from setup.cfg) detailed_errors = 1 (from setup.cfg) running egg_info Distribution.get_command_obj(): creating 'egg_info' command object Traceback (most recent call last): File "setup.py", line 58, in <module> setuptools.setup(**_SETUP_ARGS) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup dist.run_commands() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command cmd_obj.run() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/commands.py", line 132, in run self.run_command('egg_info') File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command self.distribution.run_command(command) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 971, in run_command cmd_obj.ensure_finalized() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized self.finalize_options() File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 103, in finalize_options self.ensure_dirname('egg_base') File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 269, in ensure_dirname "'%s' does not exist or is not a directory") File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 255, in _ensure_tested_string val = self._ensure_stringlike(option, what, default) File ".../Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 216, in _ensure_stringlike "'%s' must be a %s (got `%s`)" % (option, what, val) distutils.errors.DistutilsOptionError: 'egg_base' must be a directory name (got `src`) % ... # Comment out unicode_literals line in setup.py % python setup.py nosetests running nosetests running egg_info writing src/foo.egg-info/PKG-INFO writing namespace_packages to src/foo.egg-info/namespace_packages.txt writing top-level names to src/foo.egg-info/top_level.txt writing dependency_links to src/foo.egg-info/dependency_links.txt reading manifest file 'src/foo.egg-info/SOURCES.txt' writing manifest file 'src/foo.egg-info/SOURCES.txt' running build_ext Doctest: foo.base.pity.Foo ... ok testFoo (test.base.pity.TestFoo) ... ok Name Stmts Miss Cover Missing --------------------------------------------- foo 3 0 100% foo.base 0 0 100% foo.base.pity 9 0 100% --------------------------------------------- TOTAL 12 0 100% ---------------------------------------------------------------------- Ran 2 tests in 0.034s OK ---------- files: foo_test.zip messages: 724 nosy: mbogosian priority: bug status: unread title: setuptools breaks with from __future__ import unicode_literals in setup.py Added file: http://bugs.python.org/setuptools/file92/foo_test.zip _______________________________________________ Setuptools tracker <setuptools@bugs.python.org> <http://bugs.python.org/setuptools/issue152> _______________________________________________
![](https://secure.gravatar.com/avatar/7a9c1d88f484c9806bceca0d6d91e948.jpg?s=120&d=mm&r=g)
On Sat, Jul 06, 2013 at 06:52:05AM +0000, mbogosian wrote:
New submission from mbogosian:
unicode_literals break a bunch of stuff in setuptools. Considering they may become the default at some point, this should be fixed...? I do not know if this is related to issue 78.
To reproduce, run the attached setup.py (output below). Comment out the unicode_literals line in setup.py and try it again (everything should work).
% DISTUTILS_DEBUG=t python -c 'import setuptools ; print setuptools.__version__' 0.8 % unzip -d foo_test.zip ; cd foo_test ... % DISTUTILS_DEBUG=t python setup.py build
[snip output]
% DISTUTILS_DEBUG=t python setup.py nosetests [snip output]
Not sure what the unicode model is in setuptools but one way to look at this is that in python2, the setuptools API takes byte str and in python3, the API takes unicode str. So this is a case of the setup.py being invalid. If you have: from __future__ import unicode_literals That doesn't change what the api takes as input; it only changes how you express it. So a package author who does from __future__ import unicode_literals would also need to do this to make things work: 'package_dir' : { '': b'src' }, 'packages' : setuptools.find_packages(b'src', exclude = ( b'foo', b'test', b'test.*' )), Someone else will have to speak to whether that's the intended model, though. -Toshio
![](https://secure.gravatar.com/avatar/7094252405dd3dd5f798b132834d39b2.jpg?s=120&d=mm&r=g)
mbogosian <setuptools <at> bugs.python.org> writes:
unicode_literals break a bunch of stuff in setuptools. Considering they may become the default at some point, this should be fixed...? I do not know if this is related to issue 78.
These appear to be because distutils (not setuptools) is unduly restrictive, refusing to accept unicode when it could do so.
".../lib/python2.7/distutils/command/build_py.py",
line 333, in build_module "'package' must be a string (dot-separated), list, or tuple") TypeError: 'package' must be a string (dot-separated), list, or tuple
distutils code is testing for str (as opposed to list/tuple), but it could as well test for basestring here.
File ".../lib/python2.7/distutils/cmd.py", line 216, in _ensure_stringlike "'%s' must be a %s (got `%s`)" % (option, what, val) distutils.errors.DistutilsOptionError: 'egg_base' must be a directory name (got `src`)
Again, this is in distutils. It seems as if testing for basestring rather than str would be needed. There could well be other places in distutils where it's testing for str where basestring would do, but I'm not sure whether these would be regarded as bugs for 2.7. Regards, Vinay Sajip
participants (3)
-
mbogosian
-
Toshio Kuratomi
-
Vinay Sajip