pypa / distlib

A low-level library which implements some Python packaging standards (PEPs) and which could be used by third-party packaging tools to achieve interoperability.
http://distlib.readthedocs.io/
Other
49 stars 38 forks source link

test_interpret fails: distlib.version.UnsupportedVersionError: Not a valid version: 3.13.0a1+ #209

Closed hroncok closed 9 months ago

hroncok commented 10 months ago

Describe the bug

The tests of distlib fail with CPython built from git HEAD.

________________________ MarkersTestCase.test_interpret ________________________

self = <test_markers.MarkersTestCase testMethod=test_interpret>

    def test_interpret(self):
        sys_platform = sys.platform
        version = sys.version.split()[0]
        os_name = os.name
        platform_version = platform.version()
        platform_machine = platform.machine()
        platform_python_implementation = python_implementation()

        self.assertTrue(interpret("sys_platform == '%s'" % sys_platform))
>       self.assertTrue(interpret(
            "sys_platform == '%s' and python_full_version == '%s'" %
            (sys_platform, version)))

tests/test_markers.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
distlib/markers.py:153: in interpret
    return evaluator.evaluate(expr, context)
distlib/markers.py:83: in evaluate
    rhs = self.evaluate(erhs, context)
distlib/markers.py:86: in evaluate
    lhs = NV(lhs)
distlib/version.py:33: in __init__
    self._parts = parts = self.parse(s)
distlib/version.py:276: in parse
    result = _normalized_key(s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

s = '3.13.0a1+'

    def _pep_440_key(s):
        s = s.strip()
        m = PEP440_VERSION_RE.match(s)
        if not m:
>           raise UnsupportedVersionError('Not a valid version: %s' % s)
E           distlib.version.UnsupportedVersionError: Not a valid version: 3.13.0a1+

distlib/version.py:188: UnsupportedVersionError

I don't believe that the Python version is supposed to follow PEP 440. Not sure if this is a problem in test, or in distlib itself.

To Reproduce Steps to reproduce the behavior:

  1. Compile CPython from the main branch.
  2. The version is 3.13.0a1+
  3. Run tests of distlib
  4. See UnsupportedVersionError

Expected behavior The tests should work with CPython built from git as well as CPython releases.

Screenshots No screenshot is neccessary.

Environment

Additional information We (in Fedora) are testing various packages with pre-releases of Python. Normally we only use releases, but this time, we needed to fetch some reverts and built Python from git. This does not block us -- we will continue with 3.13.0a2 soon. But I thought this is worth reporting.

vsajip commented 10 months ago

I am away and won't be able to do any work on this myself before mid-December, but I will probably be able to review any submitted PRs before then.

vsajip commented 10 months ago

I can't reproduce this with 3.13.0a2+ with the repo version of distlib:

$ ~/projects/cpython/main/python --version
Python 3.13.0a2+
$ PYTHONHASHSEED=0 ~/projects/cpython/main/python tests/test_all.py
............................s.................................................s....s.......s........................s.ssssss..........sss...s..ss.........................s..........s..........................ssss.........ss.............
----------------------------------------------------------------------
Ran 215 tests in 26.665s

OK (skipped=25)