Skip to content

Commit

Permalink
Merge pull request #186 from olivier-lacroix/force_pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Oct 22, 2022
2 parents 9870b27 + e665fd6 commit 4531bb8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 19 additions & 10 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions docs/src_pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/test-flit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ channels = [
[tool.conda-lock.dependencies]
sqlite = "<3.34"
certifi = ">=2019.11.28"
toml = {source = "pypi"}
2 changes: 2 additions & 0 deletions tests/test_conda_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]


Expand Down

0 comments on commit 4531bb8

Please sign in to comment.