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

fix populate python constraints from markers #261

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def create_dependency(
from poetry.core.packages.file_dependency import FileDependency
from poetry.core.packages.url_dependency import URLDependency
from poetry.core.packages.utils.utils import create_nested_marker
from poetry.core.packages.utils.utils import get_python_constraint_from_marker
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.semver.helpers import parse_constraint
from poetry.core.version.markers import AnyMarker
Expand Down Expand Up @@ -366,6 +367,10 @@ def create_dependency(
)
else:
marker = parse_marker(markers)
# possibility that python constraint appears in markers, not keywords
if not python_versions and markers:
Copy link
Contributor

@dimbleby dimbleby Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markers is known truth-y here, isn't it, making this check redundant?

python_versions_marker = get_python_constraint_from_marker(marker)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just python_versions = get_python_constraint_from_marker(marker)?

python_versions = python_versions_marker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of this parse is never used, is it?

The test that you have added passes without the fix, which is consistent with this not doing anything.

Can you add a test that fails before the fix, and passes after it?


if not marker.is_any():
dependency.marker = marker
Expand Down
10 changes: 10 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,13 @@ def test_create_poetry_fails_with_invalid_dev_dependencies_iff_with_dev_is_true(
Factory().create_poetry(
fixtures_dir / "project_with_invalid_dev_deps", with_groups=False
)


def test_create_dependency_python_constraint_populated_from_markers():
constraint = {
"version": "1.2.3.",
"markers": 'python_version=="3.8" and sys_platform=="linux"',
}
dependency = Factory().create_dependency("a", constraint)

assert str(dependency._python_constraint) == ">=3.8,<3.9"