Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force resolving dependency via pip #186

Merged
merged 3 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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