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 doesn't parse python constraints when markers are present #4965

Closed
2 tasks done
maciejskorski opened this issue Jan 1, 2022 · 2 comments · Fixed by python-poetry/poetry-core#324
Closed
2 tasks done
Labels
kind/bug Something isn't working as expected

Comments

@maciejskorski
Copy link

maciejskorski commented Jan 1, 2022

  • I am on the latest Poetry version.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Clarifies in-depth the common root-cause for several reported issues
#3444
#4959
#4958

  • OS version and name: Linux
  • Poetry version: 1.2.0a2
  • Python 3.8

Issue

poetry fails to parse python constraints when markers appear.

This should be supported as per the official documentation.

This also has a side effect on the performance and the lock file, as this way packages bypass early compatibility checks on versions; also wrong versions may get installed.

Reproduce
The following test confirms that poetry does not populate python constraints due to markers

[tool.poetry.dependencies]
python = "3.8"
pandas = [
    {version="1.3.2",python="3.9",markers="sys_platform=='linux'"},
    {version="1.3.1",python="3.8"}
]

then setting a breakpoint inside complete_package method gives

# [(d.name+str(d._constraint),d._python_constraint) for d in requires]
[('pandas1.3.2', <VersionRange (*)>), ('pandas1.3.1', <Version 3.8>)]

Furthermore, due to the broken constraint poetry would pick up the wrong (1.3.2) version to install.

@maciejskorski maciejskorski added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jan 1, 2022
@maciejskorski maciejskorski changed the title poetry doesn't read python constraints poetry doesn't read python constraints when markers are present Jan 1, 2022
@maciejskorski
Copy link
Author

maciejskorski commented Jan 1, 2022

Root-Cause

The issue is inside the function poetry.core.factory.configure_package, which translates poetry.local_config (json-like) into package (python object) see

Indeed, consider

from poetry.core.pyproject.toml import PyProjectTOML
from poetry.core.factory import Factory
local_config=PyProjectTOML(path='pyproject.toml').poetry_config
# local_config['dependencies'] has all python constraints
package = Factory.get_package('test','0.0.0')
package = Factory.configure_package(package,local_config,'')
[d.marker for d in package._dependency_groups['default']._dependencies]
# python constraints not populated :-(

What needs to be fixed is the method Factory.create_dependency from poetry.core.factory

To reproduce the issue

constraint = {'version': '1.3.2', 'python': '3.9', 'markers': "sys_platform=='linux'"}
Factory.create_dependency('pandas', constraint)._python_constraint
# this gives wrongly version 
constraint.pop('markers')
Factory.create_dependency('pandas', constraint)._python_constraint
# correct version once markers deleted

What happens is the code logic excludes populating python constraints when markers are present.

But fixing this seems to require changes to poetry.core. Any thoughts?

@maciejskorski maciejskorski changed the title poetry doesn't read python constraints when markers are present poetry doesn't respect python constraints when markers are present Jan 1, 2022
@maciejskorski maciejskorski changed the title poetry doesn't respect python constraints when markers are present poetry doesn't parse python constraints when markers are present Jan 1, 2022
@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
2 participants