Skip to content

fedrq.backends.base

PackageQueryAlias module-attribute

PackageQueryAlias: TypeAlias = PackageQueryCompat[
    PackageCompat
]

BackendMod

Bases: Protocol

Protocol for a fedrq backend module. Each backend module (e.g. fedrq.backends.dnf.backend) implements this interface.

BACKEND instance-attribute

BACKEND: str

BaseMaker instance-attribute

BaseMaker: type[BaseMakerBase]

NEVRAForms instance-attribute

NEVRAForms: type[NEVRAFormsCompat]

Package instance-attribute

Package: type[PackageCompat]

PackageQuery instance-attribute

PackageQuery: type[PackageQueryCompat]

RepoError instance-attribute

RepoError: type[BaseException]

Repoquery instance-attribute

Repoquery: type[RepoqueryBase]

get_changelogs instance-attribute

get_changelogs: _get_changelogs

get_releasever instance-attribute

get_releasever: Callable[[], str]

BaseMakerBase

BaseMakerBase(base=None)

Create a Base object, set configuration, and load repos

Source code in src/fedrq/backends/base/__init__.py
def __init__(self, base=None) -> None:
    self.base = base

backend abstractmethod property

backend: BackendMod

base instance-attribute

base: Any = base

conf abstractmethod property

conf: Any

Return the backend’s Config object

create_repo abstractmethod

create_repo(repoid: str, **kwargs: Any) -> None

Add a Repo object to the repo sack and configure it.

Parameters:

Name Type Description Default
repoid str

Repository ID

required
kwargs Any

key-values options that should be set on the Repo object values (like $basearch) will be substituted automatically.

{}
Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def create_repo(self, repoid: str, **kwargs: Any) -> None:
    """
    Add a Repo object to the repo sack and configure it.

    Args:
        repoid:
            Repository ID
        kwargs:
            key-values options that should be set on the Repo object values
            (like $basearch) will be substituted automatically.
    """
    ...

disable_repo abstractmethod

disable_repo(
    repo: str, ignore_missing: bool = True
) -> None

Disable a repo by its id. Raise a ValueError if the repoid is not in self.base’s configuration when ignore_missing is False.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def disable_repo(self, repo: str, ignore_missing: bool = True) -> None:
    """
    Disable a repo by its id.
    Raise a ValueError if the repoid is not in `self.base`'s configuration
    when ignore_missing is False.
    """

enable_repo abstractmethod

enable_repo(repo: str) -> None

Enable a repo by its id. Raise a ValueError if the repoid is not in self.base’s configuration.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def enable_repo(self, repo: str) -> None:
    """
    Enable a repo by its id.
    Raise a ValueError if the repoid is not in `self.base`'s configuration.
    """

enable_repos abstractmethod

enable_repos(repos: Collection[str]) -> None

Enable a list of repositories by their repoid. Raise a ValueError if the repoid is not in self.base’s configuration.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def enable_repos(self, repos: Collection[str]) -> None:
    """
    Enable a list of repositories by their repoid.
    Raise a ValueError if the repoid is not in `self.base`'s configuration.
    """

enable_source_repos abstractmethod

enable_source_repos() -> None

Enable the corresponding -source repos of the currently enabled repositories

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def enable_source_repos(self) -> None:
    """
    Enable the corresponding -source repos of the currently enabled
    repositories
    """
    ...

fill_sack abstractmethod

fill_sack(
    *,
    from_cache: bool = False,
    load_system_repo: bool = False
) -> Any

Fill the sack and returns the Base object. The repository configuration shouldn’t be manipulated after this. ‘from_cache’ isn’t currently supported by the libdnf5 backend.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def fill_sack(
    self,
    *,
    from_cache: bool = False,
    load_system_repo: bool = False,
) -> Any:
    """
    Fill the sack and returns the Base object.
    The repository configuration shouldn't be manipulated after this.
    'from_cache' isn't currently supported by the libdnf5 backend.
    """
    ...

load_changelogs abstractmethod

load_changelogs(enable: bool = True) -> None

Load changelog metadata

Parameters:

Name Type Description Default
enable bool

Whether to enable or disable filelists

True
Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def load_changelogs(self, enable: bool = True) -> None:
    """
    Load changelog metadata

    Args:
        enable:
            Whether to enable or disable filelists
    """

load_filelists

load_filelists(enable: bool = True) -> None

Load the filelists if they’re not already enabled by default

Parameters:

Name Type Description Default
enable bool

Whether to enable or disable filelists

True
Source code in src/fedrq/backends/base/__init__.py
def load_filelists(self, enable: bool = True) -> None:  # noqa: ARG002
    # Can be overriden by subclasses. Purposely isn't an @abstractmethod.
    """
    Load the filelists if they're not already enabled by default

    Args:
        enable:
            Whether to enable or disable filelists
    """
    return None

load_release_repos

load_release_repos(
    release: Release, set_releasever: bool = True
) -> None

Load the repositories from a fedrq.config.Release object

Parameters:

Name Type Description Default
release Release

Release object

required
set_releasever bool

Whether to set the $releasever based on the release or just leave it alone

True
Source code in src/fedrq/backends/base/__init__.py
def load_release_repos(self, release: Release, set_releasever: bool = True) -> None:
    """
    Load the repositories from a fedrq.config.Release object

    Args:
        release:
            [`Release`][fedrq.config.Release] object
        set_releasever:
            Whether to set the `$releasever` based on the release or just
            leave it alone
    """
    if set_releasever:
        self.set_var("releasever", release.version)
    if release.release_config.system_repos:
        self.read_system_repos(
            disable=not release.release_config.append_system_repos
        )
    for path in release.release_config.full_def_paths:
        with importlib.resources.as_file(path) as fp:
            LOG.debug("Reading %s", fp)
            self._read_repofile_new(fp)
    release.repog.load(self, release.config, release)

read_repofile abstractmethod

read_repofile(file: StrPath) -> None

Load repositories from a repo file

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def read_repofile(self, file: StrPath) -> None:
    """
    Load repositories from a repo file
    """

read_system_repos abstractmethod

read_system_repos(disable: bool = True) -> None

Load system repositories into the base object. By default, they are all disabled even if ‘enabled=1’ is in the repository configuration.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def read_system_repos(self, disable: bool = True) -> None:
    """
    Load system repositories into the base object.
    By default, they are all disabled even if 'enabled=1' is in the
    repository configuration.
    """

repolist abstractmethod

repolist(enabled: bool | None = None) -> list[str]
Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def repolist(self, enabled: bool | None = None) -> list[str]: ...

set abstractmethod

set(key: str, value: Any) -> None

Set configuration options. Must be called before reading repos.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def set(self, key: str, value: Any) -> None:
    """
    Set configuration options. Must be called before reading repos.
    """
    ...

set_var abstractmethod

set_var(key: str, value: Any) -> None

Set substitutions (e.g. arch, basearch, releasever). Needs to be called before reading repos.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def set_var(self, key: str, value: Any) -> None:
    """
    Set substitutions (e.g. arch, basearch, releasever).
    Needs to be called before reading repos.
    """
    ...

sets

sets(
    conf: dict[str, Any], substitutions: dict[str, Any]
) -> None

Set options on the base object

Parameters:

Name Type Description Default
conf dict[str, Any]

A dict of configuration options. Call self.set() for each k-v pair.

required
substitutions dict[str, Any]

A dict of substitutions/vars options. Call self.set_var() for each k-v pair.

required
Source code in src/fedrq/backends/base/__init__.py
def sets(self, conf: dict[str, Any], substitutions: dict[str, Any]) -> None:
    """
    Set options on the base object

    Args:
        conf:
            A dict of configuration options. Call self.set() for each k-v
            pair.
        substitutions:
            A dict of substitutions/vars options. Call self.set_var() for
            each k-v pair.
    """
    for opt in conf.items():
        self.set(*opt)
    for opt in substitutions.items():
        self.set_var(*opt)

ChangelogEntry dataclass

ChangelogEntry(text: str, author: str, date: date)

Data class for changelog entry data. Do not instantiate directly!

author instance-attribute

author: str

date instance-attribute

date: date

text instance-attribute

text: str

NEVRAFormsCompat

Bases: Protocol

NA instance-attribute

NA: int

NAME instance-attribute

NAME: int

NEV instance-attribute

NEV: int

NEVR instance-attribute

NEVR: int

NEVRA instance-attribute

NEVRA: int

PackageCompat

Common interface provided by dnf.package.Package and other backends

a abstractmethod property

a: str

arch abstractmethod property

arch: str

buildtime abstractmethod property

buildtime: int

conflicts abstractmethod property

conflicts: Iterable

debug_name abstractmethod property

debug_name: str

description abstractmethod property

description: str

downloadsize abstractmethod property

downloadsize: int

e abstractmethod property

e: int

enhances abstractmethod property

enhances: Iterable

epoch abstractmethod property

epoch: int

evr abstractmethod property

evr: str

files abstractmethod property

files: Iterable[str]

from_repo abstractmethod property

from_repo: str

installsize abstractmethod property

installsize: int

installtime abstractmethod property

installtime: int

license abstractmethod property

license: str

location abstractmethod property

location: str

name abstractmethod property

name: str

obsoletes abstractmethod property

obsoletes: Iterable

packager abstractmethod property

packager: str

provides abstractmethod property

provides: Iterable

r abstractmethod property

r: str

reason abstractmethod property

reason: Optional[str]

recommends abstractmethod property

recommends: Iterable

release abstractmethod property

release: str

repo abstractmethod property

repo: Any

Return the package’s Repo object. The exact object depends on which backend is used.

repoid abstractmethod property

repoid: str

reponame abstractmethod property

reponame: str

requires abstractmethod property

requires: Iterable

size abstractmethod property

size: int

source_debug_name abstractmethod property

source_debug_name: str

source_name abstractmethod property

source_name: Optional[str]

sourcerpm abstractmethod property

sourcerpm: Optional[str]

suggests abstractmethod property

suggests: Iterable

summary abstractmethod property

summary: str

supplements abstractmethod property

supplements: Iterable

url abstractmethod property

url: str

v abstractmethod property

v: str

vendor abstractmethod property

vendor: str

version abstractmethod property

version: str

remote_location abstractmethod

remote_location(
    schemes: Collection[str] | None = (
        "http",
        "ftp",
        "file",
        "https",
    )
) -> str | None
Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def remote_location(
    self, schemes: Collection[str] | None = ("http", "ftp", "file", "https")
) -> str | None: ...

PackageQueryCompat

Bases: Generic[_PackageT]

Common PackageQuery interface provided by hawkey.Query and other backends. When using to annotate function parameters and return value, use PackageQueryAlias instead of directly annotating with this type.

filter abstractmethod

filter(**kwargs) -> Self

Filter the PackageQuery. Depending on the backend, this either modifies ‘self’ in place and return ‘self’ or return a new PackageQuery object. See https://dnf.readthedocs.io/en/latest/api_queries.html#dnf.query.Query.filter for the allowed kwargs.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def filter(self, **kwargs) -> Self:
    """
    Filter the PackageQuery.
    Depending on the backend, this either modifies 'self' in place and
    return 'self' or return a new PackageQuery object.
    See https://dnf.readthedocs.io/en/latest/api_queries.html#dnf.query.Query.filter
    for the allowed kwargs.
    """
    ...

filterm abstractmethod

filterm(**kwargs) -> Self

Filter the PackageQuery in place and return ‘self’. See https://dnf.readthedocs.io/en/latest/api_queries.html#dnf.query.Query.filter for the allowed kwargs.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def filterm(self, **kwargs) -> Self:
    """
    Filter the PackageQuery in place and return 'self'.
    See https://dnf.readthedocs.io/en/latest/api_queries.html#dnf.query.Query.filter
    for the allowed kwargs.
    """
    ...

union abstractmethod

union(other: Self) -> Self

Combine two PackageQuery objects. Depending on the backend, this either modifies ‘self’ in place and returns ‘self’ or returns a new PackageQuery object.

Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def union(self: Self, other: Self) -> Self:
    """
    Combine two PackageQuery objects.
    Depending on the backend, this either modifies 'self' in place and
    returns 'self' or returns a new PackageQuery object.
    """
    ...

RepoqueryBase

RepoqueryBase(base)

Bases: Generic[_PackageT]

Helpers to query a repository. Provides a unified repoquery interface for different backends.

Source code in src/fedrq/backends/base/__init__.py
def __init__(self, base) -> None:
    self.base = base

backend abstractmethod property

backend: BackendMod

base instance-attribute

base = base

base_arches abstractmethod property

base_arches: set[str]

Return a set of the system’s arch and basearch.

arch_filter

arch_filter(
    query: PackageQueryCompat,
    arch: str | Iterable[str] | None = None,
) -> PackageQueryCompat[_PackageT]

Filter a query’s architectures and return it. It includes a little more functionality than query.filter(arch=…).

  • When arch is None, the query is left untouched.
  • If arch equals ‘notsrc’, all src and multilib packages are excluded.
  • If arch equals ‘arched’, all noarch, multilib, and source packages are excluded.
  • Otherwise, arch is passed to query.filterm(arch=…) and no other validation is preformed.
Source code in src/fedrq/backends/base/__init__.py
def arch_filter(
    self,
    query: PackageQueryCompat,
    arch: str | Iterable[str] | None = None,
) -> PackageQueryCompat[_PackageT]:
    """
    Filter a query's architectures and return it.
    It includes a little more functionality than query.filter(arch=...).

    - When arch is None, the query is left untouched.
    - If arch equals 'notsrc', all src and multilib packages are
      excluded.
    - If arch equals 'arched', all noarch, multilib, and source
      packages are excluded.
    - Otherwise, arch is passed to query.filterm(arch=...) and no other
      validation is preformed.
    """
    if not arch:
        return query
    if arch == "notsrc":
        return query.filter(arch=(*self.base_arches, "noarch"))  # type: ignore
    if arch == "arched":
        return query.filter(arch=list(self.base_arches))
    return query.filter(arch=arch)

arch_filterm

arch_filterm(
    query: PackageQueryCompat,
    arch: str | Iterable[str] | None = None,
) -> PackageQueryCompat[_PackageT]

Filter a query’s architectures in place and return it. It includes a little more functionality than query.filterm(arch=…).

  • When arch is None, the query is left untouched.
  • If arch equals ‘notsrc’, all src and multilib packages are excluded.
  • If arch equals ‘arched’, all noarch, multilib, and source packages are excluded.
  • Otherwise, arch is passed to query.filterm(arch=…) and no other validation is preformed.
Source code in src/fedrq/backends/base/__init__.py
def arch_filterm(
    self,
    query: PackageQueryCompat,
    arch: str | Iterable[str] | None = None,
) -> PackageQueryCompat[_PackageT]:
    """
    Filter a query's architectures in place and return it.
    It includes a little more functionality than query.filterm(arch=...).

    - When arch is None, the query is left untouched.
    - If arch equals 'notsrc', all src and multilib packages are
      excluded.
    - If arch equals 'arched', all noarch, multilib, and source
      packages are excluded.
    - Otherwise, arch is passed to query.filterm(arch=...) and no other
      validation is preformed.
    """
    if not arch:
        return query
    if arch == "notsrc":
        return query.filterm(arch=(*self.base_arches, "noarch"))  # type: ignore
    elif arch == "arched":
        return query.filterm(arch=self.base.conf.basearch)
    else:
        return query.filterm(arch=arch)

get_package

get_package(
    name: str, arch: str | Iterable[str] | None = None
) -> _PackageT

Return the latest Package that matches the ‘name’ and ‘arch’. A ValueError is raised when no matches are found.

Source code in src/fedrq/backends/base/__init__.py
def get_package(
    self,
    name: str,
    arch: str | Iterable[str] | None = None,
) -> _PackageT:
    """
    Return the latest Package that matches the 'name' and 'arch'.
    A ValueError is raised when no matches are found.
    """
    query = self.query(name=name, arch=arch, latest=1)
    if len(query) < 1:
        raise ValueError(f"Zero packages found for {name} on {arch}")
    return next(iter(query))

get_subpackages

get_subpackages(
    packages: Iterable[PackageCompat], **kwargs
) -> PackageQueryCompat[_PackageT]

Return a PackageQuery containing the binary RPMS/subpackages produced by {packages}.

Parameters:

Name Type Description Default
packages Iterable[PackageCompat]

An interable of PackageCompat containing source packages

required
Source code in src/fedrq/backends/base/__init__.py
def get_subpackages(
    self, packages: Iterable[PackageCompat], **kwargs
) -> PackageQueryCompat[_PackageT]:
    """
    Return a PackageQuery containing the binary RPMS/subpackages produced
    by {packages}.

    Args:
        packages:
            An interable of `PackageCompat` containing source packages
    """
    arch = kwargs.get("arch")
    if arch == "src":
        raise ValueError("{arch} cannot be 'src'")
    elif not arch:
        kwargs.setdefault("arch__neq", "src")
    if val := kwargs.pop("sourcerpm", None):
        warn(f"Removing invalid kwarg: 'sourcerpm={val}")

    for package in packages:
        if package.arch != "src":
            raise ValueError(f"{package} must be a source package.")

    sourcerpms = [
        f"{package.name}-{package.version}-{package.release}.src.rpm"
        for package in packages
    ]
    query = self.query(sourcerpm=sourcerpms, **kwargs)
    return query

query

query(
    *, arch: str | Iterable[str] | None = None, **kwargs
) -> PackageQueryCompat[_PackageT]

Return an inital PackageQuery that’s filtered with **kwargs. Further filtering can be applied with the PackageQuery’s filter and filterm methods.

Source code in src/fedrq/backends/base/__init__.py
def query(
    self,
    *,
    arch: str | Iterable[str] | None = None,
    **kwargs,
) -> PackageQueryCompat[_PackageT]:
    """
    Return an inital PackageQuery that's filtered with **kwargs.
    Further filtering can be applied with the PackageQuery's filter and
    filterm methods.
    """
    if kwargs.get("latest") is None:
        kwargs.pop("latest", None)
    query = self._query()
    query.filterm(**kwargs)
    self.arch_filterm(query, arch)
    return query

resolve_pkg_specs abstractmethod

resolve_pkg_specs(
    specs: Collection[str],
    resolve: bool = False,
    latest: int | None = None,
    with_src: bool = True,
    *,
    with_filenames: bool | None = None,
    with_provides: bool | None = None,
    resolve_provides: bool | None = None
) -> PackageQueryCompat[_PackageT]

Resolve pkg specs. See https://dnf.readthedocs.io/en/latest/command_ref.html?highlight=spec#specifying-packages or https://dnf5.readthedocs.io/en/latest/misc/specs.7.html for valid forms.

Parameters:

Name Type Description Default
specs Collection[str]

Package specs to resolve.

required
resolve bool

Whether to resolve file paths or virtual Provides in addition to package specs

False
latest int | None

Limit packages with the same name and arch.

None
with_src bool

Whether to consider .src packages when resolving specs

True
Source code in src/fedrq/backends/base/__init__.py
@abc.abstractmethod
def resolve_pkg_specs(
    self,
    specs: Collection[str],
    resolve: bool = False,
    latest: int | None = None,
    with_src: bool = True,
    *,
    with_filenames: bool | None = None,
    with_provides: bool | None = None,
    resolve_provides: bool | None = None,
) -> PackageQueryCompat[_PackageT]:
    """
    Resolve pkg specs.
    See
    https://dnf.readthedocs.io/en/latest/command_ref.html?highlight=spec#specifying-packages
    or
    https://dnf5.readthedocs.io/en/latest/misc/specs.7.html
    for valid forms.

    Args:
        specs:
            Package specs to resolve.
        resolve:
            Whether to resolve file paths or virtual Provides in addition
            to package specs
        latest:
            Limit packages with the same name and arch.
        with_src:
            Whether to consider `.src` packages when resolving `specs`
    """
    ...