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 the way python markers with a precision >= 3 are handled #178

Merged
merged 1 commit into from
May 11, 2021
Merged
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
19 changes: 16 additions & 3 deletions poetry/core/packages/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,34 @@ def create_nested_marker(

marker = glue.join(parts)
elif isinstance(constraint, Version):
if name == "python_version" and constraint.precision >= 3:
name = "python_full_version"

marker = '{} == "{}"'.format(name, constraint.text)
else:
if constraint.min is not None:
op = ">="
if not constraint.include_min:
op = ">"

version = constraint.min.text
version = constraint.min
if constraint.max is not None:
text = '{} {} "{}"'.format(name, op, version)
min_name = max_name = name
if min_name == "python_version" and constraint.min.precision >= 3:
min_name = "python_full_version"

if max_name == "python_version" and constraint.max.precision >= 3:
max_name = "python_full_version"

text = '{} {} "{}"'.format(min_name, op, version)

op = "<="
if not constraint.include_max:
op = "<"

version = constraint.max

text += ' and {} {} "{}"'.format(name, op, version)
text += ' and {} {} "{}"'.format(max_name, op, version)

return text
elif constraint.max is not None:
Expand All @@ -276,6 +286,9 @@ def create_nested_marker(
else:
return ""

if name == "python_version" and version.precision >= 3:
name = "python_full_version"

marker = '{} {} "{}"'.format(name, op, version)

return marker
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/sample_project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ simple-project = { path = "../simple_project/" }
# Dependency with markers
functools32 = { version = "^3.2.3", markers = "python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'" }

# Dependency with python constraint
dataclasses = {version = "^0.7", python = ">=3.6.1,<3.7"}


[tool.poetry.extras]
db = [ "orator" ]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ def test_create_poetry():
== 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"'
)

dataclasses = dependencies["dataclasses"]
assert dataclasses.name == "dataclasses"
assert dataclasses.pretty_constraint == "^0.7"
assert dataclasses.python_versions == ">=3.6.1,<3.7"
assert (
str(dataclasses.marker)
== 'python_full_version >= "3.6.1" and python_version < "3.7"'
)

assert "db" in package.extras

classifiers = package.classifiers
Expand Down