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

InvalidPyVersion raised when trying to add a coverage dependency #1111

Closed
1 task done
gtors opened this issue Jun 2, 2022 · 3 comments · Fixed by #1112
Closed
1 task done

InvalidPyVersion raised when trying to add a coverage dependency #1111

gtors opened this issue Jun 2, 2022 · 3 comments · Fixed by #1112
Labels
🐛 bug Something isn't working

Comments

@gtors
Copy link

gtors commented Jun 2, 2022

  • I have searched the issue tracker and believe that this is not a duplicate.
 pdm add coverage -vv                                                                                                                                                                                                                                                                                              [1]
Adding packages to default dependencies: coverage
======== Start resolving requirements ========
  coverage
  python>=3.10
  Adding requirement coverage
    Found matching candidates:
      <Candidate coverage 6.4.1 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.4 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.3.3 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.3.2 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.3.1 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.3 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.2 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.1.2 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.1.1 from https://pypi.org/simple/coverage/>
      <Candidate coverage 6.1 from https://pypi.org/simple/coverage/>
      ... [1435 more candidate(s)]
  Adding requirement python>=3.10
======== Starting round 0 ========
Resolving: new pin python >=3.10
======== Ending round 0 ========
======== Starting round 1 ========
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/versions.py", line 28, in __init__
    tuple(int(v) if v != "*" else v for v in version_str.split("."))[
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/versions.py", line 28, in <genexpr>
    tuple(int(v) if v != "*" else v for v in version_str.split("."))[
ValueError: invalid literal for int() with base 10: '0a6'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.local/bin/pdm", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.10/site-packages/pdm/core.py", line 232, in main
    return Core().main(args)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/core.py", line 167, in main
    raise cast(Exception, err).with_traceback(traceback)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/core.py", line 162, in main
    f(options.project, options)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/cli/commands/add.py", line 55, in handle
    actions.do_add(
  File "/home/user/.local/lib/python3.10/site-packages/pdm/cli/actions.py", line 256, in do_add
    resolved = do_lock(project, strategy, tracked_names, reqs, dry_run=dry_run)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/cli/actions.py", line 95, in do_lock
    mapping, dependencies = resolve(
  File "/home/user/.local/lib/python3.10/site-packages/pdm/resolver/core.py", line 31, in resolve
    result = resolver.resolve(requirements, max_rounds)
  File "/home/user/.local/lib/python3.10/site-packages/resolvelib/resolvers.py", line 481, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/home/user/.local/lib/python3.10/site-packages/resolvelib/resolvers.py", line 373, in resolve
    failure_causes = self._attempt_to_pin_criterion(name)
  File "/home/user/.local/lib/python3.10/site-packages/resolvelib/resolvers.py", line 213, in _attempt_to_pin_criterion
    criteria = self._get_updated_criteria(candidate)
  File "/home/user/.local/lib/python3.10/site-packages/resolvelib/resolvers.py", line 203, in _get_updated_criteria
    for requirement in self._p.get_dependencies(candidate=candidate):
  File "/home/user/.local/lib/python3.10/site-packages/pdm/resolver/providers.py", line 172, in get_dependencies
    deps, requires_python, _ = self.repository.get_dependencies(candidate)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/repositories.py", line 70, in get_dependencies
    requirements, requires_python, summary = getter(candidate)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/repositories.py", line 35, in wrapper
    result = func(self, candidate)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/repositories.py", line 190, in _get_dependencies_from_metadata
    deps = prepared.get_dependencies_from_metadata()
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/candidates.py", line 426, in get_dependencies_from_metadata
    return filter_requirements_with_extras(
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/requirements.py", line 455, in filter_requirements_with_extras
    _r = parse_requirement(req)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/requirements.py", line 488, in parse_requirement
    r = Requirement.from_pkg_requirement(package_req)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/requirements.py", line 252, in from_pkg_requirement
    return NamedRequirement(**kwargs)  # type: ignore
  File "<string>", line 9, in __init__
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/requirements.py", line 87, in __post_init__
    self.marker.split_pyspec()[1] if self.marker else PySpecSet()
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/markers.py", line 48, in split_pyspec
    return marker, _build_pyspec_from_marker(join_list_with(py_markers, "and"))
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/markers.py", line 156, in _build_pyspec_from_marker
    pyspec = PySpecSet(f"{op}{version}")
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/specifiers.py", line 69, in __init__
    self._analyze_specifiers()
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/specifiers.py", line 77, in _analyze_specifiers
    op, version = _normalize_op_specifier(spec.operator, spec.version)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/specifiers.py", line 28, in _normalize_op_specifier
    version = Version(version_str)
  File "/home/user/.local/lib/python3.10/site-packages/pdm/models/versions.py", line 33, in __init__
    raise InvalidPyVersion(
pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Steps to reproduce

pdm add "coverage==6.4.1"

Actual behavior

InvalidPyVersion raised

Expected behavior

The dependency was successfully added without errors

Environment Information

PDM version:        1.15.0
Python Interpreter: /usr/bin/python3 (3.10)
Project Root:       /home/user/.src/project
Project Packages:   /home/user/.src/project/__pypackages__/3.10
{
  "implementation_name": "cpython",
  "implementation_version": "3.10.4",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.17.9-1-MANJARO",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT Wed May 18 09:20:53 UTC 2022",
  "python_full_version": "3.10.4",
  "platform_python_implementation": "CPython",
  "python_version": "3.10",
  "sys_platform": "linux"
}
@gtors gtors added the 🐛 bug Something isn't working label Jun 2, 2022
@Hnasar
Copy link
Contributor

Hnasar commented Jun 2, 2022

We also started seeing these errors today in our CI jobs. I can't tell yet which project it is from though 🤔

From 621 metadata it sounds like prerelease versions should be valid.

@Hnasar
Copy link
Contributor

Hnasar commented Jun 2, 2022

Ours was also due to coverage 6.4.1 which now specifies in setup.py:

    extras_require={
        # Enable pyproject.toml support.
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

This was done do resolve nedbat/coveragepy#1390

Hnasar pushed a commit to Hnasar/pdm that referenced this issue Jun 2, 2022
Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes pdm-project#1111
@Hnasar
Copy link
Contributor

Hnasar commented Jun 3, 2022

I added a pull request which fixes the issue. Until its merged, as a workaround, you can add

    "coverage<6.4",        # Needed until the fix is merged for
    "coverage[toml]<6.4",  # https://github.com/pdm-project/pdm/issues/1111

to pyproject.toml to avoid the coverage version which triggers this bug.

Hnasar pushed a commit to Hnasar/pdm that referenced this issue Jun 3, 2022
Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes pdm-project#1111
Hnasar pushed a commit to Hnasar/pdm that referenced this issue Jun 3, 2022
Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes pdm-project#1111
frostming pushed a commit that referenced this issue Jun 3, 2022
…1112)

* Fix crash if dependencies have prerelease requires-python versions

Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes #1111

* Remove workaround for pre-release python in global environment

Since prereleases are now supported in python specifiers (in the
previous commit), we can remove the workaround (from commit 8e72609
for #932) that converted a python prerelease version to a specifier
range.

Co-authored-by: Hashem Nasarat <hnasarat@beta.team>
ChrisSanderser added a commit to ChrisSanderser/pd-ms that referenced this issue Jul 15, 2022
…1112)

* Fix crash if dependencies have prerelease requires-python versions

Recently, coverage 6.4.1 listed its requirements with an alpha version of
python and this broke PDM's version parsing:

    extras_require={
        'toml': ['tomli; python_full_version<="3.11.0a6"'],
    },

Prerelease `requires-python` versions *are* valid, per these specifications:

* https://peps.python.org/pep-0440/
* https://peps.python.org/pep-0621/#requires-python
* https://packaging.python.org/en/latest/specifications/core-metadata/#requires-python

Therefore this commit adds missing parsing support for `{a|b|rc}[N]`
pre-release specifiers which are used by python language releases:

* https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work

This bug meant that projects that directly or indirectly depended on coverage
were unable to update pdm.lock using commands like `update` `add` `lock` and
`install` because `pdm.models.versions.Version` would raise:

    pdm.exceptions.InvalidPyVersion: 3.11.0a6: Prereleases or postreleases are not supported for python version specifers.

Until this is fixed, projects can workaround this by depending on:

    "coverage<6.4",
    "coverage[toml]<6.4",

Fixes pdm-project/pdm#1111

* Remove workaround for pre-release python in global environment

Since prereleases are now supported in python specifiers (in the
previous commit), we can remove the workaround (from commit 8e7260968ac
for #932) that converted a python prerelease version to a specifier
range.

Co-authored-by: Hashem Nasarat <hnasarat@beta.team>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants