Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to handle "Python 3.11.0+" (packaging.version.InvalidVersion) #12

Closed
blueyed opened this issue Nov 10, 2022 · 2 comments
Closed

Comments

@blueyed
Copy link

blueyed commented Nov 10, 2022

With the output from a local build packaging fails to parse the version:

>>> from packaging.version import Version
>>> Version('3.11.0+')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "…/.venv/lib/python3.11/site-packages/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '3.11.0+'
% python --version
Python 3.11.0+
% python --version --version
Python 3.11.0+ (heads/3.11:7c9c993945, Nov 10 2022, 10:26:35) [GCC 12.2.0]

This likely causes pdm to not detect this Python from the actually used venv, and also causes an error with pdm config:

…
Project configuration (…/.pdm.toml):
Traceback (most recent call last):
  File "…/project/.venv/bin/pdm", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/core.py", line 258, in main
    return Core().main(args)
           ^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/core.py", line 204, in main
    check_update(project)
  File "…/project/.venv/lib/python3.11/site-packages/pdm/cli/actions.py", line 868, in check_update
    latest_version = get_latest_version(project)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/cli/actions.py", line 854, in get_latest_version
    latest_version = get_latest_pdm_version_from_pypi(project)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/cli/actions.py", line 836, in get_latest_pdm_version_from_pypi
    with environment.get_finder([project.default_source]) as finder:
  File "/home/user/.local/opt/python/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/models/environment.py", line 160, in get_finder
    target_python=self.target_python,
                  ^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/opt/python/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/models/environment.py", line 116, in target_python
    python_version = self.interpreter.version_tuple
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/models/python.py", line 64, in version_tuple
    return (self.major, self.minor, self.micro)
            ^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/pdm/models/python.py", line 52, in major
    return self._py_ver.major
           ^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/findpython/python.py", line 71, in major
    return self.version.major
           ^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/findpython/python.py", line 65, in version
    self._version = self._get_version()
                    ^^^^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/findpython/python.py", line 165, in _get_version
    return Version(version)
           ^^^^^^^^^^^^^^^^
  File "…/project/.venv/lib/python3.11/site-packages/packaging/version.py", line 266, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: '3.11.0+'

I am not sure this is a bug with packaging / if it should handle it better, but certainly causes issues here.

@frostming
Copy link
Owner

Why does the locally built python doesn't have local tag? It is considered invalid by packaging

@ssbarnea
Copy link

@frostming I tested locally and the fix works fine. Thanks a lot for the very quick fix!

Adirelle pushed a commit to Adirelle/findpython that referenced this issue Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants