Skip to content

Commit 992f86f

Browse files
authored
Merge pull request #180 from python-poetry/fix-python-markers-handling-1.0
[1.0] Fix the way python markers with a precision >= 3 are handled
2 parents 0ce1956 + 79c1819 commit 992f86f

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

poetry/core/packages/utils/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,34 @@ def create_nested_marker(
244244

245245
marker = glue.join(parts)
246246
elif isinstance(constraint, Version):
247+
if name == "python_version" and constraint.precision >= 3:
248+
name = "python_full_version"
249+
247250
marker = '{} == "{}"'.format(name, constraint.text)
248251
else:
249252
if constraint.min is not None:
250253
op = ">="
251254
if not constraint.include_min:
252255
op = ">"
253256

254-
version = constraint.min.text
257+
version = constraint.min
255258
if constraint.max is not None:
256-
text = '{} {} "{}"'.format(name, op, version)
259+
min_name = max_name = name
260+
if min_name == "python_version" and constraint.min.precision >= 3:
261+
min_name = "python_full_version"
262+
263+
if max_name == "python_version" and constraint.max.precision >= 3:
264+
max_name = "python_full_version"
265+
266+
text = '{} {} "{}"'.format(min_name, op, version)
257267

258268
op = "<="
259269
if not constraint.include_max:
260270
op = "<"
261271

262272
version = constraint.max
263273

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

266276
return text
267277
elif constraint.max is not None:
@@ -273,6 +283,9 @@ def create_nested_marker(
273283
else:
274284
return ""
275285

286+
if name == "python_version" and version.precision >= 3:
287+
name = "python_full_version"
288+
276289
marker = '{} {} "{}"'.format(name, op, version)
277290

278291
return marker

tests/fixtures/sample_project/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ simple-project = { path = "../simple_project/" }
4343
# Dependency with markers
4444
functools32 = { version = "^3.2.3", markers = "python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'" }
4545

46+
# Dependency with python constraint
47+
dataclasses = {version = "^0.7", python = ">=3.6.1,<3.7"}
48+
4649

4750
[tool.poetry.extras]
4851
db = [ "orator" ]

tests/test_factory.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ def test_create_poetry():
100100
== 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"'
101101
)
102102

103+
dataclasses = dependencies["dataclasses"]
104+
assert dataclasses.name == "dataclasses"
105+
assert dataclasses.pretty_constraint == "^0.7"
106+
assert dataclasses.python_versions == ">=3.6.1,<3.7"
107+
assert (
108+
str(dataclasses.marker)
109+
== 'python_full_version >= "3.6.1" and python_version < "3.7"'
110+
)
111+
103112
assert "db" in package.extras
104113

105114
classifiers = package.classifiers

0 commit comments

Comments
 (0)