From c747ff123b5e3be0e1b31eaa29e6b1ea00afa4e3 Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Thu, 23 Feb 2023 13:21:24 -0600 Subject: [PATCH 1/6] Update README.md to reflect default-poetry-source-pypi --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a4c5e986..b32eeaf33 100644 --- a/README.md +++ b/README.md @@ -388,8 +388,18 @@ A dependency will also be treated as a `pip` dependency if explicitly marked wit [tool.conda-lock.dependencies] ampel-ztf = {source = "pypi"} ``` +##### Defaulting Poetry Dependency Source to PyPI -In both these cases, the dependencies of `pip`-installable packages will also be +Alternatively, the above behavior is defaulted for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: +- Defaulting to PyPI dependencies for `[tool.poetry.dependencies]` +- Defaulting to Conda dependencies for `[tool.conda-lock.dependencies]` + +by explicitly providing `default-poetry-source-pypi = true` in `[tool.conda-lock]` section, e.g.: +```toml +[tool.conda-lock] +default-poetry-source-pypi = true +``` +In all cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` dependency. From 9e7159b75849b1cb07a4931afbdb3c4b5ef7fee0 Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Thu, 23 Feb 2023 15:42:39 -0600 Subject: [PATCH 2/6] Default Poetry PyPI Behavior Change + Tests --- conda_lock/src_parser/pyproject_toml.py | 10 ++++++- tests/test-poetry-default-pypi/pyproject.toml | 30 +++++++++++++++++++ tests/test_conda_lock.py | 24 +++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/test-poetry-default-pypi/pyproject.toml diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 52d67a9fd..06803e4bc 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -98,6 +98,7 @@ def parse_poetry_pyproject_toml( * By default, dependency names are translated to the conda equivalent, with two exceptions: - If a dependency has `source = "pypi"`, it is treated as a pip dependency (by name) - If a dependency has a url, it is treated as a direct pip dependency (by url) + - If all dependencies are defaulted to pypi, `default-poetry-source-pypi = true` * markers are not supported @@ -134,11 +135,18 @@ def parse_poetry_pyproject_toml( url = depattrs.get("url", None) optional = depattrs.get("optional", False) extras = depattrs.get("extras", []) + default_poetry_source_pypi = get_in( + ["tool", "conda-lock", "default-poetry-source-pypi"], + contents, + False, + ) # If a dependency is explicitly marked as sourced from pypi, - # or is a URL dependency, delegate to the pip section + # or is a URL dependency, + # or if default to pypi is marked explicitly, delegate to the pip section, if ( depattrs.get("source", None) == "pypi" or poetry_version_spec is None + or default_poetry_source_pypi ): manager = "pip" # TODO: support additional features such as markers for things like sys_platform, platform_system diff --git a/tests/test-poetry-default-pypi/pyproject.toml b/tests/test-poetry-default-pypi/pyproject.toml new file mode 100644 index 000000000..f4fcc69f3 --- /dev/null +++ b/tests/test-poetry-default-pypi/pyproject.toml @@ -0,0 +1,30 @@ +[tool.poetry] +name = "conda-lock-test-poetry" +version = "0.0.1" +description = "" +authors = ["conda-lock"] + +[tool.poetry.dependencies] +requests = "^2.13.0" +toml = ">=0.10" +tomlkit = { version = ">=0.7.0,<1.0.0", optional = true } + +[tool.poetry.dev-dependencies] +pytest = "~5.1.0" + +[tool.poetry.extras] +tomlkit = ["tomlkit"] + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" + +[tool.conda-lock] +default-poetry-source-pypi = true +channels = [ + 'defaults' +] + +[tool.conda-lock.dependencies] +sqlite = "<3.34" +certifi = ">=2019.11.28" diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 943ac8789..cb7452ef3 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -182,6 +182,13 @@ def poetry_pyproject_toml(tmp_path: Path): return clone_test_dir("test-poetry", tmp_path).joinpath("pyproject.toml") +@pytest.fixture +def poetry_pyproject_toml_default_pypi(tmp_path: Path): + return clone_test_dir("test-poetry-default-pypi", tmp_path).joinpath( + "pyproject.toml" + ) + + @pytest.fixture def poetry_pyproject_toml_no_pypi(tmp_path: Path): return clone_test_dir("test-poetry-no-pypi", tmp_path).joinpath("pyproject.toml") @@ -593,6 +600,23 @@ def test_parse_poetry(poetry_pyproject_toml: Path): assert res.channels == [Channel.from_string("defaults")] +def test_parse_poetry_default_pypi(poetry_pyproject_toml_default_pypi: Path): + res = parse_pyproject_toml( + poetry_pyproject_toml_default_pypi, + ) + + specs = { + dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + } + + assert specs["sqlite"].manager == "conda" + assert specs["certifi"].manager == "conda" + assert specs["requests"].manager == "pip" + assert specs["toml"].manager == "pip" + assert specs["pytest"].manager == "pip" + assert specs["tomlkit"].manager == "pip" + + def test_parse_poetry_no_pypi(poetry_pyproject_toml_no_pypi: Path): res = parse_pyproject_toml( poetry_pyproject_toml_no_pypi, From f85dd7a294682df8609ee060cbc675ae4c35c2e8 Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Thu, 23 Feb 2023 16:25:57 -0600 Subject: [PATCH 3/6] Update docs to reflect changes --- docs/pip.md | 10 +++++++++- docs/src_pyproject.md | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/pip.md b/docs/pip.md index e1e402f7b..41884bd8e 100644 --- a/docs/pip.md +++ b/docs/pip.md @@ -45,6 +45,14 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -In both these cases, the dependencies of `pip`-installable packages will also be +Alternatively, explicitly providing `default-poetry-source-pypi = true` in the `[tool.conda-lock]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: +- Default to PyPI dependencies for `[tool.poetry.dependencies]` +- Default to Conda dependencies for `[tool.conda-lock.dependencies]` +```toml +[tool.conda-lock] +default-poetry-source-pypi = true +``` + +In all cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` dependency. diff --git a/docs/src_pyproject.md b/docs/src_pyproject.md index 1577690f4..4badd5664 100644 --- a/docs/src_pyproject.md +++ b/docs/src_pyproject.md @@ -77,7 +77,15 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -In both these cases, the dependencies of `pip`-installable packages will also be +Alternatively, explicitly providing `default-poetry-source-pypi = true` in the `[tool.conda-lock]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: +- Default to PyPI dependencies for `[tool.poetry.dependencies]` +- Default to Conda dependencies for `[tool.conda-lock.dependencies]` +```toml +[tool.conda-lock] +default-poetry-source-pypi = true +``` + +In all cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` dependency. From 27bcb29605c0d6cbf3cd98ac5e17d8a763683e0d Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Tue, 28 Feb 2023 14:51:57 -0600 Subject: [PATCH 4/6] Naming / Path switch to default-dependencies-to-conda --- README.md | 6 ++--- conda_lock/src_parser/pyproject_toml.py | 22 +++++++++---------- docs/pip.md | 6 ++--- docs/src_pyproject.md | 6 ++--- tests/test-poetry-default-pypi/pyproject.toml | 4 +++- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b32eeaf33..7f439e726 100644 --- a/README.md +++ b/README.md @@ -394,10 +394,10 @@ Alternatively, the above behavior is defaulted for all dependencies defined in ` - Defaulting to PyPI dependencies for `[tool.poetry.dependencies]` - Defaulting to Conda dependencies for `[tool.conda-lock.dependencies]` -by explicitly providing `default-poetry-source-pypi = true` in `[tool.conda-lock]` section, e.g.: +by explicitly providing `default-dependencies-to-conda = false` in `[tool.conda-lock.poetry]` section, e.g.: ```toml -[tool.conda-lock] -default-poetry-source-pypi = true +[tool.conda-lock.poetry] +default-dependencies-to-conda = false ``` In all cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 06803e4bc..8d30fa0c4 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -95,10 +95,10 @@ def parse_poetry_pyproject_toml( * dependencies in [tool.poetry.dev-dependencies] have category dev * dependencies in each `key` of [tool.poetry.extras] have category `key` - * By default, dependency names are translated to the conda equivalent, with two exceptions: + * By default, dependency names are translated to the conda equivalent, with three exceptions: - If a dependency has `source = "pypi"`, it is treated as a pip dependency (by name) - If a dependency has a url, it is treated as a direct pip dependency (by url) - - If all dependencies are defaulted to pypi, `default-poetry-source-pypi = true` + - If all dependencies are defaulted to pypi, `default-dependencies-to-conda = false` * markers are not supported @@ -121,13 +121,20 @@ def parse_poetry_pyproject_toml( group_key = tuple(["group", group_name, "dependencies"]) categories[group_key] = group_name + default_dependencies_to_conda = get_in( + ["tool", "conda-lock", "poetry", "default-dependencies-to-conda"], + contents, + True, + ) for section, default_category in categories.items(): for depname, depattrs in get_in( ["tool", "poetry", *section], contents, {} ).items(): category = dep_to_extra.get(depname) or default_category optional = category != "main" - manager: Literal["conda", "pip"] = "conda" + manager: Literal["conda", "pip"] = ( + "conda" if default_dependencies_to_conda else "pip" + ) url = None extras = [] if isinstance(depattrs, collections.abc.Mapping): @@ -135,18 +142,11 @@ def parse_poetry_pyproject_toml( url = depattrs.get("url", None) optional = depattrs.get("optional", False) extras = depattrs.get("extras", []) - default_poetry_source_pypi = get_in( - ["tool", "conda-lock", "default-poetry-source-pypi"], - contents, - False, - ) # If a dependency is explicitly marked as sourced from pypi, - # or is a URL dependency, - # or if default to pypi is marked explicitly, delegate to the pip section, + # or is a URL dependency, delegate to the pip section if ( depattrs.get("source", None) == "pypi" or poetry_version_spec is None - or default_poetry_source_pypi ): manager = "pip" # TODO: support additional features such as markers for things like sys_platform, platform_system diff --git a/docs/pip.md b/docs/pip.md index 41884bd8e..29f3e8e3e 100644 --- a/docs/pip.md +++ b/docs/pip.md @@ -45,12 +45,12 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -Alternatively, explicitly providing `default-poetry-source-pypi = true` in the `[tool.conda-lock]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: +Alternatively, explicitly providing `default-dependencies-to-conda = false` in the `[tool.conda-lock.poetry]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: - Default to PyPI dependencies for `[tool.poetry.dependencies]` - Default to Conda dependencies for `[tool.conda-lock.dependencies]` ```toml -[tool.conda-lock] -default-poetry-source-pypi = true +[tool.conda-lock.poetry] +default-dependencies-to-conda = false ``` In all cases, the dependencies of `pip`-installable packages will also be diff --git a/docs/src_pyproject.md b/docs/src_pyproject.md index 4badd5664..ebdca3484 100644 --- a/docs/src_pyproject.md +++ b/docs/src_pyproject.md @@ -77,12 +77,12 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -Alternatively, explicitly providing `default-poetry-source-pypi = true` in the `[tool.conda-lock]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: +Alternatively, explicitly providing `default-dependencies-to-conda = false` in the `[tool.conda-lock.poetry]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: - Default to PyPI dependencies for `[tool.poetry.dependencies]` - Default to Conda dependencies for `[tool.conda-lock.dependencies]` ```toml -[tool.conda-lock] -default-poetry-source-pypi = true +[tool.conda-lock.poetry] +default-dependencies-to-conda = false ``` In all cases, the dependencies of `pip`-installable packages will also be diff --git a/tests/test-poetry-default-pypi/pyproject.toml b/tests/test-poetry-default-pypi/pyproject.toml index f4fcc69f3..e77117db0 100644 --- a/tests/test-poetry-default-pypi/pyproject.toml +++ b/tests/test-poetry-default-pypi/pyproject.toml @@ -20,11 +20,13 @@ requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" [tool.conda-lock] -default-poetry-source-pypi = true channels = [ 'defaults' ] +[tool.conda-lock.poetry] +default-dependencies-to-conda = false + [tool.conda-lock.dependencies] sqlite = "<3.34" certifi = ">=2019.11.28" From 84f969ed5d29695eae71703de0c6336aa087ea6a Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Tue, 14 Mar 2023 14:48:54 -0500 Subject: [PATCH 5/6] Naming / Path switch to default-non-conda-source Implements default source to pypi switch in [tool.conda-lock] for all supported pyproject.toml flavors (poetry, pep621(flit, pdm)) --- README.md | 15 +++--- conda_lock/src_parser/pyproject_toml.py | 30 +++++++---- docs/pip.md | 10 ++-- docs/src_pyproject.md | 10 ++-- tests/test-flit-default-pip/pyproject.toml | 29 ++++++++++ tests/test-pdm-default-pip/pyproject.toml | 28 ++++++++++ .../pyproject.toml | 4 +- tests/test_conda_lock.py | 53 +++++++++++++++++-- 8 files changed, 145 insertions(+), 34 deletions(-) create mode 100644 tests/test-flit-default-pip/pyproject.toml create mode 100644 tests/test-pdm-default-pip/pyproject.toml rename tests/{test-poetry-default-pypi => test-poetry-default-pip}/pyproject.toml (89%) diff --git a/README.md b/README.md index 7f439e726..835eab2a2 100644 --- a/README.md +++ b/README.md @@ -388,17 +388,18 @@ A dependency will also be treated as a `pip` dependency if explicitly marked wit [tool.conda-lock.dependencies] ampel-ztf = {source = "pypi"} ``` -##### Defaulting Poetry Dependency Source to PyPI +##### Defaulting non-conda dependency sources to PyPI -Alternatively, the above behavior is defaulted for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: -- Defaulting to PyPI dependencies for `[tool.poetry.dependencies]` -- Defaulting to Conda dependencies for `[tool.conda-lock.dependencies]` +Alternatively, the above behavior is defaulted for all dependencies defined outside of `[tool.conda-lock.dependencies]`, i.e.: +- Default to `pip` dependencies for `[tool.poetry.dependencies]`, `[project.dependencies]`, etc. +- Default to `conda` dependencies for `[tool.conda-lock.dependencies]` -by explicitly providing `default-dependencies-to-conda = false` in `[tool.conda-lock.poetry]` section, e.g.: +by explicitly providing `default-non-conda-source = "pip"` in `[tool.conda-lock]` section, e.g.: ```toml -[tool.conda-lock.poetry] -default-dependencies-to-conda = false +[tool.conda-lock] +default-non-conda-source = "pip" ``` + In all cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` dependency. diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index 8d30fa0c4..d408b2b8f 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -98,7 +98,7 @@ def parse_poetry_pyproject_toml( * By default, dependency names are translated to the conda equivalent, with three exceptions: - If a dependency has `source = "pypi"`, it is treated as a pip dependency (by name) - If a dependency has a url, it is treated as a direct pip dependency (by url) - - If all dependencies are defaulted to pypi, `default-dependencies-to-conda = false` + - If all dependencies are default-sourced to pip, `default-non-conda-source = "pip"` * markers are not supported @@ -121,10 +121,10 @@ def parse_poetry_pyproject_toml( group_key = tuple(["group", group_name, "dependencies"]) categories[group_key] = group_name - default_dependencies_to_conda = get_in( - ["tool", "conda-lock", "poetry", "default-dependencies-to-conda"], + default_non_conda_source = get_in( + ["tool", "conda-lock", "default-non-conda-source"], contents, - True, + "conda", ) for section, default_category in categories.items(): for depname, depattrs in get_in( @@ -132,9 +132,7 @@ def parse_poetry_pyproject_toml( ).items(): category = dep_to_extra.get(depname) or default_category optional = category != "main" - manager: Literal["conda", "pip"] = ( - "conda" if default_dependencies_to_conda else "pip" - ) + manager: Literal["conda", "pip"] = default_non_conda_source url = None extras = [] if isinstance(depattrs, collections.abc.Mapping): @@ -311,11 +309,19 @@ def parse_requirements_pyproject_toml( ): sections[(*prefix, optional_tag, extra)] = extra + default_non_conda_source = get_in( + ["tool", "conda-lock", "default-non-conda-source"], + contents, + "conda", + ) for path, category in sections.items(): for dep in get_in(list(path), contents, []): dependencies.append( parse_python_requirement( - dep, manager="conda", category=category, optional=category != "main" + dep, + manager=default_non_conda_source, + category=category, + optional=category != "main", ) ) @@ -339,12 +345,16 @@ def parse_pdm_pyproject_toml( ) dev_reqs = [] - + default_non_conda_source = get_in( + ["tool", "conda-lock", "default-non-conda-source"], + contents, + "conda", + ) for section, deps in get_in(["tool", "pdm", "dev-dependencies"], contents).items(): dev_reqs.extend( [ parse_python_requirement( - dep, manager="conda", category="dev", optional=True + dep, manager=default_non_conda_source, category="dev", optional=True ) for dep in deps ] diff --git a/docs/pip.md b/docs/pip.md index 29f3e8e3e..6ae6a4cb8 100644 --- a/docs/pip.md +++ b/docs/pip.md @@ -45,12 +45,12 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -Alternatively, explicitly providing `default-dependencies-to-conda = false` in the `[tool.conda-lock.poetry]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: -- Default to PyPI dependencies for `[tool.poetry.dependencies]` -- Default to Conda dependencies for `[tool.conda-lock.dependencies]` +Alternatively, explicitly providing `default-non-conda-source = "pip"` in the `[tool.conda-lock]` section will treat all non-conda dependencies -- all dependencies defined outside of `[tool.conda-lock.dependencies]` -- as `pip` dependencies, i.e.: +- Default to `pip` dependencies for `[tool.poetry.dependencies]`, `[project.dependencies]`, etc. +- Default to `conda` dependencies for `[tool.conda-lock.dependencies]` ```toml -[tool.conda-lock.poetry] -default-dependencies-to-conda = false +[tool.conda-lock] +default-non-conda-source = "pip" ``` In all cases, the dependencies of `pip`-installable packages will also be diff --git a/docs/src_pyproject.md b/docs/src_pyproject.md index ebdca3484..0854aba98 100644 --- a/docs/src_pyproject.md +++ b/docs/src_pyproject.md @@ -77,12 +77,12 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` -Alternatively, explicitly providing `default-dependencies-to-conda = false` in the `[tool.conda-lock.poetry]` section will set PyPI as the default source for all dependencies defined in `[tool.poetry.dependencies]`, i.e.: -- Default to PyPI dependencies for `[tool.poetry.dependencies]` -- Default to Conda dependencies for `[tool.conda-lock.dependencies]` +Alternatively, explicitly providing `default-non-conda-source = "pip"` in the `[tool.conda-lock]` section will treat all non-conda dependencies -- all dependencies defined outside of `[tool.conda-lock.dependencies]` -- as `pip` dependencies, i.e.: +- Default to `pip` dependencies for `[tool.poetry.dependencies]`, `[project.dependencies]`, etc. +- Default to `conda` dependencies for `[tool.conda-lock.dependencies]` ```toml -[tool.conda-lock.poetry] -default-dependencies-to-conda = false +[tool.conda-lock] +default-non-conda-source = "pip" ``` In all cases, the dependencies of `pip`-installable packages will also be diff --git a/tests/test-flit-default-pip/pyproject.toml b/tests/test-flit-default-pip/pyproject.toml new file mode 100644 index 000000000..9de757aef --- /dev/null +++ b/tests/test-flit-default-pip/pyproject.toml @@ -0,0 +1,29 @@ +[tool.flit.metadata] +name = "conda-lock-test-poetry" +version = "0.0.1" +description = "" +authors = ["conda-lock"] +requires = [ + "requests >=2.13.0", + "toml >=0.10", + "tomlkit >=0.7", + ] + +[tool.flit.metadata.requires-extra] +test = [ + "pytest >=5.1.0" +] + +[build-system] +requires = ["flit_core >=2,<4"] +build-backend = "flit_core.buildapi" + +[tool.conda-lock] +channels = [ + 'defaults' +] +default-non-conda-source = "pip" + +[tool.conda-lock.dependencies] +sqlite = "<3.34" +certifi = ">=2019.11.28" diff --git a/tests/test-pdm-default-pip/pyproject.toml b/tests/test-pdm-default-pip/pyproject.toml new file mode 100644 index 000000000..5dd33681c --- /dev/null +++ b/tests/test-pdm-default-pip/pyproject.toml @@ -0,0 +1,28 @@ +[project] +name = "conda-lock-test-pdm" +authors = ["conda-lock"] +description = "" +requires-python = ">=3.7" +dependencies = [ + "requests >=2.13.0", + "toml >=0.10", + "tomlkit >=0.7", +] + +[project.optional-dependencies] +cli = ["click >=7.0"] + +[tool.pdm.dev-dependencies] +test = [ + "pytest >=5.1.0", +] + +[tool.conda-lock] +channels = [ + "defaults", +] +default-non-conda-source = "pip" + +[tool.conda-lock.dependencies] +certifi = ">=2019.11.28" +sqlite = "<3.34" diff --git a/tests/test-poetry-default-pypi/pyproject.toml b/tests/test-poetry-default-pip/pyproject.toml similarity index 89% rename from tests/test-poetry-default-pypi/pyproject.toml rename to tests/test-poetry-default-pip/pyproject.toml index e77117db0..2509979d1 100644 --- a/tests/test-poetry-default-pypi/pyproject.toml +++ b/tests/test-poetry-default-pip/pyproject.toml @@ -23,9 +23,7 @@ build-backend = "poetry.masonry.api" channels = [ 'defaults' ] - -[tool.conda-lock.poetry] -default-dependencies-to-conda = false +default-non-conda-source = "pip" [tool.conda-lock.dependencies] sqlite = "<3.34" diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 2b43934b5..58bb4f225 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -183,8 +183,8 @@ def poetry_pyproject_toml(tmp_path: Path): @pytest.fixture -def poetry_pyproject_toml_default_pypi(tmp_path: Path): - return clone_test_dir("test-poetry-default-pypi", tmp_path).joinpath( +def poetry_pyproject_toml_default_pip(tmp_path: Path): + return clone_test_dir("test-poetry-default-pip", tmp_path).joinpath( "pyproject.toml" ) @@ -213,6 +213,16 @@ def pdm_pyproject_toml(tmp_path: Path): return clone_test_dir("test-pdm", tmp_path).joinpath("pyproject.toml") +@pytest.fixture +def flit_pyproject_toml_default_pip(tmp_path: Path): + return clone_test_dir("test-flit-default-pip", tmp_path).joinpath("pyproject.toml") + + +@pytest.fixture +def pdm_pyproject_toml_default_pip(tmp_path: Path): + return clone_test_dir("test-pdm-default-pip", tmp_path).joinpath("pyproject.toml") + + @pytest.fixture def channel_inversion(tmp_path: Path): """Path to an environment.yaml that has a hardcoded channel in one of the dependencies""" @@ -609,9 +619,9 @@ def test_parse_poetry(poetry_pyproject_toml: Path): assert res.channels == [Channel.from_string("defaults")] -def test_parse_poetry_default_pypi(poetry_pyproject_toml_default_pypi: Path): +def test_parse_poetry_default_pip(poetry_pyproject_toml_default_pip: Path): res = parse_pyproject_toml( - poetry_pyproject_toml_default_pypi, + poetry_pyproject_toml_default_pip, ) specs = { @@ -724,6 +734,23 @@ def test_parse_flit(flit_pyproject_toml: Path): assert res.channels == [Channel.from_string("defaults")] +def test_parse_flit_default_pip(flit_pyproject_toml_default_pip: Path): + res = parse_pyproject_toml( + flit_pyproject_toml_default_pip, + ) + + specs = { + dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + } + + assert specs["sqlite"].manager == "conda" + assert specs["certifi"].manager == "conda" + assert specs["requests"].manager == "pip" + assert specs["toml"].manager == "pip" + assert specs["pytest"].manager == "pip" + assert specs["tomlkit"].manager == "pip" + + def test_parse_pdm(pdm_pyproject_toml: Path): res = parse_pyproject_toml( pdm_pyproject_toml, @@ -751,6 +778,24 @@ def test_parse_pdm(pdm_pyproject_toml: Path): assert res.channels == [Channel.from_string("defaults")] +def test_parse_pdm_default_pip(pdm_pyproject_toml_default_pip: Path): + res = parse_pyproject_toml( + pdm_pyproject_toml_default_pip, + ) + + specs = { + dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + } + + assert specs["sqlite"].manager == "conda" + assert specs["certifi"].manager == "conda" + assert specs["requests"].manager == "pip" + assert specs["toml"].manager == "pip" + assert specs["pytest"].manager == "pip" + assert specs["tomlkit"].manager == "pip" + assert specs["click"].manager == "pip" + + def test_run_lock( monkeypatch: "pytest.MonkeyPatch", zlib_environment: Path, conda_exe: str ): From b471ca30e850b0356d75d5b4d2418396d7c0b48e Mon Sep 17 00:00:00 2001 From: Salman Anwer Date: Tue, 14 Mar 2023 15:16:13 -0500 Subject: [PATCH 6/6] Fix expected platforms in tests --- tests/test_conda_lock.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 15710aead..993c1fd47 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -636,12 +636,11 @@ def test_parse_poetry(poetry_pyproject_toml: Path): def test_parse_poetry_default_pip(poetry_pyproject_toml_default_pip: Path): - res = parse_pyproject_toml( - poetry_pyproject_toml_default_pip, - ) + res = parse_pyproject_toml(poetry_pyproject_toml_default_pip, ["linux-64"]) specs = { - dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + dep.name: typing.cast(VersionedDependency, dep) + for dep in res.dependencies["linux-64"] } assert specs["sqlite"].manager == "conda" @@ -752,12 +751,11 @@ def test_parse_flit(flit_pyproject_toml: Path): def test_parse_flit_default_pip(flit_pyproject_toml_default_pip: Path): - res = parse_pyproject_toml( - flit_pyproject_toml_default_pip, - ) + res = parse_pyproject_toml(flit_pyproject_toml_default_pip, ["linux-64"]) specs = { - dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + dep.name: typing.cast(VersionedDependency, dep) + for dep in res.dependencies["linux-64"] } assert specs["sqlite"].manager == "conda" @@ -795,12 +793,11 @@ def test_parse_pdm(pdm_pyproject_toml: Path): def test_parse_pdm_default_pip(pdm_pyproject_toml_default_pip: Path): - res = parse_pyproject_toml( - pdm_pyproject_toml_default_pip, - ) + res = parse_pyproject_toml(pdm_pyproject_toml_default_pip, ["linux-64"]) specs = { - dep.name: typing.cast(VersionedDependency, dep) for dep in res.dependencies + dep.name: typing.cast(VersionedDependency, dep) + for dep in res.dependencies["linux-64"] } assert specs["sqlite"].manager == "conda"