From 841fe321e491145ebc9dbb37c2412d6947f8d091 Mon Sep 17 00:00:00 2001 From: Olivier Lacroix Date: Sun, 17 Apr 2022 13:30:03 +1000 Subject: [PATCH 1/3] Force resolving dependency via pip --- conda_lock/src_parser/pyproject_toml.py | 29 ++++++++++++++++--------- docs/src_pyproject.md | 12 ++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/conda_lock/src_parser/pyproject_toml.py b/conda_lock/src_parser/pyproject_toml.py index fee5024db..5936fb203 100644 --- a/conda_lock/src_parser/pyproject_toml.py +++ b/conda_lock/src_parser/pyproject_toml.py @@ -162,23 +162,32 @@ def parse_poetry_pyproject_toml( def specification_with_dependencies( path: pathlib.Path, toml_contents: Mapping[str, Any], dependencies: List[Dependency] ) -> LockSpecification: + force_pypi = set() for depname, depattrs in get_in( ["tool", "conda-lock", "dependencies"], toml_contents, {} ).items(): if isinstance(depattrs, str): conda_version = depattrs + dependencies.append( + VersionedDependency( + name=depname, + version=conda_version, + manager="conda", + optional=False, + category="main", + extras=[], + ) + ) + elif isinstance(depattrs, collections.abc.Mapping): + if depattrs.get("source", None) == "pypi": + force_pypi.add(depname) else: raise TypeError(f"Unsupported type for dependency: {depname}: {depattrs:r}") - dependencies.append( - VersionedDependency( - name=depname, - version=conda_version, - manager="conda", - optional=False, - category="main", - extras=[], - ) - ) + + if force_pypi: + for dep in dependencies: + if dep.name in force_pypi: + dep.manager = "pip" return LockSpecification( dependencies=dependencies, diff --git a/docs/src_pyproject.md b/docs/src_pyproject.md index 0af24f1c4..b1af8a236 100644 --- a/docs/src_pyproject.md +++ b/docs/src_pyproject.md @@ -170,5 +170,17 @@ the following sections to the `pyproject.toml` sqlite = ">=3.34" ``` +### Force pypi dependencies + +While it is with poetry, it is not possible to indicate a package's source in a `pyproject.toml` which follows PEP621. + +In that case, it is possible to force resolving a dependency as a pip dependency by indicating it in the same `pyproject.toml` section. + +This is useful in particular for packages that are not present on conda channels. + +```{.toml title="pyproject.toml"} +[tool.conda-lock.dependencies] +numpy = {source = "pypi"} +``` [mapping]: https://github.com/regro/cf-graph-countyfair/blob/master/mappings/pypi/grayskull_pypi_mapping.yaml From da8f9c9b40310df3f96abc4fc90d2b807f065b0c Mon Sep 17 00:00:00 2001 From: Olivier Lacroix Date: Sun, 17 Apr 2022 13:50:16 +1000 Subject: [PATCH 2/3] =?UTF-8?q?Add=20=C2=A7=20in=20README=20as=20well?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 450d275a8..dd21df238 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,13 @@ python = "3.9" ampel-ztf = {version = "^0.8.0-alpha.2", source = "pypi"} ``` +A dependency will also be treated as a `pip` dependency if explicitly marked with `source = "pypi"` in the `[tool.conda-lock.dependencies]` section, e.g.: + +```toml +[tool.conda-lock.dependencies] +ampel-ztf = {source = "pypi"} +``` + In both these cases, the dependencies of `pip`-installable packages will also be installed with `pip`, unless they were already requested by a `conda` dependency. From e665fd611864d1b4de4bd09b917ca31c451d2276 Mon Sep 17 00:00:00 2001 From: Olivier Lacroix Date: Thu, 20 Oct 2022 13:38:48 +1100 Subject: [PATCH 3/3] Add test --- tests/test-flit/pyproject.toml | 1 + tests/test_conda_lock.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/test-flit/pyproject.toml b/tests/test-flit/pyproject.toml index a377a6e96..a2c23a4eb 100644 --- a/tests/test-flit/pyproject.toml +++ b/tests/test-flit/pyproject.toml @@ -25,3 +25,4 @@ channels = [ [tool.conda-lock.dependencies] sqlite = "<3.34" certifi = ">=2019.11.28" +toml = {source = "pypi"} \ No newline at end of file diff --git a/tests/test_conda_lock.py b/tests/test_conda_lock.py index 823db98af..33f3269d0 100644 --- a/tests/test_conda_lock.py +++ b/tests/test_conda_lock.py @@ -442,6 +442,8 @@ def test_parse_flit(flit_pyproject_toml: Path): assert specs["pytest"].optional is True assert specs["pytest"].category == "dev" + assert specs["toml"].manager == "pip" + assert res.channels == [Channel.from_string("defaults")]