Skip to content

Poetry does not handle full Python version markers correctly #2480

@cjolowicz

Description

@cjolowicz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/solverRelated to the dependency resolverkind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions