tmt.libraries package

Submodules

tmt.libraries.beakerlib module

class tmt.libraries.beakerlib.BeakerLib(parent: ~tmt.utils.Common, _logger: ~tmt.log.Logger, identifier: ~tmt.base.core.DependencyFmfId, format: str, repo: ~tmt._compat.pathlib.Path, name: str, dest: ~tmt._compat.pathlib.Path, path: ~tmt._compat.pathlib.Path | None, require: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, recommend: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, default_branch: str | None = None)

Bases: Library

A beakerlib library

Takes care of fetching beakerlib libraries from remote repositories based on provided library identifier described in detail here: https://tmt.readthedocs.io/en/latest/spec/tests.html#require

Libraries are fetched into the ‘libs’ directory under parent’s workdir or into ‘destination’ if provided in the identifier.

default_branch: str | None = None
dest: Path

Target folder into which the library repo is cloned

fetch() None

Fetch the library from the source in the identifier.

property fmf_node_path: Path

Path to fmf node

classmethod from_identifier(*, identifier: DependencySimple | DependencyFmfId | DependencyFile, parent: Common | None = None, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) Library

Factory function to get correct library instance

identifier: DependencyFmfId

The original dependency requested

path: Path | None
recommend: list[DependencySimple | DependencyFmfId | DependencyFile]

List of recommended packages

abstract property ref_formatted: str

Format the library name for debugging.

require: list[DependencySimple | DependencyFmfId | DependencyFile]

List of required packages

source_directory: Path

Source directory where used for files required by the library dependencies

tree: Tree

Fmf tree holding library metadata

class tmt.libraries.beakerlib.BeakerLibFromPath(parent: ~tmt.utils.Common, _logger: ~tmt.log.Logger, identifier: ~tmt.base.core.DependencyFmfId, format: ~typing.Literal['fmf'], repo: ~tmt._compat.pathlib.Path, name: str, dest: ~tmt._compat.pathlib.Path, path: ~tmt._compat.pathlib.Path, require: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, recommend: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, default_branch: str | None = None)

Bases: BeakerLib

A beakerlib library on the local filesystem.

format: Literal['fmf']

Format of the library type requested

classmethod from_identifier(*, identifier: DependencySimple | DependencyFmfId | DependencyFile, parent: Common | None = None, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) BeakerLib

Factory function to get correct library instance

path: Path

Absolute path on the local filesystem pointing to the library

property ref_formatted: str

Format the library name for debugging.

class tmt.libraries.beakerlib.BeakerLibFromUrl(parent: ~tmt.utils.Common, _logger: ~tmt.log.Logger, identifier: ~tmt.base.core.DependencyFmfId, format: ~typing.Literal['rpm', 'fmf'], repo: ~tmt._compat.pathlib.Path, name: str, dest: ~tmt._compat.pathlib.Path, path: ~tmt._compat.pathlib.Path | None = None, require: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, recommend: list[~tmt.base.core.DependencySimple | ~tmt.base.core.DependencyFmfId | ~tmt.base.core.DependencyFile] = <factory>, default_branch: str | None = None, url: str = '', ref: str | None = None)

Bases: BeakerLib

An external beakerlib library fetched from a git url.

format: Literal['rpm', 'fmf']

Format of the library type requested

classmethod from_identifier(*, identifier: DependencySimple | DependencyFmfId | DependencyFile, parent: Common | None = None, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) Library

Factory function to get correct library instance

path: Path | None = None

Path under the git repository pointing to the fmf root

ref: str | None = None

Git revision (branch, tag or commit)

property ref_formatted: str

Format the library name for debugging.

url: str = ''

Full git repository url

tmt.libraries.file module

class tmt.libraries.file.File(parent: Common, _logger: Logger, identifier: DependencyFile, format: Literal['file'], repo: Path, name: str, pattern: list[str], source_location: Path, target_location: Path)

Bases: Library

Required files

Takes care of copying required files for specific test or library, more details here: https://tmt.readthedocs.io/en/latest/spec/tests.html#require

fetch() None

Fetch the library from the source in the identifier.

format: Literal['file']

Format of the library type requested

classmethod from_identifier(*, identifier: DependencySimple | DependencyFmfId | DependencyFile, parent: Common | None = None, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) Library

Factory function to get correct library instance

identifier: DependencyFile

The original dependency requested

pattern: list[str]

Filename paths and regexes which need to be copied

source_location: Path

Root source location of the tests directory of the Discover phase (test_dir)

target_location: Path

Root target location where to copy the file into

Module contents

Handle libraries

class tmt.libraries.Library(parent: Common, _logger: Logger, identifier: DependencySimple | DependencyFmfId | DependencyFile, format: str, repo: Path, name: str)

Bases: ABC

General library class

Used as parent for specific libraries like beakerlib and file

abstractmethod fetch() None

Fetch the library from the source in the identifier.

property fmf_node_path: Path

Path to fmf node

format: str

Format of the library type requested

classmethod from_identifier(*, identifier: DependencySimple | DependencyFmfId | DependencyFile, parent: Common | None = None, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) Library

Factory function to get correct library instance

identifier: DependencySimple | DependencyFmfId | DependencyFile

The original dependency requested

name: str

Fully-qualified name of the library (excluding the repo part).

For example the name used in the rlImport command. Must start with /.

parent: Common

The phase that requested the library as a dependency

repo: Path

Name of the repository where the library came from

exception tmt.libraries.LibraryError

Bases: Exception

Used when library cannot be parsed from the identifier

tmt.libraries.resolve_dependencies(*, original_require: list[DependencySimple | DependencyFmfId | DependencyFile], original_recommend: list[DependencySimple | DependencyFmfId | DependencyFile], parent: Common, logger: Logger, source_location: Path | None = None, target_location: Path | None = None) tuple[list[DependencySimple | DependencyFmfId | DependencyFile], list[DependencySimple | DependencyFmfId | DependencyFile]]

Resolve the require and recommend dependencies.

For each library type encountered do the fetching, recursively resolve the library’s dependencies as well, and forward all of the package dependencies that need to be processed by the PrepareInstall plugin.

The libraries are first processed from the require list and then from the recommend list. Within each dependency list, each library’s dependencies are expanded first before moving to the next dependency on the list.

When encountering duplicate beakerlib libraries, the first library that was resolved takes precedence (this logic is defined in the Beakerlib._do_fetch and the recursion order of this function). For example, starting from the test’s dependencies, the libraries can be resolved as follows:

/test:                          (1)
  ├── library(A/lib)            (2)
  ├── library(B/lib)            (3)
  │   ├── library(A/lib)        (skipped, reuse (2))
  │   └── library(C/lib)        (4)
  └── library(C/lib)            (skipped, reuse (4))