question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tilde requirements vs PEP 440 compatible release

See original GitHub issue

https://python-poetry.org/docs/versions/#tilde-requirements https://www.python.org/dev/peps/pep-0440/#compatible-release

PEP 440 describes the use of ~ in version specifiers. Imprecisely, it treats the version given as the minimum version, and treats the final segment of the version specifier as a *.

This is notably different than ^ in Poetry and other languages’ package managers (caret requirements are not in PEP440), which treats the version given as the minimum version, and treats all segments after the first as a *.

I expect that for many people, if they are wishing to use only PEP440 version specifiers for some reason, that compatible releases might be just the thing to use.

Unfortunately, it appears that Poetry either has a documentation bug, or has a behavior with this version specifier that is incompatible with PEP 440. The Poetry documentation for tilde requirements gives three examples, two of which are not compatible with PEP 440 compatible release. Compare what PEP 440 says to what the Poetry docs say, to what the docs should say if using the same format to match the meaning of PEP 440.

requirement PEP 440 says Poetry docs say Poetry docs should say
~1.2.3 >=1.2.3,1.2.* >=1.2.3 <1.3.0 >=1.2.3 <1.3.0
~1.2 >=1.2,1.* >=1.2.0 <1.3.0 >=1.2.3 <2
~1 invalid >=1.0.0 <2.0.0 ?

For many cases, including my own, I expect that people will want a version specifier that is like PEP 440’s ~1.2 meaning, but to get (almost) that with Poetry they have to use ~1, which is an explicitly invalid specifier under PEP 440. I think that Poetry should match PEP 440’s version specifier’s meaning.

Poetry might prefer to assign a valid meaning to the ~1 version, although I think I’d prefer to follow PEP 440 there as well and throw an error, but having valid PEP 440 specifiers do (or document) something other than what PEP 440 instructs seems very unwise.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
andriisoldatenkocommented, Aug 17, 2021

I see maybe same/or other issue with poetry==1.2.0a2:

poetry add pyjwt
Using version ^2.1.0 for PyJWT


  InvalidVersion

  Invalid PEP 440 version: '3.6.'

  at ~/.pyenv/versions/3.9.5/envs/internal-transaction-tagger-lib-python/lib/python3.9/site-packages/poetry/core/version/pep440/parser.py:67 in parse
       63│     @classmethod
       64│     def parse(cls, value: str, version_class: Optional[Type["PEP440Version"]] = None):
       65│         match = cls._regex.search(value) if value else None
       66│         if not match:
    →  67│             raise InvalidVersion(f"Invalid PEP 440 version: '{value}'")
       68│
       69│         if version_class is None:
       70│             from poetry.core.version.pep440.version import PEP440Version
       71│

The following error occurred when trying to handle this error:


  ValueError

  Could not parse version constraint: >=3.6.*

  at ~/.pyenv/versions/3.9.5/envs/internal-transaction-tagger-lib-python/lib/python3.9/site-packages/poetry/core/semver/helpers.py:139 in parse_single_constraint
      135│
      136│         try:
      137│             version = Version.parse(version)
      138│         except ValueError:
    → 139│             raise ValueError(
      140│                 "Could not parse version constraint: {}".format(constraint)
      141│             )
      142│
      143│         if op == "<":
0reactions
ryanhiebertcommented, Nov 6, 2022

@dimbleby: You are right, although there was a documentation issue brought up that appears to be rectified now.

@pbhuss: Thank you for your work on that comment, very effectively demonstrating my confusion. The documentation issue you pointed out in your comment appears to be fixed up.

I could appreciate some additional language clarifying that is is not the same as PEP 440’s ~= operator, and that ~= does work. Still, my OP was ultimately invalid and confused.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 440 – Version Identification and Dependency Specification
Local version identifiers SHOULD be used by downstream projects when releasing a version that is API compatible with the version of the upstream...
Read more >
In requirements.txt, what does tilde equals (~=) mean?
A compatible release clause consists of the compatible release operator ~= and a version identifier. It matches any candidate version that is expected...
Read more >
Dependency specification | Documentation | Poetry - Python ...
Tilde requirements specify a minimal version with some ability to update. If you specify a major, minor, and patch version or only a...
Read more >
Should You Use Upper Bound Version Constraints?
In this discussion I would like to explain why always providing an upper limit causes far more harm than good even for true...
Read more >
Specifying Your Project's Version - Setuptools
c1 and 2.4-c1 all represent release candidate 1 of version 2.4 , and are treated as identical by setuptools. Note that only a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found