Resolver¶
The library provides its resolution machinery via an object oriented interface,
which allows users to explore the structure of data before or during
resolution using DependencyGroupInclude and DependencyGroupResolver.
For example,
from dependency_groups import DependencyGroupResolver
groups = {
"test": ["pytest", {"include-group": "runtime"}],
"runtime": ["flask"],
}
resolver = DependencyGroupResolver(groups)
# you can lookup a group without resolving it
resolver.lookup("test") # [Requirement('pytest'), DependencyGroupInclude('runtime')]
# and resolve() produces packaging Requirements
resolver.resolve("test") # [Requirement('pytest'), Requirement('flask')]
Models¶
Resolver¶
- class dependency_groups.DependencyGroupResolver(dependency_groups: Mapping[str, str | Mapping[str, str]])[source]¶
A resolver for Dependency Group data.
This class handles caching, name normalization, cycle detection, and other parsing requirements. There are only two public methods for exploring the data:
lookup()andresolve().- Parameters:
dependency_groups – A mapping, as provided via pyproject
[dependency-groups].
- lookup(group: str) tuple[Requirement | DependencyGroupInclude, ...][source]¶
Lookup a group name, returning the parsed dependency data for that group. This will not resolve includes.
- Parameters:
group – the name of the group to lookup
- Raises:
ValueError – if the data does not appear to be valid dependency group data
TypeError – if the data is not a string
LookupError – if group name is absent
packaging.requirements.InvalidRequirement – if a specifier is not valid
- resolve(group: str) tuple[Requirement, ...][source]¶
Resolve a dependency group to a list of requirements.
- Parameters:
group – the name of the group to resolve
- Raises:
TypeError – if the inputs appear to be the wrong types
ValueError – if the data does not appear to be valid dependency group data
LookupError – if group name is absent
packaging.requirements.InvalidRequirement – if a specifier is not valid
- resolve_all() Mapping[str, tuple[Requirement, ...]][source]¶
Resolve all dependency groups, returning a mapping of normalized group names to resolved requirements.
This is more efficient than calling resolve() on each group individually because it avoids repeated work when groups share common includes.
- Raises:
TypeError – if the data appears to be the wrong types
ValueError – if the data does not appear to be valid dependency group data
packaging.requirements.InvalidRequirement – if a specifier is not valid