This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients jaraco
Date 2013-09-05.20:03:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1378411388.86.0.748005801735.issue18936@psf.upfronthosting.co.za>
In-reply-to
Content
Today I encountered a bug where I was using a Distutils.Command subclass, which uses getopt for option parsing. The implementation is here: https://bitbucket.org/jaraco/jaraco.packaging/src/2.2/jaraco/packaging/depends.py?at=default

Around line 59, the options are defined, but because the syntax is Python 3 style with unicode literals, under Python 2.7, those get created as unicode objects.

When I invoke that Command under Python 2.7, I get this error:

Traceback (most recent call last):
  File "setup.py", line 160, in <module>
    setup(**setup_params)
  File "/usr/lib/python2.7/distutils/core.py", line 138, in setup
    ok = dist.parse_command_line()
  File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 250, in parse_command_line
  File "/usr/lib/python2.7/distutils/dist.py", line 467, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 533, in _parse_command_opts
  File "/usr/lib/python2.7/distutils/dist.py", line 564, in _parse_command_opts
    (args, opts) = parser.getopt(args[1:])
  File "/usr/lib/python2.7/distutils/fancy_getopt.py", line 253, in getopt
    self._grok_option_table()
  File "/usr/lib/python2.7/distutils/fancy_getopt.py", line 171, in _grok_option_table
    "must be a string of length >= 2") % long
distutils.errors.DistutilsGetoptError: invalid long option 'requirement=': must be a string of length >= 2

That error is raised because 'requirement=' is a Unicode, but the test in fancy_getopt is isinstance(opt, str).

I can work around the issue by wrapping all of the options in str() calls, which leaves them unchanged on Python 3 and downcasts them to strings on Python 2, but that's not pretty.

I suggest that fancy_getopt should either include 'unicode' in the isinstance test or (if unicode values really aren't supported), encode unicode values first.
History
Date User Action Args
2013-09-05 20:03:08jaracosetrecipients: + jaraco
2013-09-05 20:03:08jaracosetmessageid: <1378411388.86.0.748005801735.issue18936@psf.upfronthosting.co.za>
2013-09-05 20:03:08jaracolinkissue18936 messages
2013-09-05 20:03:08jaracocreate