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.

Version matching does not conform to PEP440 when specifier sets contain pre-release versions

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

Poetry version matching doesn’t seem to conform to PEP440, specifically for specifier sets containing pre-release versions and inequality constraints.

According to https://www.python.org/dev/peps/pep-0440/#exclusive-ordered-comparison: “The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified version unless the specified version is itself a pre-release.”

From the lock file generated from the pyproject.toml file in the gist above, we have:

<snip>
tensorflow-estimator = ">=2.1.0rc0,<2.2.0"
<snip>
[[package]]
category = "main"
description = "TensorFlow Estimator."
name = "tensorflow-estimator"
optional = false
python-versions = "*"
version = "2.2.0rc0"

That is, despite the constraint “<2.2.0” we’re getting the version “2.2.0rc0”.

The issue seems to be https://github.com/python-poetry/poetry/blob/master/poetry/semver/version_range.py#L63, which doesn’t account for pre-release versions.

Incidentally, when trying to hunt down the cause of this issue I also came across https://github.com/python-poetry/poetry/blob/master/poetry/version/specifiers.py#L715, which doesn’t seem to be used but does look to have a similar issue: if any of the specifiers in the set allow prereleases, the entire set is considered to allow prereleases, which will mean that a constraint like “>=2.1.0rc0,<2.2.0” is considered to allow prereleases and will thus erroneously allow “2.2.0rc0”.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
az0uzcommented, Apr 15, 2020

I think the version constrain solver is at fault here:

from poetry.semver import parse_constraint, Version
parse_constraint("~=2.1.0").allows(Version.parse("2.2.0rc0"))

returns True It seems poetry converts parse_constraint("~=2.1.0") to >=2.1.0,<2.2.0, which I guess is wrong because then we have 2.2.0rc0 < 2.2.0 (which is true) parse_constraint("~=2.1.0") should be >=2.1.0, <2.2.0a0

2reactions
charmasaurcommented, Jan 12, 2021

Personally I don’t interpret the PEP that way. It also states The comma (",") is equivalent to a logical and operator: a candidate version must match all given version clauses in order to match the specifier as a whole., which to me suggests that the clauses are treated independently before eventually being ANDed. With that in mind, I don’t think the pre-release in one clause affects the interpretation of the other. Also, The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified version unless the specified version is itself a pre-release. seems unambiguous to me: if V is not a pre-release, then <V must not allow pre-releases of that version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 440 – Version Identification and Dependency Specification
Public version identifiers MUST be unique within a given distribution. Installation tools SHOULD ignore any public versions which do not comply with this...
Read more >
Pre-release versions are not matched by pip when using the
Summary. The pip --pre option directs pip to include potential matching pre-release and development versions, but it does not change the ...
Read more >
stable PDF - Packaging
InvalidVersion – If the version does not conform to PEP 440 in ... prerelease item SHOULD be accepted if no other versions match...
Read more >
Inter-Release Versioning Recommendations - Michael Goerz
After an in-depth reading of PEP 440 and the Semantic Versioning ... releases prior to release candidates, but this is not something I...
Read more >
Linux/Python Compatible Semantic Versioning 3.0.0
All versions have been made PEP-440 compatible, because of our deep roots in Python. Pre-release versions are now separated by . not -,...
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