Skip to content

Commit

Permalink
Merge pull request #72 from pbjc/conda-dependencies
Browse files Browse the repository at this point in the history
Add support for specifying conda dependencies in pyproject.toml
  • Loading branch information
mariusvniekerk authored Dec 28, 2020
2 parents 8b3ae9d + a2bce56 commit 99b4a58
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
19 changes: 18 additions & 1 deletion conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import collections.abc
import pathlib

from typing import List, Optional
from typing import List, Mapping, Optional

import requests
import toml
Expand Down Expand Up @@ -97,6 +97,9 @@ def parse_poetry_pyproject_toml(
else:
specs.append(spec)

conda_deps = get_in(["tool", "conda-lock", "dependencies"], contents, {})
specs.extend(parse_conda_dependencies(conda_deps))

channels = get_in(["tool", "conda-lock", "channels"], contents, [])

return LockSpecification(specs=specs, channels=channels, platform=platform)
Expand Down Expand Up @@ -164,6 +167,20 @@ def parse_flit_pyproject_toml(

specs = [python_requirement_to_conda_spec(req) for req in requirements]

conda_deps = get_in(["tool", "conda-lock", "dependencies"], contents, {})
specs.extend(parse_conda_dependencies(conda_deps))

channels = get_in(["tool", "conda-lock", "channels"], contents, [])

return LockSpecification(specs=specs, channels=channels, platform=platform)


def parse_conda_dependencies(conda_deps: Mapping) -> List[str]:
specs = []
for depname, depattrs in conda_deps.items():
if isinstance(depattrs, str):
conda_version = depattrs
else:
raise TypeError(f"Unsupported type for dependency: {depname}: {depattrs:r}")
specs.append(to_match_spec(depname, conda_version))
return specs
6 changes: 5 additions & 1 deletion tests/test-flit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ build-backend = "flit_core.buildapi"
[tool.conda-lock]
channels = [
'defaults'
]
]

[tool.conda-lock.dependencies]
sqlite = "<3.34"
certifi = ">=2019.11.28"
6 changes: 5 additions & 1 deletion tests/test-poetry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ build-backend = "poetry.masonry.api"
[tool.conda-lock]
channels = [
'defaults'
]
]

[tool.conda-lock.dependencies]
sqlite = "<3.34"
certifi = ">=2019.11.28"
4 changes: 4 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def test_parse_poetry(poetry_pyproject_toml, include_dev_dependencies):

assert "requests[version='>=2.13.0,<3.0.0']" in res.specs
assert "toml[version='>=0.10']" in res.specs
assert "sqlite[version='<3.34']" in res.specs
assert "certifi[version='>=2019.11.28']" in res.specs
assert ("pytest[version='>=5.1.0,<5.2.0']" in res.specs) == include_dev_dependencies
assert res.channels == ["defaults"]

Expand All @@ -118,6 +120,8 @@ def test_parse_flit(flit_pyproject_toml, include_dev_dependencies):

assert "requests[version='>=2.13.0']" in res.specs
assert "toml[version='>=0.10']" in res.specs
assert "sqlite[version='<3.34']" in res.specs
assert "certifi[version='>=2019.11.28']" in res.specs
# test deps
assert ("pytest[version='>=5.1.0']" in res.specs) == include_dev_dependencies
assert res.channels == ["defaults"]
Expand Down

0 comments on commit 99b4a58

Please sign in to comment.