From 85bb282a26b3111da2dd57c10e2b6b01d8fc8506 Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Thu, 12 Oct 2023 16:31:55 -0500 Subject: [PATCH] fix: :bug: parse `python` version, always managed by `conda` only impacts poetry's pyproject.toml --- conda_lock/src_parser/pyproject_toml.py | 5 +++++ tests/test-poetry-default-pip/pyproject.toml | 1 + tests/test-poetry-git/pyproject.toml | 1 + tests/test-poetry-no-pypi/other_project1/pyproject.toml | 1 + tests/test-poetry-no-pypi/other_project2/pyproject.toml | 1 + tests/test-poetry-no-pypi/pyproject.toml | 1 + tests/test-poetry-optional/pyproject.toml | 1 + tests/test-poetry/pyproject.toml | 1 + tests/test_conda_lock.py | 4 ++++ 9 files changed, 16 insertions(+) diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index fe440f8b7..9c33d9a57 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -227,6 +227,11 @@ def parse_poetry_pyproject_toml( extras: List[Any] = [] in_extra: bool = False + # Poetry spec includes Python version in "tool.poetry.dependencies" + # Cannot be managed by pip + if depname == "python": + manager = "conda" + # Extras can only be defined in `tool.poetry.dependencies` if default_category == "main": in_extra = category != "main" diff --git a/tests/test-poetry-default-pip/pyproject.toml b/tests/test-poetry-default-pip/pyproject.toml index 2509979d1..3c6c7e30b 100644 --- a/tests/test-poetry-default-pip/pyproject.toml +++ b/tests/test-poetry-default-pip/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test-poetry-git/pyproject.toml b/tests/test-poetry-git/pyproject.toml index 206c1cdf4..5ed432879 100644 --- a/tests/test-poetry-git/pyproject.toml +++ b/tests/test-poetry-git/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test-poetry-no-pypi/other_project1/pyproject.toml b/tests/test-poetry-no-pypi/other_project1/pyproject.toml index f53cbef54..ee31a36d6 100644 --- a/tests/test-poetry-no-pypi/other_project1/pyproject.toml +++ b/tests/test-poetry-no-pypi/other_project1/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test-poetry-no-pypi/other_project2/pyproject.toml b/tests/test-poetry-no-pypi/other_project2/pyproject.toml index af205675c..5a832feda 100644 --- a/tests/test-poetry-no-pypi/other_project2/pyproject.toml +++ b/tests/test-poetry-no-pypi/other_project2/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test-poetry-no-pypi/pyproject.toml b/tests/test-poetry-no-pypi/pyproject.toml index ef05d550b..7ed42823d 100644 --- a/tests/test-poetry-no-pypi/pyproject.toml +++ b/tests/test-poetry-no-pypi/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test-poetry-optional/pyproject.toml b/tests/test-poetry-optional/pyproject.toml index b6092b90f..004c14d7e 100644 --- a/tests/test-poetry-optional/pyproject.toml +++ b/tests/test-poetry-optional/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" toml = "" # Checking `optional = true` but not in extra tomlkit = { version = "", optional = true } diff --git a/tests/test-poetry/pyproject.toml b/tests/test-poetry/pyproject.toml index f53cbef54..ee31a36d6 100644 --- a/tests/test-poetry/pyproject.toml +++ b/tests/test-poetry/pyproject.toml @@ -5,6 +5,7 @@ description = "" authors = ["conda-lock"] [tool.poetry.dependencies] +python = "^3.7" requests = "^2.13.0" toml = ">=0.10" tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 265aaa96b..a753f33ea 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -658,6 +658,8 @@ def test_parse_poetry(poetry_pyproject_toml: Path): for dep in res.dependencies["linux-64"] } + assert specs["python"].manager == "conda" + assert specs["python"].version == ">=3.7,<4.0" assert specs["requests"].version == ">=2.13.0,<3.0.0" assert specs["toml"].version == ">=0.10" assert specs["sqlite"].version == "<3.34" @@ -678,6 +680,8 @@ def test_parse_poetry_default_pip(poetry_pyproject_toml_default_pip: Path): for dep in res.dependencies["linux-64"] } + assert specs["python"].manager == "conda" + assert specs["python"].version == ">=3.7,<4.0" assert specs["sqlite"].manager == "conda" assert specs["certifi"].manager == "conda" assert specs["requests"].manager == "pip"