Skip to content

Commit

Permalink
Merge pull request #307 from conda-incubator/poetry-dependency-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusvniekerk authored Jan 16, 2023
2 parents 5bc4e6c + bbd1ce5 commit f92a0a0
Show file tree
Hide file tree
Showing 5 changed files with 481 additions and 5 deletions.
25 changes: 22 additions & 3 deletions conda_lock/src_parser/pyproject_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
import sys

from functools import partial
from typing import AbstractSet, Any, List, Mapping, Optional, Sequence, Union
from typing import (
AbstractSet,
Any,
Dict,
List,
Mapping,
Optional,
Sequence,
Tuple,
Union,
)
from urllib.parse import urldefrag


Expand Down Expand Up @@ -94,16 +104,25 @@ def parse_poetry_pyproject_toml(
"""
dependencies: List[Dependency] = []

categories = {"dependencies": "main", "dev-dependencies": "dev"}
categories: Dict[Tuple[str, ...], str] = {
("dependencies",): "main",
("dev-dependencies",): "dev",
}

dep_to_extra = {}
for category, deps in get_in(["tool", "poetry", "extras"], contents, {}).items():
for dep in deps:
dep_to_extra[dep] = category

# Support for poetry dependency groups as specified in
# https://python-poetry.org/docs/managing-dependencies/#optional-groups
for group_name, _ in get_in(["tool", "poetry", "group"], contents, {}).items():
group_key = tuple(["group", group_name, "dependencies"])
categories[group_key] = group_name

for section, default_category in categories.items():
for depname, depattrs in get_in(
["tool", "poetry", section], contents, {}
["tool", "poetry", *section], contents, {}
).items():
category = dep_to_extra.get(depname) or default_category
optional = category != "main"
Expand Down
21 changes: 21 additions & 0 deletions docs/src_pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ When generating lockfiles that make use of extras it is recommended to make use
conda-lock --extra incompatiblea --filter-extras -f pyproject.toml
```

## Poetry specific supported features

### Dependency groups

conda-lock can map (dependency groups)[https://python-poetry.org/docs/master/managing-dependencies/#dependency-groups] to
categories similar to how extras are handled.

```{.toml title="pyproject.toml"}
[tool.poetry.group.docs.dependencies]
mkdocs = "*"
```

!!! note ""

By default *ALL* dependency groups are included. Depdency groups that have the same name as an extra are fused.
These can be filtered out / included using the same flags as for extras.

```
conda-lock --extra docs --filter-extras -f pyproject.toml
```

## Extensions

As the `pyproject.toml` format is not really designed for conda there are a few extensions we support in the
Expand Down
4 changes: 4 additions & 0 deletions tests/test-poetry-ibis/fetch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# fetch the latest version of the ibis pyproject.toml
curl -s https://raw.githubusercontent.com/ibis-project/ibis/master/pyproject.toml > pyproject.toml
Loading

0 comments on commit f92a0a0

Please sign in to comment.