pip icon indicating copy to clipboard operation
pip copied to clipboard

pip does not work with development versions of CPython due to parse error on version string

Open tacaswell opened this issue 1 year ago • 6 comments

Description

The version string of development versions of CPython end with +, e.g. 3.12.3+ which causes errors in pip.

caused by #12300

Expected behavior

pip accepts the version string on the development versions of CPython.

pip version

approximately current main branch

Python version

3.12.3+ (the 3.12 branch)

OS

arch

How to Reproduce

  1. install development version of CPython from 3.12 branch (but I suspect any of the 3.X branches will show this)
  2. install a from a branch of pip that contains 47a8480065d4eac252edb3673cfaecccb7dbf3c2
  3. try to install anything that specifies python versions (in my case it was build)

Output

(bleeding) ~/s/p/p/build main|✓
✘ 13:41:38 [belanna] @ pip install . --no-build-isolation
Processing /home/tcaswell/source/p/pypa/build
  Preparing metadata (pyproject.toml) ... done
ERROR: Exception:
Traceback (most recent call last):
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 180, in exc_logging_wrapper
    status = run_func(*args)
             ^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 377, in run
    requirement_set = resolver.resolve(
                      ^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 95, in resolve
    result = self._result = resolver.resolve(
                            ^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 427, in resolve
    failure_causes = self._attempt_to_pin_criterion(name)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 239, in _attempt_to_pin_criterion
    criteria = self._get_updated_criteria(candidate)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/resolvelib/resolvers.py", line 229, in _get_updated_criteria
    for requirement in self._p.get_dependencies(candidate=candidate):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/provider.py", line 247, in get_dependencies
    return [r for r in candidate.iter_dependencies(with_requires) if r is not None]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 243, in iter_dependencies
    for r in requires:
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_internal/metadata/importlib/_dists.py", line 222, in iter_dependencies
    elif not extras and req.marker.evaluate({"extra": ""}):
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py", line 252, in evaluate
    return _evaluate_markers(self._markers, current_environment)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py", line 158, in _evaluate_markers
    groups[-1].append(_eval_op(lhs_value, op, rhs_value))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/markers.py", line 116, in _eval_op
    return spec.contains(lhs, prereleases=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/specifiers.py", line 568, in contains
    normalized_item = _coerce_version(item)
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/specifiers.py", line 36, in _coerce_version
    version = Version(version)
              ^^^^^^^^^^^^^^^^
  File "/home/tcaswell/.virtualenvs/bleeding/lib/python3.12/site-packages/pip/_vendor/packaging/version.py", line 200, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
pip._vendor.packaging.version.InvalidVersion: Invalid version: '3.12.3+'

Code of Conduct

tacaswell avatar May 10 '24 17:05 tacaswell

@tacaswell do you have a dependency with a python_full_version environment marker ?

sbidoul avatar May 11 '24 12:05 sbidoul

https://github.com/pypa/packaging/issues/678#issuecomment-1436033646

pradyunsg avatar May 11 '24 15:05 pradyunsg

Is this considered a blocker for pip 24.1?

uv has taken the approach of fixing up versions that are not PEP 440 compliant, in particular this is how they handle python_full_version: https://github.com/astral-sh/uv/pull/1771/files

Might it be worth applying the same on pip side for python_full_version specifically?

notatallshaw avatar May 18 '24 13:05 notatallshaw

I have proposed https://github.com/pypa/packaging/pull/802 to fix this.

sbidoul avatar May 19 '24 10:05 sbidoul

hello, I'm apparently maybe by this also in a constraint file:

ERROR: Invalid requirement: 'python-hdf4>=0.10.0+dummy' (from line 436 of ...\constraints.txt)

is this the same bug ? and solution ?

stonebig avatar May 20 '24 09:05 stonebig

@stonebig this is another issue:

InvalidRequirement: Local version label can only be used with `==` or `!=` operators
    python-hdf4>=0.10.0+dummy
               ~~~~~~~~^

Pip should show the detailed error, though.

sbidoul avatar May 20 '24 09:05 sbidoul