pyTooling.Dependency
Implementation of package dependencies.
Hint
See high-level help for explanations and usage examples.
Exceptions
DependencyException: Base-exception of all exceptions raised bypyTooling.Dependency.NoSessionAvailableException: The operation needs a session to the package index, but no session was opened.ProjectNotFoundException: The package index doesn’t know a project of that name.ReleaseNotFoundException: The project exists in the package index, but not in the requested version.
Classes
BrokenRequirementWarning: A requirement carries an environment marker that matches none of the extras declared by the project.ReleaseDetailsWarning: Downloading the details of a release failed, therefore the release was dropped from the project.PackageVersion: The package’s version of aPackage.Package: The package, which exists in multiple versions (PackageVersion).PackageStorage: A storage for packages.PackageDependencyGraph: A package dependency graph collecting all known packages.
Exceptions
- exception pyTooling.Dependency.DependencyException[source]
Base-exception of all exceptions raised by
pyTooling.Dependency.Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Dependency.NoSessionAvailableException[source]
The operation needs a session to the package index, but no session was opened.
A session is created by the package index and handed to the objects it creates.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Dependency.ProjectNotFoundException[source]
The package index doesn’t know a project of that name.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Dependency.ReleaseNotFoundException[source]
The project exists in the package index, but not in the requested version.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
Classes
- class pyTooling.Dependency.BrokenRequirementWarning[source]
A requirement carries an environment marker that matches none of the extras declared by the project.
Such a requirement can’t be assigned to an extra, so it’s not reachable through
Requirements.Inheritance
- property HasNotes: bool
Read-only property to return if the warning has attached notes.
- Returns:
True, if the warning has attached notes.
- property Notes: Tuple[str, ...]
Read-only property to return warning’s attached notes.
- Returns:
Attached notes.
- __cause__
exception cause
- __context__
exception context
- __getattribute__(name, /)
Return getattr(self, name).
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- __reduce__()
Helper for pickle.
- __repr__()
Return repr(self).
- __str__()
Return str(self).
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class pyTooling.Dependency.ReleaseDetailsWarning[source]
Downloading the details of a release failed, therefore the release was dropped from the project.
Inheritance
- property HasNotes: bool
Read-only property to return if the warning has attached notes.
- Returns:
True, if the warning has attached notes.
- property Notes: Tuple[str, ...]
Read-only property to return warning’s attached notes.
- Returns:
Attached notes.
- __cause__
exception cause
- __context__
exception context
- __getattribute__(name, /)
Return getattr(self, name).
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- __reduce__()
Helper for pickle.
- __repr__()
Return repr(self).
- __str__()
Return str(self).
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class pyTooling.Dependency.PackageVersion[source]
The package’s version of a
Package.A
Packagehas multiple available versions. A version can have multiple dependencies to other :class:`PackageVersion`s.Inheritance
- __init__(version, package, releasedAt=None)[source]
Initializes a package version.
- Parameters:
version (
SemanticVersion) – Semantic version of this package.package (
Package) – Package this version is associated to.releasedAt (
Optional[datetime]) – Optional release date and time.
- Raises:
TypeError – When parameter ‘version’ is not of type ‘SemanticVersion’.
TypeError – When parameter ‘package’ is not of type ‘Package’.
TypeError – When parameter ‘releasedAt’ is not of type ‘datetime’.
ToolingException – When version already exists for the associated package.
- Return type:
None
- _version: SemanticVersion
SemanticVersionof this package version.
- _dependsOn: Dict[Package, Dict[SemanticVersion, PackageVersion]]
Versioned dependencies to other packages.
- property Package: Package
Read-only property to access the associated package.
- Returns:
Associated package.
- property Version: SemanticVersion
Read-only property to access the semantic version of a package.
- Returns:
Semantic version of a package.
- property ReleasedAt: datetime | None
Read-only property to access the release date and time.
- Returns:
Optional release date and time.
- property DependsOn: Dict[Package, Dict[SemanticVersion, PackageVersion]]
Read-only property to access the dictionary of dictionaries referencing dependencies.
The outer dictionary key groups dependencies by
Package.
The inner dictionary key accesses dependencies bySemanticVersion.- Returns:
Dictionary of dependencies.
- AddDependencyToPackageVersion(packageVersion)[source]
Add a dependency from current package version to another package version.
- Parameters:
packageVersion (
PackageVersion) – Dependency to be added.- Return type:
- AddDependencyToPackageVersions(packageVersions)[source]
Add multiple dependencies from current package version to a list of other package versions.
- Parameters:
packageVersions (
Iterable[PackageVersion]) – Dependencies to be added.- Return type:
- AddDependencyTo(package, version)[source]
Add a dependency from current package version to another package version.
- Parameters:
package (
str|Package) –Packageobject or name of the package.version (
Union[str,SemanticVersion,Iterable[str|SemanticVersion]]) –SemanticVersionobject or version string or an iterable thereof.
- Return type:
- SortDependencies()[source]
Sort versions of a package and dependencies by version, thus dependency resolution can work on pre-sorted lists and dictionaries.
- Return type:
Self- Returns:
The instance itself (for method-chaining).
- SolveLatest()[source]
Solve the dependency problem, while using preferably latest versions.
Todo
Describe algorithm.
- Return type:
- Returns:
A list of :class:`PackageVersion`s fulfilling the constraints of the dependency problem.
- Raises:
ToolingException – When there is no valid solution to the problem.
- __len__()[source]
Returns the number of dependencies.
- Return type:
- Returns:
Number of dependencies.
- __str__()[source]
Return a string representation of this package version.
- Return type:
- Returns:
The package’s name and version.
- classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
- Parameters:
predicate (
Union[TypeVar(TAttr),Iterable[TypeVar(TAttr)],None]) – An attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- class pyTooling.Dependency.Package[source]
The package, which exists in multiple versions (
PackageVersion).Inheritance
- __init__(name, *, storage)[source]
Initializes a package.
- Parameters:
name (
str) – Name of the package.storage (
PackageStorage) – The package’s storage.
- Return type:
None
- _storage: PackageStorage
Reference to the package’s storage.
- _versions: Dict[SemanticVersion, PackageVersion]
A dictionary of available versions for this package.
- property Storage: PackageStorage
Read-only property to access the package’s storage.
- Returns:
Package storage.
- property Versions: Dict[SemanticVersion, PackageVersion]
Read-only property to access the dictionary of available versions.
- Returns:
Available version dictionary.
- property VersionCount: int
Read-only property to return the number of versions this package has.
- Returns:
Number of versions.
- SortVersions()[source]
Sort versions within this package in reverse order (latest first).
- Return type:
- __len__()[source]
Returns the number of available versions.
- Return type:
- Returns:
Number of versions.
- __getitem__(version)[source]
Access a package version in the package by version string or semantic version.
- Parameters:
version (
str|SemanticVersion) – Version as string or instance.- Return type:
- Returns:
The package version.
- Raises:
KeyError – If version is not available for the package.
- __str__()[source]
Return a string representation of this package.
- Return type:
- Returns:
The package’s name and latest version.
- classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
- Parameters:
predicate (
Union[TypeVar(TAttr),Iterable[TypeVar(TAttr)],None]) – An attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- class pyTooling.Dependency.PackageStorage[source]
A storage for packages.
Inheritance
- __init__(name, graph)[source]
Initializes the package storage.
- Parameters:
name (
str) – Name of the package storage.graph (
PackageDependencyGraph) – PackageDependencyGraph instance (parent).
- Return type:
None
- _graph: PackageDependencyGraph
Reference to the overall dependency graph data structure.
- property Graph: PackageDependencyGraph
Read-only property to access the package dependency graph.
- Returns:
Package dependency graph.
- property Name: str
Read-only property to access the package dependency graph’s name.
- Returns:
Name of the package dependency graph.
- property Packages: Dict[str, Package]
Read-only property to access the dictionary of known packages.
- Returns:
Known packages dictionary.
- property PackageCount: int
Read-only property to return the number of packages in this storage.
- Returns:
Number of packages.
- CreatePackageVersion(packageName, version)[source]
Create a new package and a package version in the package dependency graph.
- Parameters:
- Return type:
- Returns:
New package version instance.
- CreatePackageVersions(packageName, versions)[source]
Create a new package and multiple package versions in the package dependency graph.
- Parameters:
- Return type:
- Returns:
List of new package version instances.
- SortPackageVersions()[source]
Sort versions within all known packages in reverse order (latest first).
- Return type:
- __str__()[source]
Return a string representation of this graph.
- Return type:
- Returns:
The graph’s name and number of known packages.
- classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
- Parameters:
predicate (
Union[TypeVar(TAttr),Iterable[TypeVar(TAttr)],None]) – An attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- class pyTooling.Dependency.PackageDependencyGraph[source]
A package dependency graph collecting all known packages.
Inheritance
- classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
- Parameters:
predicate (
Union[TypeVar(TAttr),Iterable[TypeVar(TAttr)],None]) – An attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __init__(name)[source]
Initializes the package dependency graph.
- Parameters:
name (
str) – Name of the dependency graph.- Return type:
None
- _storages: Dict[str, PackageStorage]
Dictionary of known package storages.
- property Name: str
Read-only property to access the package dependency graph’s name.
- Returns:
Name of the package dependency graph.
- property Storages: Dict[str, PackageStorage]
Read-only property to access the dictionary of known package storages.
- Returns:
Known package storage dictionary.
- SortPackageVersions()[source]
Sort versions within all known packages in reverse order (latest first).
- Return type: