Skip to content

API


Dependency

A packaging.requirements.Requirement with support for editable metadata.

Parameters:

Name Type Description Default
requirement_string str

The requirement string.

required
editable bool

Whether the dependency should be editable.

False

editable = False if self.url is None else editable instance-attribute

path: str | None cached property

Returns:

Type Description
str | None

The path of the dependency if it's a local path, otherwise None.

dependencies_satisfied(dependencies: list[Dependency], *, sys_path: list[str] | None = None, environment: dict[str, str] | None = None) -> bool

This is equivalent to creating an instance of InstalledDistributions and calling its dependencies_satisfied method.

Parameters:

Name Type Description Default
dependencies list[Dependency]

The dependencies to check.

required
sys_path list[str] | None

The list of directories to search for installed distributions, defaulting to sys.path.

None
environment dict[str, str] | None

The marker environment, defaulting to packaging.markers.default_environment.

None

Returns:

Type Description
bool

Whether all the dependencies are satisfied.

dependency_state(dependencies: list[Dependency], *, exhaustive: bool = False, sys_path: list[str] | None = None, environment: dict[str, str] | None = None) -> DependencyState

This is equivalent to creating an instance of InstalledDistributions and calling its dependency_state method.

Parameters:

Name Type Description Default
dependencies list[Dependency]

The dependencies to check.

required
exhaustive bool

Whether to search for all distributions that are not required.

False

Returns:

Type Description
DependencyState

An instance of dep_sync.DependencyState.

InstalledDistributions

Represents the installed distributions within a Python environment. This adds caching to the distribution discovery process for improved performance and should be used instead of the standalone functions when the state of the environment would not change between calls.

Parameters:

Name Type Description Default
sys_path list[str] | None

The list of directories to search for installed distributions, defaulting to sys.path.

None
environment dict[str, str] | None

The marker environment, defaulting to packaging.markers.default_environment.

None

dependencies_satisfied(dependencies: list[Dependency]) -> bool

This should be preferred for simple checks as the discovery process halts when a dependency is not satisfied.

Parameters:

Name Type Description Default
dependencies list[Dependency]

The dependencies to check.

required

Returns:

Type Description
bool

Whether all the dependencies are satisfied.

dependency_state(dependencies: list[Dependency], *, exhaustive: bool = False) -> DependencyState

This should be preferred for more complex checks as it returns the state of all dependencies. If the exhaustive argument is True, the not_required attribute of the returned dep_sync.DependencyState will contain the names of all distributions found in the environment that were not requested. If not, the attribute will be empty.

Parameters:

Name Type Description Default
dependencies list[Dependency]

The dependencies to check.

required
exhaustive bool

Whether to search for all distributions that are not required.

False

Returns:

Type Description
DependencyState

An instance of dep_sync.DependencyState.

get(project_name: str) -> Distribution | None

Parameters:

Name Type Description Default
project_name str

The name of the project.

required

Returns:

Type Description
Distribution | None

The distribution for the given project name, or None if a distribution is not found.

DependencyState

Represents the state of dependencies within a Python environment as returned by the dep_sync.InstalledDistributions.dependency_state method.

missing = tuple(missing) instance-attribute

not_required = tuple(not_required) instance-attribute

satisfied = tuple(satisfied) instance-attribute