Abstract dnf and libdnf5 code into backends

- Monkeypatch libdnf5.rpm.Package to add back the metadata attributes
  from dnf.
- Monkeypatch libdnf5.rpm.Reldep to have a useful __str__().
- Create a libdnf5.rpm.PackageQuery subclass that includes query() and
  querym() methods for compatability with hawkey.Query. Play around with
  TypedDicts.
- Make fedrq.repoquery.BaseMaker and fedrq.repoquery.Repoquery into
  ABCs that are implemented by both the libdnf5 and dnf backends.
- Copy code from dnf4 to figure out releasever until this functionality
  is exposed in libdnf5's bindings.
- Add types for backends.
- Make loading filelists optional. Vendor `enum.StrEnum`.
- Inteligent backend loading. Avoid importing dnf and libdnf5 into the
  same subprocess.
- Make fedrq.repoquery into a shim module that imports the correct
  members from the default package manager backend.

- Cleanup fedrq.cli.*. Fix --exclude-subpackages to account for
  libdnf5.package.PackageQuery's in place filtering.
- Adjust unit tests to account for dynamic backend loading.

Implements: https://todo.sr.ht/~gotmax23/fedrq/9
This commit is contained in:
Maxwell G 2023-01-13 00:08:57 -06:00
commit f1c66d4591
Signed by: gotmax23
GPG key ID: F79E4E25E8C661F8
29 changed files with 1706 additions and 359 deletions

47
LICENSES/PSF-2.0.txt Normal file
View file

@ -0,0 +1,47 @@
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
1. This LICENSE AGREEMENT is between the Python Software Foundation
("PSF"), and the Individual or Organization ("Licensee") accessing and
otherwise using this software ("Python") in source or binary form and
its associated documentation.
2. Subject to the terms and conditions of this License Agreement, PSF hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python alone or in any derivative version,
provided, however, that PSF's License Agreement and PSF's notice of copyright,
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Python Software Foundation;
All Rights Reserved" are retained in Python alone or in any derivative version
prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python.
4. PSF is making Python available to Licensee on an "AS IS"
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between PSF and
Licensee. This License Agreement does not grant permission to use PSF
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.
8. By copying, installing or otherwise using Python, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.

View file

@ -95,9 +95,11 @@ This project follows the REUSE specification. In general:
licensed.
These are only used when the needed repo defs are not available in the system
config (i.e. for querying the Fedora repos from a non Fedora system).
- `enum.StrEnum` is copied from Cpython 3.11 for older Python versions. It's
~30 lines of PSF-2.0 licensed code.
```
SPDX-License-Identifier: GPL-2.0-or-later AND Unlicense AND MIT
SPDX-License-Identifier: GPL-2.0-or-later AND Unlicense AND MIT AND PSF-2.0
```

View file

@ -1,15 +1,17 @@
# This specfile is licensed under:
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>
Name: fedrq
Version: 0.2.0
Release: 1%{?dist}
Summary: A tool to query the Fedora and EPEL repositories
# - code is GPL-2.0-or-later
# - the data and config files in fedrq/config are UNLICENSEed
# - the data and config files in fedrq/data are UNLICENSEed
# - Embeded repo defs are MIT.
License: GPL-2.0-or-later AND Unlicense AND MIT
# - PSF-2.0 code copied from Cpython 3.11 for older Python versions
License: GPL-2.0-or-later AND Unlicense AND MIT AND PSF-2.0
URL: https://git.sr.ht/~gotmax23/fedrq
Source: %{url}/refs/download/v%{version}/fedrq-%{version}.tar.gz
@ -46,8 +48,8 @@ fedrq is a tool to query the Fedora and EPEL repositories.
%build
%pyproject_wheel
scdoc < doc/fedrq.1.scd > fedrq.1
scdoc < doc/fedrq.5.scd > fedrq.5
scdoc <doc/fedrq.1.scd >fedrq.1
scdoc <doc/fedrq.5.scd >fedrq.5
%install

View file

@ -27,6 +27,6 @@ run isort --add-import "from __future__ import annotations" ${c} src/fedrq/
run isort ${c} tests/
run black ${c} src/fedrq tests/
run flake8 --max-line-length 89 src/fedrq/
run mypy src/fedrq/
run mypy --enable-incomplete-feature=Unpack src/fedrq/
run reuse lint
exit $r

View file

@ -71,7 +71,7 @@ def install_system(
@nox.session(venv_params=["--system-site-packages"])
def test(session: nox.Session):
install_system(session, "createrepo_c", "rpm-build", "python3-rpm")
install(session, ".[test]", editable=True)
install(session, ".[test]", "pytest-xdist", editable=True)
posargs = session.posargs
if "--check" in posargs:
posargs.remove("--check")
@ -80,7 +80,10 @@ def test(session: nox.Session):
"-m",
"pytest",
*session.posargs,
env={"PYTEST_PLUGINS": "pytest_mock", "PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1"},
env={
"PYTEST_PLUGINS": "xdist.plugin,pytest_mock",
"PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
},
)
@ -114,7 +117,9 @@ def codeql(session: nox.Session):
@nox.session(venv_params=["--system-site-packages"])
def typing(session: nox.Session):
install(session, ".", "tomli_w", "mypy", editable=True)
session.run("python", "-m", "mypy", "src/fedrq/")
session.run(
"python", "-m", "mypy", "--enable-incomplete-feature=Unpack", "src/fedrq/"
)
@nox.session

View file

@ -31,7 +31,7 @@ classifiers = [
dependencies = [
# This cannot be installed from PyPI
# "dnf",
"pydantic",
"pydantic ~= 1.0",
"tomli; python_version<'3.11'",
# Optional dependency for `fedrq check-config --dump`
# "tomli-w",
@ -47,12 +47,12 @@ lint = [
"reuse",
# Optional fedrq runtime dependency
"tomli-w",
"typing_extensions",
]
test = [
"pytest",
"pytest-mock",
"tomli-w",
"typing_extensions",
]
dev = [
"fedrq[test]",
@ -79,11 +79,11 @@ include = [
# To comply with the license, its must be included in the wheel.
directory = ".data"
[tool.mypy]
plugins = ["pydantic.mypy"]
# [tool.mypy]
# plugins = ["pydantic.mypy"]
[[tool.mypy.overrides]]
module = ["dnf.*", "hawkey.*"]
module = ["dnf.*", "hawkey.*", "libdnf5.*", "rpm.*"]
ignore_missing_imports = true

View file

@ -5,14 +5,6 @@ from __future__ import annotations
import logging
from fedrq import _utils, config, repoquery
format = "{levelname}:{name}: {message}"
logging.basicConfig(format=format, style="{")
logger = logging.getLogger("fedrq")
__all__ = (
"config",
"_utils",
"repoquery",
)

51
src/fedrq/_compat.py Normal file
View file

@ -0,0 +1,51 @@
from __future__ import annotations
import sys
if sys.version_info < (3, 11):
# if True:
# SPDX-License-Identifier: PSF-2.0
# Copyright (c) 2001-2023 Python Software Foundation
from enum import Enum
from typing import Any, TypeVar
_S = TypeVar("_S", bound="StrEnum")
class StrEnum(str, Enum):
"""
Enum where members are also (and must be) strings
"""
def __new__(cls: type[_S], *values: str) -> _S:
if len(values) > 3:
raise TypeError("too many arguments for str(): %r" % (values,))
if len(values) == 1:
# it must be a string
if not isinstance(values[0], str):
raise TypeError("%r is not a string" % (values[0],))
if len(values) >= 2:
# check that encoding argument is a string
if not isinstance(values[1], str):
raise TypeError("encoding must be a string, not %r" % (values[1],))
if len(values) == 3:
# check that errors argument is a string
if not isinstance(values[2], str):
raise TypeError("errors must be a string, not %r" % (values[2]))
value = str(*values)
member = str.__new__(cls, value)
member._value_ = value
return member
__str__ = str.__str__
@staticmethod
def _generate_next_value_(
name: str, start: int, count: int, last_values: list[Any]
) -> str:
"""
Return the lower-cased version of the member name.
"""
return name.lower()
else:
from enum import StrEnum

View file

@ -1,19 +0,0 @@
# SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
try:
import dnf # noqa
import hawkey # noqa
except ImportError:
HAS_DNF = False
dnf = None
hawkey = None
else:
HAS_DNF = True
def needs_dnf() -> None:
if not HAS_DNF:
raise RuntimeError("python3-dnf is not installed.")

View file

@ -7,7 +7,6 @@ import logging
import typing as t
if t.TYPE_CHECKING:
import dnf
import hawkey
@ -20,7 +19,7 @@ def get_source_name(package: dnf.package.Package) -> str:
def filter_latest(query: hawkey.Query, latest: t.Optional[int]) -> None:
logger.debug("filter_latest(query={}, latest={})".format(tuple(query), latest))
# logger.debug("filter_latest(query={}, latest={})".format(tuple(query), latest))
if latest:
query.filterm(latest=latest)

View file

@ -0,0 +1,89 @@
# SPDX-FileCopyrightText: 2022 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
"""
fedrq supports dnf and libdnf5. Importing both in the same process doesn't
work, so we use some finagling to dynmaically load the requested backend.
"""
from __future__ import annotations
import functools
import logging
import warnings
from typing import TYPE_CHECKING
from fedrq.backends import dnf, libdnf5
if TYPE_CHECKING:
from types import ModuleType
from .base import BackendMod
class MissingBackendError(Exception):
pass
BACKENDS: dict[str, ModuleType] = {
"dnf": dnf,
"libdnf5": libdnf5,
}
DEFAULT_BACKEND = "dnf"
LOG = logging.getLogger(__name__)
class Backends:
def __init__(self) -> None:
self.available: dict[str, ModuleType] = {}
self.missing: dict[str, MissingBackendError] = {}
for name, mod in BACKENDS.items():
try:
mod.ensure_backend()
except MissingBackendError as exc:
self.missing[name] = exc
else:
self.available[name] = mod
@functools.lru_cache
def _get_backends() -> Backends:
return Backends()
class _DefaultBackend:
def __init__(self) -> None:
self.backend: BackendMod | None = None
def __call__(
self, default: str | None = None, fallback: bool = False
) -> BackendMod:
if not self.backend:
self.backend = self._get_backend(default, fallback)
LOG.info("Using %s backend", self.backend.BACKEND)
elif default and default != self.backend.BACKEND:
warnings.warn(
f"Falling back to {self.backend.BACKEND}. {default} cannot be used."
)
return self.backend
def _get_backend(
self, default: str | None = None, fallback: bool = False
) -> BackendMod:
default = default or DEFAULT_BACKEND
if default not in BACKENDS:
raise MissingBackendError(f"Invalid backend {default!r}.")
backends = _get_backends()
if backend := backends.available.get(default):
return backend._get_backend()
if not fallback:
raise backends.missing[default]
if backend := next(iter(backends.available.values()), None):
return backend._get_backend()
_split = ", ".join(backends.missing)
raise MissingBackendError(
f"Neither of the following backends were available: {_split}"
)
get_default_backend = _DefaultBackend()

388
src/fedrq/backends/base.py Normal file
View file

@ -0,0 +1,388 @@
# SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
import abc
import importlib.resources
import logging
from collections.abc import Callable, Collection, Iterable, Iterator
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, runtime_checkable
from warnings import warn
if TYPE_CHECKING:
from _typeshed import StrPath
from fedrq.config import Release
_QueryT = TypeVar("_QueryT", bound="PackageQueryCompat")
LOG = logging.getLogger("fedrq.backends")
@runtime_checkable
class PackageCompat(Protocol):
@property
def name(self) -> str:
...
@property
def arch(self) -> str:
...
@property
def a(self) -> str:
...
@property
def epoch(self) -> int:
...
@property
def e(self) -> int:
...
@property
def version(self) -> str:
...
@property
def v(self) -> str:
...
@property
def release(self) -> str:
...
@property
def r(self) -> str:
...
@property
def from_repo(self) -> str:
...
@property
def evr(self) -> str:
...
@property
def debug_name(self) -> str:
...
@property
def source_name(self) -> str | None:
...
@property
def source_debug_name(self) -> str:
...
@property
def installtime(self) -> int:
...
@property
def buildtime(self) -> int:
...
@property
def size(self) -> int:
...
@property
def downloadsize(self) -> int:
...
@property
def installsize(self) -> int:
...
@property
def provides(self) -> Iterable:
...
@property
def requires(self) -> Iterable:
...
@property
def recommends(self) -> Iterable:
...
@property
def suggests(self) -> Iterable:
...
@property
def supplements(self) -> Iterable:
...
@property
def enhances(self) -> Iterable:
...
@property
def obsoletes(self) -> Iterable:
...
@property
def conflicts(self) -> Iterable:
...
@property
def sourcerpm(self) -> str:
...
@property
def description(self) -> str:
...
@property
def summary(self) -> str:
...
@property
def license(self) -> str:
...
@property
def url(self) -> str:
...
@property
def reason(self) -> str | None:
...
@property
def files(self) -> Iterable[str]:
...
@property
def reponame(self) -> str:
...
@property
def repoid(self) -> str:
...
@property
def vendor(self) -> str:
...
@property
def packager(self) -> str:
...
@runtime_checkable
class PackageQueryCompat(Protocol):
def filter(self, **kwargs) -> PackageQueryCompat:
...
def filterm(self, **kwargs) -> PackageQueryCompat:
...
def union(self: _QueryT, other: _QueryT) -> _QueryT:
...
def __len__(self) -> int:
...
def __iter__(self) -> Iterator[PackageCompat]:
...
class BaseMakerBase(abc.ABC):
"""
Create a Base object and load repos
"""
base: Any
def __init__(self, base=None) -> None:
...
@abc.abstractmethod
def fill_sack(
self,
*,
from_cache: bool = False,
load_system_repo: bool = False,
):
"""
Fill the sack and returns the Base object.
The repository configuration shouldn't be manipulated after this.
Note that the `_cachedir` arg is private and subject to removal.
"""
@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.
"""
@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.
"""
@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.
"""
@abc.abstractmethod
def read_repofile(self, file: StrPath) -> None:
"""
Load repositories from a repo file
"""
@abc.abstractmethod
def set(self, key: str, value: Any) -> None:
"""
Set configuration options.
Must be called before set_var() and before reading repos.
"""
...
@abc.abstractmethod
def set_var(self, key: str, value: Any) -> None:
"""
Set substitutions (e.g. arch, basearch, releasever).
Needs to be called after all options have been set() (if any)
and before reading repos.
"""
...
def load_filelists(self) -> None:
# Can be overriden by subclasses. Purposely isn't an @abstractmethod.
pass
def load_release_repos(self, release: Release) -> None:
if release.release_config.system_repos:
self.read_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((str(fp)))
LOG.debug("Enabling repos: %s", release.repos)
self.enable_repos(release.repos)
class RepoqueryBase(abc.ABC):
"""
Helpers to query a repository.
Provides a unified interface for different backends.
"""
def __init__(self, base) -> None:
self.base = base
@property
@abc.abstractmethod
def base_arches(self) -> set[str]:
...
@abc.abstractmethod
def resolve_pkg_specs(
self,
specs: Collection[str],
resolve: bool = False,
latest: int | None = None,
with_src: bool = True,
) -> PackageQueryCompat:
...
def arch_filterm(
self, query: PackageQueryCompat, arch: str | Iterable[str] | None = None
) -> PackageQueryCompat:
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)
def arch_filter(
self, query: PackageQueryCompat, arch: str | Iterable[str] | None = None
) -> PackageQueryCompat:
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)
@abc.abstractmethod
def _query(self) -> PackageQueryCompat:
return self.base.sack.query()
def query(
self, *, arch: str | Iterable[str] | None = None, **kwargs
) -> PackageQueryCompat:
if kwargs.get("latest", "UNDEFINED") is None:
kwargs.pop("latest")
query = self._query()
query.filterm(**kwargs)
self.arch_filterm(query, arch)
return query
def get_package(
self,
name: str,
arch: str | Iterable[str] | None = None,
) -> PackageCompat:
query = self.query(name=name, arch=arch, latest=1)
if len(query) < 1:
raise RuntimeError(f"Zero packages found for {name} on {arch}")
return next(iter(query))
def get_subpackages(
self, packages: Iterable[PackageCompat], **kwargs
) -> PackageQueryCompat:
"""
Return a hawkey.Query containing the binary RPMS/subpackages produced
by {packages}.
:param package: A :class:`PackageQueryCompat` containing source packages
:arch package: Set this to filter out subpackages with a specific arch
"""
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
class BackendMod(Protocol):
"""
Protocol for a backend module
"""
get_releasever: Callable[[], str]
BaseMaker: type[BaseMakerBase]
Repoquery: type[RepoqueryBase]
BACKEND: str

View file

@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
import importlib.util
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types import ModuleType
BACKEND = "dnf"
NEEDS = ("dnf", "hawkey")
def ensure_backend() -> None:
from fedrq.backends import MissingBackendError
needs = ", ".join(NEEDS)
for req in NEEDS:
if not importlib.util.find_spec(req):
raise MissingBackendError(f"Backend {BACKEND!r} requires {needs}")
def _get_backend() -> ModuleType:
from . import backend
return backend

View file

@ -0,0 +1,142 @@
# SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
import logging
import typing as t
from collections.abc import Collection
from fedrq._utils import filter_latest
from fedrq.backends import MissingBackendError
from fedrq.backends.base import BaseMakerBase, RepoqueryBase
from fedrq.backends.dnf import BACKEND
try:
import dnf
except ImportError:
raise MissingBackendError from None
if t.TYPE_CHECKING:
from _typeshed import StrPath
LOG = logging.getLogger(__name__)
class BaseMaker(BaseMakerBase):
"""
Create a Base object and load repos
"""
base: dnf.Base
def __init__(self, base: dnf.Base | None = None) -> None:
"""
Initialize and configure the base object.
"""
self.base: dnf.Base = base or dnf.Base()
@property
def conf(self) -> dnf.conf.MainConf:
return self.base.conf
def set(self, key: str, value: t.Any) -> None:
# self.conf.set_or_append_opt_value(key, value)
setattr(self.conf, key, value)
def set_var(self, key: str, value: t.Any) -> None:
self.set(key, value)
def fill_sack(
self,
*,
from_cache: bool = False,
load_system_repo: bool = False,
) -> dnf.Base:
"""
Fill the sack and returns the dnf.Base object.
The repository configuration shouldn't be manipulated after this.
Note that the `_cachedir` arg is private and subject to removal.
"""
if from_cache:
self.base.fill_sack_from_repos_in_cache(load_system_repo=load_system_repo)
else:
self.base.fill_sack(load_system_repo=load_system_repo)
return self.base
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.
"""
self.base.read_all_repos()
if not disable:
return None
for repo in self.base.repos.iter_enabled():
repo.disable()
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.
"""
for repo in repos:
self.enable_repo(repo)
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.
"""
if repo_obj := self.base.repos.get_matching(repo):
repo_obj.enable()
else:
raise ValueError(f"{repo} repo definition was not found.")
def read_repofile(self, file: StrPath) -> None:
rr = dnf.conf.read.RepoReader(self.base.conf, None)
for repo in rr._get_repos(str(file)):
self.base.repos.add(repo)
class Repoquery(RepoqueryBase):
def __init__(self, base: dnf.Base) -> None:
self.base: dnf.Base = base
@property
def base_arches(self) -> set[str]:
return {self.base.conf.arch, self.base.conf.basearch}
def _query(self) -> dnf.query.Query:
return self.base.sack.query()
def resolve_pkg_specs(
self,
specs: Collection[str],
resolve: bool = False,
latest: int | None = None,
with_src: bool = True,
) -> dnf.query.Query:
...
LOG.debug(f"specs={specs}, resolve={resolve}, latest={latest}")
query = self.query(empty=True)
for p in specs:
subject = dnf.subject.Subject(p).get_best_query(
self.base.sack,
with_provides=resolve,
with_filenames=resolve,
with_src=with_src,
)
query = query.union(subject)
# LOG.debug(f"subject query: {tuple(subject)}")
filter_latest(query, latest)
return query
def get_releasever():
return dnf.rpm.detect_releasever("/")
__all__ = ("BACKEND", "BaseMaker", "Repoquery", "get_releasever")

View file

@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
import importlib.util
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types import ModuleType
BACKEND = "libdnf5"
NEEDS = ("libdnf5",)
def ensure_backend() -> None:
from fedrq.backends import MissingBackendError
needs = ", ".join(NEEDS)
for req in NEEDS:
if not importlib.util.find_spec(req):
raise MissingBackendError(f"Backend {BACKEND!r} requires {needs}")
def _get_backend() -> ModuleType:
from . import backend
return backend

View file

@ -0,0 +1,629 @@
# SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import annotations
import logging
import typing as t
from collections.abc import Collection, Iterable
from fedrq._utils import filter_latest
from fedrq.backends import MissingBackendError
from fedrq.backends.base import BaseMakerBase, RepoqueryBase
from fedrq.backends.libdnf5 import BACKEND # noqa: F401
if t.TYPE_CHECKING:
from _typeshed import StrPath
from typing_extensions import TypeAlias, Unpack
try:
import libdnf5
import rpm
except ImportError as exc:
raise MissingBackendError(str(exc)) from None
LOG = logging.getLogger(__name__)
Priority_RUNTIME = libdnf5.conf.Option.Priority_RUNTIME
StrIter = t.Union[list[str], tuple[str], str]
IntIter = t.Union[list[int], tuple[int], int]
CONVERT_TO_LIST = (str, int)
class QueryFilterKwargs(t.TypedDict, total=False):
name: t.Union[StrIter, libdnf5.rpm.PackageSet]
name__eq: t.Union[StrIter, libdnf5.rpm.PackageSet]
name__neq: t.Union[StrIter, libdnf5.rpm.PackageSet]
name__glob: StrIter
name__contains: StrIter
epoch: t.Union[StrIter, IntIter]
epoch__eq: t.Union[StrIter, IntIter]
epoch__neq: t.Union[StrIter, IntIter]
epoch__glob: StrIter
epoch__gt: IntIter
epoch__lt: IntIter
epoch__lte: IntIter
epoch__gte: IntIter
version: StrIter
version__eq: StrIter
version__neq: StrIter
version__glob: StrIter
version__gt: StrIter
version__lt: StrIter
version__gte: StrIter
version__lte: StrIter
release: StrIter
release__eq: StrIter
release__neq: StrIter
release__glob: StrIter
release__gt: StrIter
release__lt: StrIter
release__gte: StrIter
release__lte: StrIter
arch: StrIter
arch__eq: StrIter
arch__neq: StrIter
arch__glob: StrIter
sourcerpm: StrIter
sourcerpm__eq: StrIter
sourcerpm__neq: StrIter
sourcerpm__glob: StrIter
url: StrIter
url__eq: StrIter
url__neq: StrIter
url__glob: StrIter
url__contains: StrIter
summary: StrIter
summary__eq: StrIter
summary__neq: StrIter
summary__glob: StrIter
summary__contains: StrIter
description: StrIter
description__eq: StrIter
description__neq: StrIter
description__glob: StrIter
description__contains: StrIter
provides: t.Union[StrIter, libdnf5.rpm.ReldepList]
provides__eq: t.Union[StrIter, libdnf5.rpm.ReldepList]
provides__neq: t.Union[StrIter, libdnf5.rpm.ReldepList]
provides__glob: StrIter
requires: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
requires__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
requires__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
requires__glob: StrIter
conflicts: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
conflicts__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
conflicts__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
conflicts__glob: StrIter
obsoletes: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
obsoletes__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
obsoletes__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
obsoletes__glob: StrIter
recommends: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
recommends__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
recommends__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
recommends__glob: StrIter
suggests: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
suggests__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
suggests__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
suggests__glob: StrIter
enhances: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
enhances__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
enhances__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
enhances__glob: StrIter
supplements: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
supplements__eq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
supplements__neq: t.Union[StrIter, libdnf5.rpm.ReldepList, libdnf5.rpm.PackageSet]
supplements__glob: StrIter
file: StrIter
file__eq: StrIter
file__neq: StrIter
file__glob: StrIter
file__contains: StrIter
latest: int
latest_per_arch: int
downgrades: bool
empty: bool
reponame: StrIter
reponame__eq: StrIter
reponame__neq: StrIter
reponame__glob: StrIter
reponame__contains: StrIter
pkg: Iterable[libdnf5.rpm.Package]
pkg__eq: Iterable[libdnf5.rpm.Package]
pkg__neq: Iterable[libdnf5.rpm.Package]
class BaseMaker(BaseMakerBase):
"""
Create a Base object and load repos
"""
base: libdnf5.base.Base
def __init__(
self, base: libdnf5.base.Base | None = None, *, initialized=False
) -> None:
"""
Initialize and configure the base object.
:param base: Pass in a :class:`libdnf.base.Base object` to configure
instead of creating a new one.
:param initialized: Set to True if base.setup() has already been
called.
"""
self.base = base or libdnf5.base.Base()
self.initialized = initialized if base else False
if not base:
self.base.load_config_from_file()
def setup(self) -> None:
if not self.initialized:
self.base.setup()
self.initialized = True
@property
def config(self) -> libdnf5.config.ConfigMain:
return self.base.get_config()
def set(self, key: str, value: t.Any) -> None:
# if self.initialized:
# raise RuntimeError("The base object has already been initialized")
LOG.debug("Setting config option %s=%r", key, value)
option_obj = getattr(self.config, key, None)
if not callable(option_obj):
raise ValueError(f"{key!r} is not a valid option.")
option_obj().set(Priority_RUNTIME, value)
def set_var(self, key: str, value: t.Any) -> None:
self.base.get_vars().set(key, value)
@property
def rs(self) -> libdnf5.repo.RepoSackWeakPtr:
self.setup()
return self.base.get_repo_sack()
def fill_sack(
self,
*,
from_cache: bool = False,
load_system_repo: bool = False,
) -> libdnf5.base.Base:
"""
Fill the sack and returns the Base object.
The repository configuration shouldn't be manipulated after this.
Note that the `_cachedir` arg is private and subject to removal.
"""
if from_cache:
raise NotImplementedError
self.rs.update_and_load_enabled_repos(load_system_repo)
return self.base
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.
"""
self.rs.create_repos_from_system_configuration()
if disable:
repoq = libdnf5.repo.RepoQuery(self.base)
repoq.filter_enabled(True)
for repo in repoq:
repo.disable()
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.
"""
for repo in repos:
self.enable_repo(repo)
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.
"""
repoq = libdnf5.repo.RepoQuery(self.base)
repoq.filter_id(repo, libdnf5.common.QueryCmp_GLOB)
if not repoq:
raise ValueError(f"{repo} repo definition was not found.")
for repo in repoq:
repo.enable() # type: ignore
def read_repofile(self, file: StrPath) -> None:
"""
Load repositories from a repo file
"""
self.rs.create_repos_from_file(str(file))
def load_filelists(self) -> None:
LOG.debug("Loading filelists")
option: libdnf5.conf.OptionStringSet = self.config.optional_metadata_types()
option.add_item(libdnf5.conf.METADATA_TYPE_FILELISTS)
class Package(libdnf5.rpm.Package):
DEBUGINFO_SUFFIX = "-debuginfo"
DEBUGSOURCE_SUFFIX = "-debugsource"
@property
def name(self) -> str:
return self.get_name()
@property
def arch(self) -> str:
return self.get_arch()
@property
def a(self) -> str:
return self.get_arch()
@property
def epoch(self) -> int:
return int(self.get_epoch())
@property
def e(self) -> int:
return self.epoch
@property
def version(self) -> str:
return self.get_version()
@property
def v(self) -> str:
return self.version
@property
def release(self) -> str:
return self.get_release()
@property
def r(self) -> str:
return self.release
@property
def from_repo(self) -> str:
return self.get_from_repo_id()
@property
def evr(self) -> str:
return self.get_evr()
@property
def debug_name(self) -> str:
# Taken from dnf.package.Package
# Copyright (C) 2012-2016 Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later
"""
Returns name of the debuginfo package for this package.
If this package is a debuginfo package, returns its name.
If this package is a debugsource package, returns the debuginfo package
for the base package.
e.g. kernel-PAE -> kernel-PAE-debuginfo
"""
if self.name.endswith(self.DEBUGINFO_SUFFIX):
return self.name
name = self.name
if self.name.endswith(self.DEBUGSOURCE_SUFFIX):
name = name[: -len(self.DEBUGSOURCE_SUFFIX)]
return name + self.DEBUGINFO_SUFFIX
@property
def source_name(self) -> str | None:
# def source_name(self) -> str:
return None if self.arch == "src" else self.get_source_name()
# return self.get_source_name()
@property
def source_debug_name(self) -> str:
source_name = self.name if self.arch == "src" else self.source_name
return source_name + self.DEBUGSOURCE_SUFFIX # type: ignore[operator]
@property
def installtime(self) -> int:
return self.get_install_time()
@property
def buildtime(self) -> int:
return self.get_build_time()
@property
def size(self) -> int:
return self.get_package_size()
@property
def downloadsize(self) -> int:
return self.get_package_size()
@property
def installsize(self) -> int:
return self.get_install_size()
@property
def provides(self) -> Iterable[Reldep5]:
return self.get_provides()
@property
def requires(self) -> Iterable[Reldep5]:
return self.get_requires()
@property
def recommends(self) -> Iterable[Reldep5]:
return self.get_recommends()
@property
def suggests(self) -> Iterable[Reldep5]:
return self.get_suggests()
@property
def supplements(self) -> Iterable[Reldep5]:
return self.get_supplements()
@property
def enhances(self) -> Iterable[Reldep5]:
return self.get_enhances()
@property
def obsoletes(self) -> Iterable[Reldep5]:
return self.get_obsoletes()
@property
def conflicts(self) -> Iterable[Reldep5]:
return self.get_conflicts()
@property
def sourcerpm(self) -> str:
return self.get_sourcerpm()
@property
def description(self) -> str:
return self.get_description()
@property
def summary(self) -> str:
return self.get_summary()
@property
def license(self) -> str:
return self.get_license()
@property
def url(self) -> str:
return self.get_url()
@property
def reason(self) -> str:
reason = self.get_reason()
reason_str = libdnf5.transaction.transaction_item_reason_to_string(reason)
return reason_str
@property
def files(self) -> Iterable[str]:
return self.get_files()
@property
def reponame(self) -> str:
return self.get_repo_id()
@property
def repoid(self) -> str:
return self.get_repo_id()
@property
def vendor(self) -> str:
return self.get_vendor()
@property
def packager(self) -> str:
return self.get_packager()
def __repr__(self) -> str:
return f"{self.__class__.__name__}<{str(self)}>"
def __str__(self) -> str:
return self.get_nevra()
libdnf5._rpm.Package_swigregister(Package)
class Reldep5(libdnf5.rpm.Reldep):
def __str__(self) -> str:
return self.to_string()
libdnf5._rpm.Reldep_swigregister(Reldep5)
class PackageQuery(libdnf5.rpm.PackageQuery):
__rq__: Repoquery
def _filter( # type: ignore[override]
self,
**kwargs: Unpack[QueryFilterKwargs],
) -> None:
filter_mapping = {
"latest": "latest_evr",
"latest_per_arch": "latest_evr",
"reponame": "repo_id",
}
comp_mapping: dict[str, int] = {
"eq": libdnf5.common.QueryCmp_EQ,
"neq": libdnf5.common.QueryCmp_NEQ,
"glob": libdnf5.common.QueryCmp_GLOB,
"contains": libdnf5.common.QueryCmp_NOT_CONTAINS,
"gt": libdnf5.common.QueryCmp_GT,
"gte": libdnf5.common.QueryCmp_GTE,
"lt": libdnf5.common.QueryCmp_LT,
"lte": libdnf5.common.QueryCmp_LTE,
}
invalid = []
for key in kwargs:
if key not in QueryFilterKwargs.__annotations__:
invalid.append(key)
if invalid:
raise TypeError(f"Invalid keyword arguments: {invalid}")
if kwargs.pop("empty", None):
self.clear()
return None
if kwargs.pop("downgrades", None):
self.filter_downgrades()
for key, value in kwargs.items():
split = key.rsplit("__", 1)
name = "filter_" + filter_mapping.get(split[0], split[0])
args = [_convert_value(key, value)]
if len(split) == 2:
args.append(comp_mapping[split[1]])
getattr(self, name)(*args)
def filterm( # type: ignore[override]
self,
**kwargs: Unpack[QueryFilterKwargs],
) -> PackageQuery:
self._filter(**kwargs)
return self
def filter( # type: ignore[override]
self,
**kwargs: Unpack[QueryFilterKwargs],
) -> PackageQuery:
self._filter(**kwargs)
return self
def __len__(self) -> int:
return self.size()
def union(self, other: PackageQuery) -> PackageQuery:
self.update(other)
return self
def __ior__(self, other: PackageQuery) -> PackageQuery:
return self.union(other)
_pkg_comps: TypeAlias = (
"t.Union[libdnf5.common.QueryCmp_EQ, libdnf5.common.QueryCmp_NEQ]"
)
def filter_pkg(
self,
pkgs: Iterable[libdnf5.rpm.Package],
comp: _pkg_comps = libdnf5.common.QueryCmp_EQ,
/,
):
if hasattr(self, "__rq__"):
base = self.__rq__.base
else:
base = self.get_base()
newquery = libdnf5.rpm.PackageSet(base)
newquery.clear()
for p in pkgs:
newquery.add(p)
if comp == libdnf5.common.QueryCmp_EQ:
self.intersection(newquery)
elif comp == libdnf5.common.QueryCmp_NEQ:
self.difference(newquery)
else:
raise ValueError()
def __str__(self) -> str:
return f"{self.__class__.__name__}<{tuple(self)}>"
ValT = t.TypeVar("ValT")
def _convert_value(key: str, value: ValT) -> t.Union[list[ValT], ValT]:
d_annotations = t.get_type_hints(QueryFilterKwargs)
annotation = d_annotations[key]
if t.get_origin(annotation) is not t.Union or not any(
isinstance(value, typ) for typ in CONVERT_TO_LIST
):
return value
union_types = t.get_args(annotation)
pairs = [(t.get_origin(arg), t.get_args(arg)) for arg in union_types]
for origin, sargs in pairs:
assert isinstance(origin, type)
if not issubclass(origin, list):
continue
if t.get_origin(sargs[0]) is t.Union:
pairs = [(t.get_origin(arg), t.get_args(arg)) for arg in union_types]
for origin, sargs in pairs:
assert isinstance(origin, type)
if issubclass(origin, list) and isinstance(value, sargs[0]):
return [value]
if isinstance(value, sargs[0]):
return [value]
return value
class Repoquery(RepoqueryBase):
def __init__(self, base: libdnf5.base.Base) -> None:
self.base: libdnf5.base.Base = base
@property
def base_arches(self) -> set[str]:
base_vars = self.base.get_vars()
return {base_vars.get_value("arch"), base_vars.get_value("basearch")}
def _query(self) -> PackageQuery:
obj = PackageQuery(self.base)
obj.__rq__ = self
return obj
def query(
self, *, arch: str | Iterable[str] | None = None, **kwargs
) -> PackageQuery:
return t.cast(PackageQuery, super().query(arch=arch, **kwargs))
def resolve_pkg_specs(
self,
specs: Collection[str],
resolve: bool = False,
latest: int | None = None,
with_src: bool = True,
) -> PackageQuery:
settings = libdnf5.base.ResolveSpecSettings()
settings.with_filenames = resolve
settings.with_provides = resolve
r_query = self.query(empty=True)
for spec in specs:
query = self._query()
query.resolve_pkg_spec(spec, settings, with_src)
r_query.union(query)
filter_latest(r_query, latest)
return r_query
def get_releasever() -> str:
base = libdnf5.base.Base()
base.load_config_from_file()
base.setup()
return base.get_vars().get_value("releasever")

View file

@ -12,7 +12,7 @@ import logging
import sys
from functools import wraps
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any
try:
import tomli_w
@ -23,8 +23,8 @@ else:
from pydantic import ValidationError
from fedrq._dnf import HAS_DNF, dnf, hawkey
from fedrq._utils import mklog
from fedrq.backends import BACKENDS, MissingBackendError
from fedrq.cli.formatters import (
DefaultFormatters,
Formatter,
@ -33,19 +33,22 @@ from fedrq.cli.formatters import (
)
from fedrq.config import (
ConfigError,
LoadFilelists,
Release,
RQConfig,
get_config,
get_smartcache_basedir,
)
from fedrq.repoquery import Repoquery, get_releasever
if TYPE_CHECKING:
from fedrq.backends.base import BackendMod, PackageQueryCompat
logger = logging.getLogger("fedrq")
FORMATTER_ERROR_SUFFIX = "See fedrq(1) for more information about formatters."
NO_DNF_ERROR = """
The dnf and hawkey modules are not available in the current context.
MISSING_BACKEND_MSG = """
Failed to load the package management backend: {}
These modules are only available for the default system Python interpreter.
""".strip()
@ -89,26 +92,57 @@ def v_fatal_error(
class Command(abc.ABC):
config: RQConfig
release: Release
query: hawkey.Query
query: PackageQueryCompat
formatters: FormatterContainer = DefaultFormatters()
formatter: Formatter
def __init__(self, args: argparse.Namespace):
self.args = args
self.v_logging()
flog = mklog(__name__, self.__class__.__name__)
flog.debug("args=%s", args)
self.get_names()
try:
self.config = get_config()
except (ValidationError) as exc:
self.config = self._get_config()
except ValidationError as exc:
sys.exit(str(exc))
self._set_config("backend")
self._set_config("load_filelists")
self._v_errors: list[str] = []
def _get_config(self):
# This makes it easier to mock the config
return get_config()
@property
def backend(self) -> BackendMod:
return self.config.backend_mod
@abc.abstractmethod
def run(self) -> None:
...
def _set_config(self, key: str) -> None:
arg = getattr(self.args, key, None)
if arg is not None:
setattr(self.config, key, arg)
def _logq(
self, query: PackageQueryCompat, name: str = "query", level=logging.DEBUG
) -> PackageQueryCompat:
"""
Log a query object after performing the appropriate formatting.
Don't iterate over the query unless the logging level is low enough to
avoid a performance penalty.
"""
if logger.getEffectiveLevel() <= level:
logger.debug("%s = %s", name, tuple(query))
return query
@classmethod
def parent_parser(cls) -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(add_help=False)
@ -153,6 +187,18 @@ class Command(abc.ABC):
# and subject to change.
cachedir_group.add_argument("--cachedir", help=argparse.SUPPRESS, type=Path)
parser.add_argument("--debug", action="store_true")
parser.add_argument(
"-L",
"--filelists",
choices=tuple(LoadFilelists),
dest="load_filelists",
help="Whether to load filelists."
" By default, filelists are only loaded when using the files formatter."
" This only applies when using the libdnf5 backend,"
" which doesn't load filelists by default to save bandwidth."
" dnf4 always loads filelists.",
)
parser.add_argument("-B", "--backend", choices=tuple(BACKENDS))
return parser
@classmethod
@ -218,6 +264,15 @@ class Command(abc.ABC):
return str(err) + "\n" + FORMATTER_ERROR_SUFFIX
return None
@v_add_errors
def v_filelists(self) -> None:
options: dict[LoadFilelists, bool] = {
LoadFilelists.never: False,
LoadFilelists.always: True,
LoadFilelists.auto: "files" in self.args.formatter,
}
self.filelists = options[self.config.load_filelists]
@v_add_errors
def v_arch(self) -> str | None:
# TODO: Verify that arches are actually valid RPM arches.
@ -242,7 +297,7 @@ class Command(abc.ABC):
self.args.smartcache = True
if not self.args.smartcache:
return None
if self.release.version == get_releasever():
if self.release.version == self.backend.get_releasever():
self.args.cachedir = None
self.args.smartcache = False
return None
@ -259,27 +314,30 @@ class Command(abc.ABC):
@v_add_errors
def v_rq(self) -> str | None:
try:
base = self.release.make_base(_cachedir=self.args.cachedir)
except dnf.exceptions.RepoError as exc:
sys.exit(f"Failed to load repositories: {exc}")
base = self.release.make_base(
_cachedir=self.args.cachedir,
load_filelists=self.filelists,
backend=self.backend,
)
self.rq = Repoquery(base)
self.rq = self.backend.Repoquery(base)
return None
@v_fatal_error
def needs_dnf(self) -> str | None:
if HAS_DNF:
return None
return NO_DNF_ERROR
def v_backend(self) -> str | None:
try:
_ = self.backend
except MissingBackendError as exc:
return MISSING_BACKEND_MSG.format(str(exc))
return None
def v_default(self):
self.v_formatters()
self.v_filelists()
self.v_latest()
self.v_arch()
# Fatal
self.needs_dnf()
# Fatal
self.v_backend()
self.v_release()
self.v_smartcache()
self.v_rq()
@ -339,7 +397,7 @@ class CheckConfig(Command):
print("Validating config...")
try:
self.config = get_config()
except (ValidationError) as exc:
except ValidationError as exc:
sys.exit(str(exc))
try:
self.config.get_release(self.config.default_branch)

View file

@ -75,17 +75,14 @@ class Pkgs(Command):
resolved_packages = self.rq.resolve_pkg_specs(
self.args.names, self.args.resolve_packages
)
flog.debug("resolved_packages = %s", tuple(resolved_packages))
self._logq(resolved_packages, "resolved_packages")
self.query = self.query.union(resolved_packages)
# flog.debug("self.query = %s", tuple(self.query))
glob_packages = self.rq.query(name__glob=self.args.names)
flog.debug("glob_packages = %s", tuple(glob_packages))
self._logq(glob_packages, "glob_packages")
self.query = self.query.union(glob_packages)
# flog.debug("self.query = %s", tuple(self.query))
self.query = self.rq.arch_filter(self.query, self.args.arch)
# flog.debug("self.query = %s", tuple(self.query))
filter_latest(self.query, self.args.latest)
flog.debug("self.query = %s", tuple(self.query))

View file

@ -10,17 +10,15 @@ import logging
import typing as t
from fedrq._utils import filter_latest, get_source_name
from fedrq.backends.base import PackageQueryCompat
from fedrq.cli.base import Command
from fedrq.cli.formatters import DefaultFormatters, Formatter
if t.TYPE_CHECKING:
import hawkey
logger = logging.getLogger(__name__)
class BreakdownFormatter(Formatter):
def format(self, packages: hawkey.Query) -> cabc.Iterable[str]:
def format(self, packages: PackageQueryCompat) -> cabc.Iterable[str]:
runtime = []
buildtime = []
for p in packages:
@ -119,12 +117,12 @@ class WhatCommand(Command):
parser.add_argument("-X", "--exclude-subpackages", action="store_true")
return parser
def exclude_subpackages(self, rpms: t.Optional[hawkey.Query]) -> None:
def exclude_subpackages(self, rpms: t.Optional[PackageQueryCompat]) -> None:
import re
rpms = rpms or self.rq.resolve_pkg_specs(self.args.names, resolve=True)
brpms = rpms.filter(arch__neq="src")
srpms = rpms.filter(arch="src")
brpms = self.rq.query(pkg=rpms, arch__neq="src")
srpms = self.rq.query(pkg=rpms, arch="src")
brpm_sourcerpms = [re.sub(r"\.rpm$", "", pkg.sourcerpm) for pkg in brpms]
brpm_srpm_query = self.rq.resolve_pkg_specs(brpm_sourcerpms)
@ -141,16 +139,16 @@ class WhatCommand(Command):
resolved_packages = self.rq.resolve_pkg_specs(
self.args.names, self.args.resolve_packages, with_src=False
)
logger.debug(f"resolved_packages: {tuple(resolved_packages)}")
self._logq(resolved_packages, "resolved_packages")
operator_kwargs = {self.operator: resolved_packages}
rp_rdeps = self.rq.query(**operator_kwargs, arch=self.args.arch)
logger.debug(f"rp_rdeps={tuple(rp_rdeps)}")
self._logq(rp_rdeps, "rp_rdeps")
self.query = self.query.union(rp_rdeps)
operator_kwargs = {f"{self.operator}__glob": self.args.names}
glob_rdeps = self.rq.query(**operator_kwargs, arch=self.args.arch)
logger.debug(f"glob_rdeps={tuple(glob_rdeps)}")
self._logq(glob_rdeps, "glob_rdeps")
self.query = self.query.union(glob_rdeps)
filter_latest(self.query, self.args.latest)

View file

@ -211,7 +211,7 @@ class AttrFormatter(SpecialFormatter):
def format(self, packages: hawkey.Query) -> Iterable[str]:
for p in sorted(packages):
result = getattr(p, self.params)
if isinstance(result, list):
if isinstance(result, Iterable) and not isinstance(result, str):
yield from map(stringify, result)
continue
yield stringify(result)
@ -239,7 +239,7 @@ class JsonFormatter(SpecialFormatter):
def _format(self, package: dnf.package.Package) -> Iterable[tuple[str, t.Any]]:
for attr in self.attrs:
result = getattr(package, attr)
if isinstance(result, list):
if isinstance(result, Iterable) and not isinstance(result, str):
result = [str(i) for i in result]
yield attr, result

View file

@ -12,9 +12,12 @@ import sys
import typing as t
import zipfile
from collections.abc import Callable
from enum import auto as auto_enum
from importlib.abc import Traversable
from pathlib import Path
from fedrq._compat import StrEnum
if sys.version_info < (3, 11):
import tomli as tomllib
else:
@ -22,14 +25,15 @@ else:
from pydantic import BaseModel, Field, validator
from fedrq._dnf import dnf, needs_dnf
from fedrq._utils import mklog
from fedrq.repoquery import BaseMaker, Repoquery, get_releasever
from fedrq.backends import BACKENDS, get_default_backend
if t.TYPE_CHECKING:
import dnf
from _typeshed import StrPath
from fedrq.backends.base import BackendMod, RepoqueryBase
CONFIG_DIRS = (Path.home() / ".config/fedrq", Path("/etc/fedrq"))
logger = logging.getLogger(__name__)
@ -38,6 +42,12 @@ class ConfigError(ValueError):
pass
class LoadFilelists(StrEnum):
auto = auto_enum()
always = auto_enum()
never = auto_enum()
class ReleaseConfig(BaseModel):
name: str = Field(exclude=True)
defs: dict[str, list[str]]
@ -187,41 +197,60 @@ class Release:
fill_sack: bool = True,
*,
_cachedir: StrPath | None = None,
load_filelists: bool = True,
backend: BackendMod | None = None,
) -> dnf.Base:
"""
Return a dnf.Base object based on the releases's configuration
Note that the `_cachedir` arg is private and subject to removal.
"""
needs_dnf()
flog = mklog(__name__, self.__class__.__name__, "make_base")
base_maker = BaseMaker(base)
backend = backend or get_default_backend()
base_maker = backend.BaseMaker(base)
base = base_maker.base
base_maker.base.conf.substitutions["releasever"] = self.version
if self.release_config.system_repos:
base_maker.read_system_repos()
# flog.debug("full_def_paths: %s", self.release_config.full_def_paths)
for path in self.release_config.full_def_paths:
with importlib_resources.as_file(path) as fp:
flog.debug("Reading %s", fp)
base_maker._read_repofile((str(fp)))
flog.debug("Enabling repos: %s", self.repos)
base_maker.enable_repos(self.repos)
if _cachedir:
base_maker.set("cachedir", str(_cachedir))
if load_filelists:
base_maker.load_filelists()
base_maker.set_var("releasever", self.version)
base_maker.load_release_repos(self)
if fill_sack:
base_maker.fill_sack(_cachedir=_cachedir)
base_maker.fill_sack()
return base_maker.base
class RQConfig(BaseModel):
backend: t.Optional[str] = os.environ.get("FEDRQ_BACKEND")
releases: dict[str, ReleaseConfig]
default_branch: str = "rawhide"
smartcache: bool = True
load_filelists: LoadFilelists = LoadFilelists.auto
_backend_mod = None
class Config:
json_encoders: dict[t.Any, Callable[[t.Any], str]] = {
re.Pattern: lambda pattern: pattern.pattern,
zipfile.Path: lambda path: str(path),
}
underscore_attrs_are_private = True
validate_assignment = True
@validator("backend")
def v_backend(cls, value) -> str:
assert value in BACKENDS, f"Valid backends are: {', '.join(BACKENDS)}"
return value
@property
def backend_mod(self) -> BackendMod:
if not self._backend_mod:
self._backend_mod = get_default_backend(
self.backend,
# allow falling back to a non default backend
# (i.e. not backends.DEFAULT_BACKEND)
# when the user does not explicitly request a backend.
fallback=bool(self.backend),
)
return self._backend_mod
def get_release(
self, branch: str | None = None, repo_name: str = "base"
@ -310,20 +339,32 @@ def _get_releases(rdict: dict[str, dict[str, t.Any]]) -> dict[str, t.Any]:
def get_rq(
branch: str | None = None, repo: str = "base", *, smart_cache: bool = False
) -> Repoquery:
branch: str | None = None,
repo: str = "base",
*,
smart_cache: bool | None = None,
load_filelists: bool = False,
backend: str | None = None,
) -> RepoqueryBase:
"""
Higher level interface that creates an RQConfig object, finds the Release
object that mathces {branch} and {repo}, creates a dnf.Base, and finally
returns a Repoquery object.
"""
needs_dnf()
config = get_config()
if smart_cache is None:
smart_cache = config.smartcache
branch = branch or config.default_branch
release = config.get_release(branch, repo)
cachedir = None
if release.version != get_releasever():
if smart_cache and release.version != config.backend_mod.get_releasever():
base_cachedir = get_smartcache_basedir()
cachedir = base_cachedir / branch
rq = Repoquery(release.make_base(_cachedir=cachedir))
rq = config.backend_mod.Repoquery(
release.make_base(
_cachedir=cachedir,
load_filelists=load_filelists,
backend=config.backend_mod,
)
)
return rq

View file

@ -2,196 +2,28 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""
Provides access to the default package backend interface.
It is recommended to use the backend directly instead of this module.
"""
from __future__ import annotations
import typing as t
from collections.abc import Collection, Iterable
from warnings import warn
from collections.abc import Callable
from fedrq._dnf import dnf, hawkey, needs_dnf
from fedrq._utils import filter_latest, mklog
from fedrq.backends import get_default_backend
from fedrq.backends.base import BaseMakerBase, RepoqueryBase
if t.TYPE_CHECKING:
from _typeshed import StrPath
backend = get_default_backend()
BaseMaker: type[BaseMakerBase] = backend.BaseMaker
Repoquery: type[RepoqueryBase] = backend.Repoquery
get_releasever: Callable[[], str] = backend.get_releasever
BACKEND: str = backend.BACKEND
class BaseMaker:
"""
Create a dnf.Base object and load repos
"""
def __init__(self, base: dnf.Base | None = None) -> None:
needs_dnf()
self.base: dnf.Base = base or dnf.Base()
def fill_sack(
self,
*,
from_cache: bool = False,
load_system_repo: bool = False,
_cachedir: StrPath | None = None,
) -> dnf.Base:
"""
Fill the sack and returns the dnf.Base object.
The repository configuration shouldn't be manipulated after this.
Note that the `_cachedir` arg is private and subject to removal.
"""
if _cachedir:
self.base.conf.cachedir = str(_cachedir)
if from_cache:
self.base.fill_sack_from_repos_in_cache(load_system_repo=load_system_repo)
else:
self.base.fill_sack(load_system_repo=load_system_repo)
return self.base
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.
"""
self.base.read_all_repos()
if not disable:
return None
for repo in self.base.repos.iter_enabled():
repo.disable()
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.
"""
for repo in repos:
self.enable_repo(repo)
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.
"""
if repo_obj := self.base.repos.get_matching(repo):
repo_obj.enable()
else:
raise ValueError(f"{repo} repo definition was not found.")
def _read_repofile(self, file: str) -> None:
rr = dnf.conf.read.RepoReader(self.base.conf, None)
for repo in rr._get_repos(file):
self.base.repos.add(repo)
class Repoquery:
base: dnf.Base
def __init__(
self,
base: dnf.Base,
) -> None:
needs_dnf()
self.base = base
@property
def sack(self) -> dnf.sack.Sack:
return self.base.sack
def arch_filter(
self, query: hawkey.Query, arch: str | Iterable[str] | None = None
) -> hawkey.Query:
if not arch:
return query
if arch == "notsrc":
return query.filter(
arch=(*{self.base.conf.basearch, self.base.conf.arch}, "noarch")
)
if arch == "arched":
return query.filter(arch=self.base.conf.basearch)
return query.filter(arch=arch)
def query(
self, *, arch: str | Iterable[str] | None = None, **kwargs
) -> hawkey.Query:
if kwargs.get("latest", "UNDEFINED") is None:
kwargs.pop("latest")
query = self.base.sack.query().filter(**kwargs)
return self.arch_filter(query, arch)
def get_package(
self,
name: str,
arch: str | Iterable[str] | None = None,
) -> dnf.package.Package:
query = self.query(name=name, latest=1, arch=arch)
# if len(query) > 1:
# raise RuntimeError(
# f"Multiple packages found for {name} on {arch}"
# ) from None
if len(query) < 1:
raise RuntimeError(f"Zero packages found for {name} on {arch}")
return query[0]
def get_subpackages(
self,
packages: hawkey.Query | dnf.package.Package,
**kwargs,
) -> hawkey.Query:
"""
Return a hawkey.Query containing the binary RPMS/subpackages produced
by {packages}.
:param package: A :class:`hawkey.Query` containing source packages
or a single :class:`dnf.package.Package`.
:arch package: Set this to filter out subpackages with a specific arch
"""
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}")
if isinstance(packages, dnf.package.Package):
packages = self.query(pkg=[packages])
for package in packages:
if package.arch != "src":
raise ValueError(f"{package} must be a source package.")
query = self.query(empty=True)
for srpm in (
f"{package.name}-{package.version}-{package.release}.src.rpm"
for package in packages
):
query = query.union(self.query(sourcerpm=srpm, **kwargs))
return query
def resolve_pkg_specs(
self,
specs: Collection[str],
resolve: bool = False,
latest: int | None = None,
**kwargs,
) -> hawkey.Query:
flog = mklog(__name__, self.__class__.__name__, "resolve_pkg_spec")
flog.debug(f"specs={specs}, resolve={resolve}, latest={latest}")
query = self.query(empty=True)
for p in specs:
subject = dnf.subject.Subject(p).get_best_query(
self.sack, **kwargs, with_provides=resolve, with_filenames=resolve
)
query = query.union(subject)
flog.debug(f"subject query: {tuple(subject)}")
# get_best_query() may miss some Provides
if resolve:
flog.debug("Resolving provides...")
pp = self.query(provides=specs)
flog.debug(f"pp = {tuple(pp)}")
query = query.union(pp)
filter_latest(query, latest)
return query
def get_releasever() -> str:
needs_dnf()
return dnf.rpm.detect_releasever("/")
__all__ = (
"BACKEND",
"BaseMaker",
"Repoquery",
"backend",
"get_releasever",
)

View file

@ -6,11 +6,9 @@ from pathlib import Path
from shutil import rmtree
import pytest
from rpm import expandMacro
import fedrq.cli
from fedrq import config as rqconfig
from fedrq.repoquery import Repoquery
TEST_DATA = Path(__file__).parent.resolve() / "test_data"
@ -31,6 +29,8 @@ defpaths = ["testrepo1.repo"]
system_repos = false
"""
# @pytest.fixture(scope="session", autouse=True)
@pytest.fixture(scope="session", autouse=True)
def clear_cache():
@ -86,18 +86,14 @@ def patch_config_dirs(tmp_path, monkeypatch):
@pytest.fixture
def repo_test_rq(patch_config_dirs):
config = rqconfig.get_config()
release = config.get_release("tester", "base")
base = release.make_base(fill_sack=False)
base.cachedir = rqconfig.get_smartcache_basedir()
base.fill_sack(load_system_repo=False)
rq = Repoquery(base)
return rq
return rqconfig.get_rq("tester", "base", smart_cache=True, load_filelists=True)
@pytest.fixture(scope="session")
def target_cpu():
macro = expandMacro("%{_target_cpu}")
macro = subprocess.run(
["rpm", "-E", "%_target_cpu"], text=True, capture_output=True, check=True
).stdout.strip()
assert macro != "%{_target_cpu}"
return macro

View file

@ -10,4 +10,4 @@ import fedrq.cli
def test_pkgs_basic_rawhide(capsys, target_cpu):
fedrq.cli.main(["pkgs", "bash", "-Fna", "--sc"])
stdout, stderr = capsys.readouterr()
assert stdout.splitlines() == ["bash.src", f"bash.{target_cpu}"]
assert sorted(stdout.splitlines()) == sorted(["bash.src", f"bash.{target_cpu}"])

View file

@ -18,7 +18,7 @@ def test_subpkgs_match1(capsys):
["subpkgs", "-b", "f37", "yt-dlp", "--match", "*completion", "-F", "name"]
)
stdout, stderr = capsys.readouterr()
assert stdout.splitlines() == YT_DLP_SUPKGS
assert sorted(stdout.splitlines()) == YT_DLP_SUPKGS
assert not stderr

View file

@ -16,42 +16,56 @@ import fedrq.config
SUBCOMMANDS = ("pkgs", "whatrequires", "subpkgs")
@pytest.mark.parametrize("subcommand", SUBCOMMANDS)
def test_no_dnf_clean_failure(subcommand, capsys, monkeypatch):
monkeypatch.setattr(fedrq.cli.base, "HAS_DNF", False)
monkeypatch.setattr(fedrq.cli.base, "dnf", None)
monkeypatch.setattr(fedrq.cli.base, "hawkey", None)
# @pytest.mark.parametrize("subcommand", SUBCOMMANDS)
# def test_no_dnf_clean_failure(subcommand, capsys, monkeypatch):
# monkeypatch.setattr(fedrq.cli.base, "HAS_DNF", False)
# monkeypatch.setattr(fedrq.cli.base, "dnf", None)
# monkeypatch.setattr(fedrq.cli.base, "hawkey", None)
with pytest.raises(SystemExit, match=r"^1$") as exc:
fedrq.cli.main([subcommand, "dummy"])
assert exc.value.code == 1
stdout, stderr = capsys.readouterr()
assert not stdout
assert stderr == "FATAL ERROR: " + fedrq.cli.base.NO_DNF_ERROR + "\n"
# with pytest.raises(SystemExit, match=r"^1$") as exc:
# fedrq.cli.main([subcommand, "dummy"])
# assert exc.value.code == 1
# stdout, stderr = capsys.readouterr()
# assert not stdout
# assert stderr == "FATAL ERROR: " + fedrq.cli.base.NO_DNF_ERROR + "\n"
@pytest.mark.parametrize("subcommand", SUBCOMMANDS)
def test_smartcache_used(subcommand, mocker, patch_config_dirs, temp_smartcache: Path):
def test_smartcache_used(
subcommand, mocker, monkeypatch, patch_config_dirs, temp_smartcache: Path
):
"""
Ensure that the smartcache is used when the requested
branch's releasever is different the the system's releasever
"""
assert not list(temp_smartcache.iterdir())
get_releasever = mocker.patch(
"fedrq.cli.base.get_releasever", return_value="rawhide"
)
bm_fill_sack = mocker.spy(fedrq.config.BaseMaker, "fill_sack")
mocks = {}
def _set_config(self, key: str) -> None:
arg = getattr(self.args, key, None)
if arg is not None:
setattr(self.config, key, arg)
if key == "backend":
mocks["get_releasever"] = mocker.patch.object(
self.config.backend_mod, "get_releasever", return_value="rawhide"
)
mocks["bm_set"] = mocker.spy(self.config.backend_mod.BaseMaker, "set")
cls = fedrq.cli.COMMANDS[subcommand]
monkeypatch.setattr(cls, "_set_config", _set_config)
parser = cls.make_parser()
args = parser.parse_args(["--sc", "packageb"])
obj = cls(args)
get_releasever.assert_called_once()
mocks["get_releasever"].assert_called_once()
bm_fill_sack.assert_called_once()
assert bm_fill_sack.call_args.kwargs == dict(
_cachedir=temp_smartcache / "fedrq" / "tester"
expected_cachedir = temp_smartcache / "fedrq" / "tester"
assert any(
call.args[1:] == ("cachedir", str(expected_cachedir))
for call in mocks["bm_set"].call_args_list
)
assert obj.args.smartcache
@ -60,30 +74,40 @@ def test_smartcache_used(subcommand, mocker, patch_config_dirs, temp_smartcache:
@pytest.mark.parametrize("subcommand", SUBCOMMANDS)
def test_smartcache_not_used(subcommand, mocker, patch_config_dirs, temp_smartcache):
def test_smartcache_not_used(
subcommand, mocker, monkeypatch, patch_config_dirs, temp_smartcache
):
"""
Ensure that the smartcache is not used when the requested branch's
releasever matches the the system's releasever
"""
assert not list(temp_smartcache.iterdir())
get_releasever = mocker.patch(
"fedrq.cli.base.get_releasever", return_value="tester"
)
bm_fill_sack = mocker.spy(fedrq.config.BaseMaker, "fill_sack")
mocks = {}
def _set_config(self, key: str) -> None:
arg = getattr(self.args, key, None)
if arg is not None:
setattr(self.config, key, arg)
if key == "backend":
mocks["get_releasever"] = mocker.patch.object(
self.config.backend_mod, "get_releasever", return_value="tester"
)
mocks["bm_set"] = mocker.spy(self.config.backend_mod.BaseMaker, "set")
cls = fedrq.cli.COMMANDS[subcommand]
monkeypatch.setattr(cls, "_set_config", _set_config)
parser = cls.make_parser()
args = parser.parse_args(["--sc", "packageb"])
obj = cls(args)
get_releasever.assert_called_once()
bm_fill_sack.assert_called_once()
assert bm_fill_sack.call_args.kwargs == {"_cachedir": None}
mocks["get_releasever"].assert_called_once()
assert not obj.args.smartcache
assert not list(temp_smartcache.iterdir())
assert all(call.args[1] != "cachedir" for call in mocks["bm_set"].call_args_list)
# assert not list(temp_smartcache.iterdir())
@pytest.mark.parametrize(

View file

@ -4,6 +4,7 @@
import pytest
from fedrq import config as rqconfig
from fedrq.backends.base import PackageCompat, PackageQueryCompat, RepoqueryBase
@pytest.mark.no_rpm_mock
@ -11,5 +12,26 @@ def test_make_base_rawhide_repos():
config = rqconfig.get_config()
rawhide = config.get_release("rawhide")
base = rawhide.make_base(fill_sack=False)
assert len(tuple(base.repos.iter_enabled())) == len(rawhide.repos)
assert set(repo.id for repo in base.repos.iter_enabled()) == set(rawhide.repos)
backend: str = config.backend_mod.BACKEND
if backend == "dnf":
assert len(tuple(base.repos.iter_enabled())) == len(rawhide.repos)
assert set(repo.id for repo in base.repos.iter_enabled()) == set(rawhide.repos)
elif backend == "libdnf5":
import libdnf5
repoq = libdnf5.repo.RepoQuery(base)
repoq.filter_enabled(True)
assert len(tuple(repoq)) == len(rawhide.repos)
assert set(repo.get_id() for repo in repoq) == set(rawhide.repos)
else:
raise TypeError
def test_package_protocol(repo_test_rq: RepoqueryBase):
package = repo_test_rq.get_package("packagea", arch="noarch")
assert isinstance(package, PackageCompat)
def test_query_protocol(repo_test_rq: RepoqueryBase):
query = repo_test_rq.query()
assert isinstance(query, PackageQueryCompat)

View file

@ -99,7 +99,6 @@ def test_subpkg_match(run_command):
"*-sub",
"-Fna",
"-la",
"--debug",
]
)
assert stdout == ["packagea.noarch", "packagea-sub.noarch", "packageb-sub.noarch"]

View file

@ -33,30 +33,27 @@ def test_whatrequires_name(run_command):
assert not output[1]
def test_whatrequires_resolve_b(run_command):
output = run_command(
["package(b)", "-l", "a", "-P"],
return_tuples=True,
)
output1 = run_command(
["vpackage(b)", "-l", "a", "-P"],
return_tuples=True,
)
output2 = run_command(
["packageb", "-l", "a", "-P"],
return_tuples=True,
)
output3 = run_command(["packageb", "-l", "a"], return_tuples=True)
output4 = run_command(["/usr/share/packageb", "-l", "a", "-P"], return_tuples=True)
outputs = {output[0], output1[0], output2[0], output3[0], output4[0]}
assert output[0] == (
@pytest.mark.parametrize(
"args",
(
pytest.param(["package(b)", "-l", "a", "-P"]),
pytest.param(["vpackage(b)", "-l", "a", "-P"]),
pytest.param(["packageb", "-l", "a", "-P"]),
pytest.param(
["packageb", "-l", "a"],
),
pytest.param(["/usr/share/packageb", "-l", "a", "-P", "-Lalways"]),
),
)
def test_whatrequires_resolve_b(run_command, args):
stdout, stderr = run_command(args, return_tuples=True)
assert stdout == (
"packagea-1-1.fc36.noarch",
"packagea-1-1.fc36.src",
"packageb-sub-1-1.fc36.noarch",
"packageb-sub-11111:2-1.fc36.noarch",
)
assert len(outputs) == 1
assert not output[1]
assert not stderr
@pytest.mark.parametrize(
@ -66,7 +63,7 @@ def test_whatrequires_resolve_b(run_command):
(["packagea", "-P"]),
(["package(a)", "-P"]),
(["vpackage(a)", "-P"]),
(["/usr/share/packagea", "-P"]),
(["/usr/share/packagea", "-P", "-Lalways"]),
),
)
def test_whatrequires_resolve_a(run_command, args):
@ -99,8 +96,8 @@ def test_whatrequires_versioned_resolve(run_command):
# when no packages are provided.
(["package(a)", "-F", "attr:repoid"], True),
(["vpackage(a)", "-F", "source"], True),
(["/usr/share/packagea", "-F", "attr:sourcerpm"], True),
(["/usr/share/packageb", "-F", "nev"], True),
(["/usr/share/packagea", "-F", "attr:sourcerpm", "-Lalways"], True),
(["/usr/share/packageb", "-F", "nev", "-Lalways"], True),
# fedrq will resolve package names, so we need
# to explicitly pass -E.
(["packageb", "-F", "nv"], False),