Python Interpreter generated by buildout does not support -V option

Bug #1641983 reported by Eric Lapouyade
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Buildout
New
Undecided
Unassigned

Bug Description

For the python interpreter generated by buildout, that is, when you specify in buildout.cfg :

    ...
    [eggs]
    recipe = zc.recipe.egg
    eggs =
        ${buildout:eggs}
    extra-paths =
        ${buildout:directory}
        ${buildout:directory}/../../bin/pycharm/helpers
    interpreter = python

it does not recognize the -V option:

    $ <myproject>/bin/python -V
    Traceback (most recent call last):
      File "bin/python", line 87, in <module>
        _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
      File "/usr/lib/python2.7/getopt.py", line 90, in getopt
        opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
      File "/usr/lib/python2.7/getopt.py", line 190, in do_shorts
        if short_has_arg(opt, shortopts):
      File "/usr/lib/python2.7/getopt.py", line 206, in short_has_arg
        raise GetoptError('option -%s not recognized' % opt, opt)
    getopt.GetoptError: option -V not recognized

A normal behaviour should be :

    # /usr/bin/python -V
    Python 2.7.5

This is normal because buildout generated an interpreter that does not include detection of -V option, one can see within the interpreter script:

    _interactive = True
    if len(sys.argv) > 1:
        _options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
        _interactive = False
        for (_opt, _val) in _options:
            if _opt == '-i':
                _interactive = True
            elif _opt == '-c':
                exec(_val)
            elif _opt == '-m':
                sys.argv[1:] = _args
                _args = []
                __import__("runpy").run_module(
                     _val, {}, "__main__", alter_sys=True)

The suggested fix is (buildout/easy_install.py) :

    _interactive = True
    if len(sys.argv) > 1:
        _options, _args = __import__("getopt").getopt(sys.argv[1:], 'Vic:m:')
        _interactive = False
        for (_opt, _val) in _options:
            if _opt == '-i':
                _interactive = True
            elif _opt == '-c':
                exec(_val)
            elif _opt == '-V':
                print sys.version.split(' ', 1)[0]
                exit()
            elif _opt == '-m':
                sys.argv[1:] = _args
                _args = []
                __import__("runpy").run_module(
                     _val, {}, "__main__", alter_sys=True)

Note : the '-V' option is mandatory to get PyCharm IDE fully working as it must detect python version to make a correct syntax coloring.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.