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

Poetry does not handle full Python version markers correctly #2480

Closed
cjolowicz opened this issue May 31, 2020 · 3 comments
Closed

Poetry does not handle full Python version markers correctly #2480

cjolowicz opened this issue May 31, 2020 · 3 comments
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected

Comments

@cjolowicz
Copy link

Poetry does not install dependencies into an environment if the dependency has a marker with a full three-digit Python version, even though the environment matches the marker.

For example, the pyproject.toml below is for a project requiring Python 3.6.1 and higher. It also uses the backport of dataclasses to Python 3.6.

(This is not an uncommon situation. Packages like pre-commit explicitly exclude 3.6.0 due to a broken NamedTuple implementation. If such packages are added as dependency, our package also needs to exclude it.)

[tool.poetry]
name = "example"
version = "0.1.0"
description = ""
authors = ["user <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.6.1"
dataclasses = {version = "^0.7", python = ">= 3.6.1, < 3.7"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

If we create an environment with the latest Python 3.6, dataclasses is not installed:

$ poetry env use 3.6
Creating virtualenv example-TsH6FKJq-py3.6 in ~/Library/Caches/pypoetry/virtualenvs
Using virtualenv: ~/Library/Caches/pypoetry/virtualenvs/example-TsH6FKJq-py3.6

$ poetry run python -V
Python 3.6.10

$ poetry run pip freeze | grep dataclasses

$ poetry export --format=requirements.txt | grep dataclasses
dataclasses==0.7; python_version >= "3.6.1" and python_version < "3.7" \

Note that the generated requirements.txt is invalid. The python_version marker cannot contain the full three-digit version. Instead python_full_version should be used. See PEP 508.

@finswimmer finswimmer added kind/bug Something isn't working as expected area/solver Related to the dependency resolver status/triage This issue needs to be triaged labels Jun 2, 2020
@RauliRuohonen
Copy link

[...] if the dependency has a marker with a full three-digit Python version [...]

The python_version marker cannot contain the full three-digit version. Instead python_full_version should be used.

This focuses on three-digit versions, but the requirements.txt issue at least can occur with two-digit versions as well:

pyenv local 3.6.1
poetry new foo
cd foo
perl -pe 's/python = "\^3.6"/python = "~3.6.1"/' -i pyproject.toml
poetry add fsspec==0.8.4
poetry export -f requirements.txt -o requirements.txt
pip install -r requirements.txt

says

Ignoring fsspec: markers 'python_version > "3.6"' don't match your environment

This is wrong, even though the requirement python_version > "3.6" has only a two-digit version number in it. The reason is the strict comparison: it basically says "the next version after 3.6 or newer", but "the next version" is different for python_version (3.7) and python_full_version (3.6.1). The latter is what is meant, but not what is said.

The original requirement for fsspec 0.8.4 is Requires-Python: >3.6 in its METADATA file. Although this has two digits, it's basically the same thing as >=3.6.1: if you run pip install fsspec==0.8.4 on Python 3.6.0 it fails, but on 3.6.1 it works. Since >3.6 is basically the same requirement as >=3.6.1, it has the same problem: a python_version constraint cannot express it.

Using python_full_version fixes this, too.

@dimbleby
Copy link
Contributor

results of export today for the two cases described are

dataclasses==0.7 ; python_full_version >= "3.6.1" and python_version < "3.7"

and

fsspec==0.8.4 ; python_full_version >= "3.6.1" and python_full_version < "3.7.0"

which both use python_full_version as desired.

@Secrus Secrus closed this as completed Aug 27, 2022
@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Sep 18, 2022
Copy link

github-actions bot commented Mar 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

6 participants