2023-02-19 12:01:23 -06:00
|
|
|
<!--
|
|
|
|
|
SPDX-FileCopyrightText: 2023 Maxwell G <gotmax@e.email>
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
# fedrq's Python API
|
|
|
|
|
|
2024-10-30 14:12:33 -05:00
|
|
|
The `fedrq.config` module and the `fedrq.backends` package are public API.
|
2024-10-30 14:00:05 -05:00
|
|
|
Everything under `fedrq.cli` is internal.
|
|
|
|
|
fedrq is primarily a CLI tool and its API only abstracts the specific
|
|
|
|
|
dnf/libdnf5 functionality that the CLI uses.
|
|
|
|
|
The API's main purpose is "repoquerying",
|
|
|
|
|
but you can use the fedrq functionality you'd like and then access the
|
|
|
|
|
underlying dnf Base object to preform other tasks if needed.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-08-27 23:16:30 -05:00
|
|
|
Take a look at the docstrings — in particular the base classes' documentation —
|
|
|
|
|
for more information.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-10-30 14:12:33 -05:00
|
|
|
!!! warning
|
|
|
|
|
|
|
|
|
|
The `fedrq.backends.**.experimental` modules are not meant for
|
|
|
|
|
public use.
|
|
|
|
|
They are subject to breaking changes in minor releases and should not be
|
|
|
|
|
relied on by external code.
|
|
|
|
|
Once the functionality has stabilized, the code will be moved out of the
|
|
|
|
|
experimental namespace.
|
|
|
|
|
|
2023-02-19 12:01:23 -06:00
|
|
|
## fedrq.backends
|
|
|
|
|
|
2024-03-18 02:08:11 +00:00
|
|
|
`fedrq.backends` is the heart of fedrq's API.
|
2024-02-09 05:27:39 +00:00
|
|
|
There is a dnf backend (`fedrq.backends.dnf`)
|
|
|
|
|
and a libdnf5 backend (`fedrq.backends.libdnf5`).
|
|
|
|
|
This package provides an interface to configure a Base session, load
|
|
|
|
|
repositories, preform queries, and related functionality.
|
|
|
|
|
The main primitives are:
|
2023-02-19 12:01:23 -06:00
|
|
|
|
|
|
|
|
### BaseMaker
|
|
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**Base class**: [`fedrq.backends.base.BaseMakerBase`][fedrq.backends.base.BaseMakerBase]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**dnf backend:** [`fedrq.backends.dnf.backend.BaseMaker`][fedrq.backends.dnf.backend.BaseMaker]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**libdnf5 backend:** [`fedrq.backends.libdnf5.backend.BaseMaker`][fedrq.backends.libdnf5.backend.BaseMaker]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-02-09 05:27:39 +00:00
|
|
|
`BaseMaker` allows configuring a dnf `Base` session and loading repositories.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
|
|
|
|
### Repoquery
|
|
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**Base class**: [`fedrq.backends.base.RepoqueryBase`][fedrq.backends.base.RepoqueryBase]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**dnf backend:** [`fedrq.backends.dnf.backend.Repoquery`][fedrq.backends.dnf.backend.Repoquery]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**libdnf5 backend:** [`fedrq.backends.libdnf5.backend.Repoquery`][fedrq.backends.libdnf5.backend.Repoquery]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-02-09 05:27:39 +00:00
|
|
|
`Repoquery` accepts an initialized Base object (see `BaseMaker`) and allows
|
|
|
|
|
performing a large range of queries. Most of its methods return
|
2023-02-19 12:01:23 -06:00
|
|
|
`PackageQueryCompat` or `PackageCompat` objects.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PackageQueryCompat
|
|
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**Protocol:** [`fedrq.backends.base.PackageQueryCompat`][fedrq.backends.base.PackageQueryCompat]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-09-30 04:44:57 +00:00
|
|
|
**dnf backend:** [`fedrq.backends.dnf.backend.PackageQuery`][fedrq.backends.dnf.backend.PackageQuery] -> [`hawkey.Query`][dnf.query.Query]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-10-23 01:45:57 +00:00
|
|
|
**libdnf5 backend:** [`fedrq.backends.libdnf5.backend.PackageQuery`][fedrq.backends.libdnf5.backend.PackageQuery]
|
|
|
|
|
([`libdnf5.rpm.PackageQuery`][libdnf5.rpm.PackageQuery] subclass)
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-02-09 05:27:39 +00:00
|
|
|
`PackageQueryCompat` is a set-like object of `PackageCompat` objects. It contains
|
|
|
|
|
methods to filter its Packages based on certain criteria. Typically, you would
|
|
|
|
|
access the filtering methods through the `Repoquery` class's wrappers.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-02-09 05:27:39 +00:00
|
|
|
- `fedrq.backends.libdnf5.backend.PackageQuery` --- subclass of
|
2023-02-19 12:01:23 -06:00
|
|
|
`libdnf5.rpm.PackageQuery`. adds back missing `query` and `querym` methods.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### PackageCompat
|
|
|
|
|
|
|
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**Protocol:** [`fedrq.backends.base.PackageCompat`][fedrq.backends.base.PackageCompat]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-09-30 04:44:57 +00:00
|
|
|
**dnf backend:** [`fedrq.backends.dnf.backend.Package`][fedrq.backends.dnf.backend.Package] -> [`dnf.package.Package`][dnf.package.Package]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
**libdnf5 backend:** [`fedrq.backends.libdnf5.backend.Package`][fedrq.backends.libdnf5.backend.Package]
|
2023-09-30 04:44:57 +00:00
|
|
|
([`libdnf5.rpm.Package`][libdnf5.rpm.Package] subclass)
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-02-09 05:27:39 +00:00
|
|
|
- [`fedrq.backends.libdnf5.backend.Package`][fedrq.backends.libdnf5.backend.Package] ---
|
2023-09-30 04:44:57 +00:00
|
|
|
subclass of [`libdnf5.rpm.Package`][libdnf5.rpm.Package]
|
2024-02-09 05:27:39 +00:00
|
|
|
that implements missing functionality and compatibility with
|
|
|
|
|
[`dnf.package.Package`][dnf.package.Package].
|
|
|
|
|
The subclass includes properties to access Package attributes.
|
2023-02-19 12:01:23 -06:00
|
|
|
These properties were removed from libdnf5 in favor of `get_foo()` methods.
|
|
|
|
|
It also includes rich comparison support (`__lt__`, `__gt__`, etc.) and
|
|
|
|
|
implements roughly the same sort order as the dnf backend and adds a
|
2024-02-09 05:27:39 +00:00
|
|
|
`__hash__()` method so it can e.g., be used in a set or as a dictionary key.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-09-30 04:44:57 +00:00
|
|
|
Importing
|
|
|
|
|
[`fedrq.backends.libdnf5.backend`][fedrq.backends.libdnf5.backend]
|
|
|
|
|
registers the `Package` subclass so PackageQuery contains our subclass.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
## [`fedrq.config`][fedrq.config]
|
2023-02-19 12:01:23 -06:00
|
|
|
|
|
|
|
|
Most of the code here should not be called directly. Use `get_config()` to load
|
|
|
|
|
the configuration from the filesystem. Create an `RQConfig` object manually if
|
|
|
|
|
you must.
|
|
|
|
|
|
2023-03-19 00:52:39 -05:00
|
|
|
This example shows how to load the configuration and preform a basic query.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
|
|
|
|
``` python
|
|
|
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
|
# SPDX-FileCopyrightText: None
|
|
|
|
|
|
|
|
|
|
# Roughly equivalent to:
|
|
|
|
|
# fedrq whatrequires --arch=noarch -b rawhide -r buildroot bash | grep '^a'
|
|
|
|
|
|
|
|
|
|
from fedrq.config import get_config, RQConfig
|
|
|
|
|
|
2024-11-25 13:41:18 -06:00
|
|
|
# The get_config() function returns an RqConfig object.
|
|
|
|
|
#
|
2023-02-19 12:01:23 -06:00
|
|
|
# Load config from filesystem and override some options
|
2024-11-25 13:41:18 -06:00
|
|
|
config = get_config(backend="libdnf5")
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-11-25 13:41:18 -06:00
|
|
|
# The RQConfig.get_rq() method returns a Repoquery object.
|
|
|
|
|
# Repoquery is fedrq's helper class to perform various types of package queries.
|
|
|
|
|
#
|
|
|
|
|
# This creates a Repoquery containing the Fedora Rawhide koji buildroot repositories.
|
|
|
|
|
# get_rq() supports any release configuration builtin to fedrq
|
2023-02-19 12:01:23 -06:00
|
|
|
# or configured on your local system.
|
2024-11-25 13:41:18 -06:00
|
|
|
rq = config.get_rq("rawhide", "buildroot")
|
2023-02-19 12:01:23 -06:00
|
|
|
|
2024-11-25 13:41:18 -06:00
|
|
|
# The Repoquery.query() method returns a PackageQuery implementation.
|
|
|
|
|
#
|
|
|
|
|
# This gets all noarch packages that start with 'a' and depend on bash
|
2023-02-19 12:01:23 -06:00
|
|
|
query = rq.query(
|
|
|
|
|
name__glob="a*", arch="noarch", requires=rq.query(name="bash", arch="notsrc")
|
|
|
|
|
)
|
|
|
|
|
# By using sorted(), you'll get (relatively) consistent ordering between backends
|
|
|
|
|
for package in sorted(query):
|
|
|
|
|
print(package)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
|
|
See [api-examples] for some simple example code.
|
|
|
|
|
|
|
|
|
|
Real world examples:
|
|
|
|
|
|
|
|
|
|
- [mkblocker.py] - given a list of source packages names, use jinja2 to
|
|
|
|
|
template a specfile that Conflicts on every subpackage produced by the source
|
|
|
|
|
packages. This was used as part of the [Mass_Retire_Golang_Leaves] Fedora Change.
|
2023-04-11 14:33:23 +00:00
|
|
|
- [sig_policy.py] - enforces the FESCo [SIG Policy][sig-policy] by using fedrq
|
|
|
|
|
to find packages that meet certain criteria and adding the corresponding SIG
|
|
|
|
|
to the distgit repo's ACLs.
|
2023-02-19 12:01:23 -06:00
|
|
|
|
|
|
|
|
[api-examples]: https://git.sr.ht/~gotmax23/fedrq/tree/main/item/contrib/api_examples
|
|
|
|
|
[mkblocker.py]: https://git.sr.ht/~gotmax23/fedora-scripts/tree/main/item/go-sig/blocker/mkblocker.py
|
|
|
|
|
[Mass_Retire_Golang_Leaves]: https://fedoraproject.org/wiki/Changes/Mass_Retire_Golang_Leaves#Implementation
|
2023-04-11 14:33:23 +00:00
|
|
|
[sig_policy.py]: https://pagure.io/releng/blob/main/f/scripts/fesco/sig-policy/sig_policy.py
|
|
|
|
|
[sig-policy]: https://docs.fedoraproject.org/en-US/fesco/SIG_policy/
|