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

The poetry export (and maybe lock) command does not handle dependencies with "bifurcated requirements". #4381

Closed
3 tasks done
jsirois opened this issue Aug 13, 2021 · 2 comments
Labels
kind/bug Something isn't working as expected

Comments

@jsirois
Copy link

jsirois commented Aug 13, 2021

  • 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).

(No exception occurs re the last checkbox question)

  • OS version and name: Arch Linux kernel version 5.13.9-arch1-1
  • Poetry version: 1.1.7

Issue

The poetry export command produces an incorrect requirements-style lock file when interior dependency nodes contain "bifurcated requirements". By "bifurcated requirements" (my made up terminology), I mean Requires-Dist metadata like so:

$ unzip -qc dist/project1-0.1.0-py2.py3-none-any.whl project1-0.1.0.dist-info/METADATA | grep Requires-Dist
Requires-Dist: pytest (==4.6.11); python_version == "2.7" or python_version == "3.5"
Requires-Dist: pytest (==6.2.4); python_version >= "3.6" and python_version < "3.10"

In particular the exported requirements are:

$ poetry export | grep -A4 pytest
pytest==6.2.4; python_version >= "3.6" and python_version < "3.10" and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b

Instead of the expected:

pytest==4.6.11; python_version == "2.7" or python_version == "3.5" \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b
pytest==6.2.4; python_version >= "3.6" and python_version < "3.10" \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b

This issue also appears to affect the poetry.lock file itself so I suspect the issue isn't in the export code, but in the code that generates the lock itself.

Below are the command line details of my experiment. Note that Poetry does get this right when the "bifurcated requirements" are present in the top-level Poetry managed project's pyproject.toml. The failure to generate a correct lock only occurs for interior nodes in the resolve.

1st I create a project (poject1) that uses "bifurcated requirements" and everything works as expected:

^jsirois@gill /tmp/poetry-tests/project1 $ ls -l
total 4
-rw-r--r-- 1 jsirois jsirois   0 Aug 13 10:08 project1.py
-rw-r--r-- 1 jsirois jsirois 521 Aug 13 10:06 pyproject.toml
^jsirois@gill /tmp/poetry-tests/project1 $ cat pyproject.toml 
[tool.poetry]
name = "project1"
version = "0.1.0"
description = ""
authors = ["John Sirois <[email protected]>"]

[tool.poetry.dependencies]
python = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.10"
pytest = [
  {version = "4.6.11", markers = "python_version == '2.7' or python_version == '3.5'"},
  {version = "6.2.4", markers = "python_version >= '3.6' and python_version < '3.10'"},
]

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
^jsirois@gill /tmp/poetry-tests/project1 $ cat poetry.lock 

...

[[package]]
name = "pytest"
version = "4.6.11"
description = "pytest: simple powerful testing with Python"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"

...

[[package]]
name = "pytest"
version = "6.2.4"
description = "pytest: simple powerful testing with Python"
category = "main"
optional = false
python-versions = ">=3.6"

...
^jsirois@gill /tmp/poetry-tests/project1 $ poetry export | grep -A4 pytest
pytest==4.6.11; python_version == "2.7" or python_version == "3.5" \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b
pytest==6.2.4; python_version >= "3.6" and python_version < "3.10" \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b
$ poetry build
Recreating virtualenv project1-4YBmDZOx-py3.9 in /home/jsirois/.cache/pypoetry/virtualenvs/project1-4YBmDZOx-py3.9
Building project1 (0.1.0)
  - Building sdist
  - Built project1-0.1.0.tar.gz
  - Building wheel
  - Built project1-0.1.0-py2.py3-none-any.whl
^jsirois@gill /tmp/poetry-tests/project1 $ unzip -qc dist/project1-0.1.0-py2.py3-none-any.whl project1-0.1.0.dist-info/METADATA | grep Requires-
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
Requires-Dist: pytest (==4.6.11); python_version == "2.7" or python_version == "3.5"
Requires-Dist: pytest (==6.2.4); python_version >= "3.6" and python_version < "3.10"

Next I try to consume that project as a dependency in a different Poetry managed project:

^jsirois@gill /tmp/poetry-tests/lock-me $ ls -l
total 4
-rw-r--r-- 1 jsirois jsirois   0 Aug 13 10:13 lock_me.py
-rw-r--r-- 1 jsirois jsirois 408 Aug 13 10:18 pyproject.toml
^jsirois@gill /tmp/poetry-tests/lock-me $ cat pyproject.toml 
[tool.poetry]
name = "lock-me"
version = "0.1.0"
description = ""
authors = ["John Sirois <[email protected]>"]

[tool.poetry.dependencies]
python = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.10"
project1 = { path = "../project1/dist/project1-0.1.0-py2.py3-none-any.whl" }

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
^jsirois@gill /tmp/poetry-tests/project1 $ cat poetry.lock 
...

[[package]]
name = "project1"
version = "0.1.0"
description = ""
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"

[package.dependencies]
pytest = {version = "6.2.4", markers = "python_version >= \"3.6\" and python_version < \"3.10\""}

...

^jsirois@gill /tmp/poetry-tests/lock-me $ poetry export | grep -A4 pytest
pytest==6.2.4; python_version >= "3.6" and python_version < "3.10" and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") \
    --hash=sha256:a00a7d79cbbdfa9d21e7d0298392a8dd4123316bfac545075e6f8f24c94d8c97 \
    --hash=sha256:50fa82392f2120cc3ec2ca0a75ee615be4c479e66669789771f1758332be4353 \
    --hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890 \
    --hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b
@dimbleby
Copy link
Contributor

All works fine with latest code, this is fixed.

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 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
kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

4 participants