Commit f8761f73 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Fix -V when underlying python is not exactly release

When python is built from git checkout, not exactly on any tag state, it
adds a "+" sign as suffix to its version, for example:

    (py312.venv) kirr@deca:~/src/tools/go/pygolang$ python -V
    Python 3.12.2+

    (py312.venv) kirr@deca:~/src/tools/go/pygolang$ python
    Python 3.12.2+ (heads/3.12:0e4f73b8e45, Feb 15 2024, 10:52:08) [GCC 12.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

but our handler for -V was trying to construct the version from
sys.version_info where there is no information about that "extra" part:

    In [2]: sys.version_info
    Out[2]: sys.version_info(major=3, minor=12, micro=2, releaselevel='final', serial=0)	# no +

    In [4]: platform.python_version()
    Out[4]: '3.12.2+'

as the result test_pymain_ver is failing:

    =================== FAILURES ===================
    ______________ test_pymain_ver[] _______________

    runtime = ''

        @gpython_only
        def test_pymain_ver(runtime):
            from golang import b
            from gpython import _version_info_str as V
            import gevent
            vok = 'GPython %s' % golang.__version__
            if runtime != 'threads':
                vok += ' [gevent %s]' % gevent.__version__
            else:
                vok += ' [threads]'

            if is_cpython:
                vok += ' / CPython %s' % platform.python_version()
            elif is_pypy:
                vok += ' / PyPy %s / Python %s' % (V(sys.pypy_version_info), V(sys.version_info))
            else:
                vok = sys.version

            vok += '\n'

            ret, out, err = _pyrun(['-V'], stdout=PIPE, stderr=PIPE, env=gpyenv(runtime))
    >       assert (ret, out, b(err)) == (0, b'', b(vok))
    E       AssertionError: assert (0, b'', b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2\n') == (0, b'', b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2+\n')
    E         At index 2 diff: b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2\n' != b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2+\n'
    E         Full diff:
    E         - (0, b'', b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2+\n')
    E         ?                                                        -
    E         + (0, b'', b'GPython 0.1 [gevent 24.2.1] / CPython 3.12.2\n')

    gpython/gpython_test.py:341: AssertionError

-> Fix it by handling -V with platform.python_version() directly.

/reviewed-by @jerome
/reviewed-on !23
parent 74a9838c
......@@ -239,11 +239,12 @@ def pymain(argv, init=None):
pyimpl = platform.python_implementation()
v = _version_info_str
pyver = platform.python_version() # ~ v(sys.version_info) but might also have e.g. '+' at tail
if pyimpl == 'CPython':
ver.append('CPython %s' % v(sys.version_info))
ver.append('CPython %s' % pyver)
elif pyimpl == 'PyPy':
ver.append('PyPy %s' % v(sys.pypy_version_info))
ver.append('Python %s' % v(sys.version_info))
ver.append('Python %s' % pyver)
else:
ver = [] # unknown
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment