• Kirill Smelkov's avatar
    gpython: Fix -V when underlying python is not exactly release · f8761f73
    Kirill Smelkov authored
    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 nexedi/pygolang!23
    f8761f73
__init__.py 19.9 KB