Use pyalpm instead of running pacman multiple times (fixes #39)

This commit is contained in:
Kivi Kaitaniemi
2025-12-27 02:43:02 +02:00
parent d54fd89852
commit 77bd72575e
11 changed files with 230 additions and 202 deletions
+8 -21
View File
@@ -8,7 +8,7 @@ AUR plugin can be used to manage AUR and custom packages. The pacman plugin mana
It manages packages exactly the same way as the pacman plugin.
> This plugin will ensure that explicitly installed packages match those defined in the decman source. If your system has explicitly installed package A, but it is not included in the source, it will be uninstalled. You don't need to list dependencies in your source as those will be handeled by pacman automatically. However, if you have inluded package B in your source and that package depends on A, this plugin will not remove A. Instead it will demote A to a dependency. This plugin will also remove all orphaned packages automatically.
> This plugin will ensure that explicitly installed packages match those defined in the decman source. If your system has explicitly installed package A, but it is not included in the source, it will be uninstalled. You don't need to list dependencies in your source as those will be handeled by pacman automatically. However, if you have inluded package B in your source and that package depends on A, this plugin will not remove A. Instead it will demote A to a dependency. This plugin will also remove all orphaned packages automatically. **Packages that are only optionally required by other packages are considered orphans.** This way this plugin can ensure that your system truly matches your source. You cannot install an optional dependency, and forget about it later.
Building of foreign packages happens in a chroot. This creates some overhead, but ensures clean builds. By default the chroot is created to `/tmp/decman/build`. If `/tmp` is a in-memory filesystem like tmpfs, make sure that the tmpfs-partition is large enough. I recommend at least 6 GB. You can also change the build directory if memory is an issue.
@@ -81,7 +81,7 @@ If these sets change, this plugin will flag the module as changed. The module's
## Configuration
This module has partially the same configuration with pacman. You'll have to define pacman output keywords again.
This module has partially the same configuration with pacman. You'll have to define pacman output keywords and database options again.
```py
import decman
@@ -89,6 +89,12 @@ import decman
decman.aur.keywords = {"pacsave", "pacnew", "warning"}
# disable the feature
decman.aur.print_highlights = False
# signature level for querying existing databases
decman.aur.database_signature_level = 2048 # pyalpm.SIG_DATABASE_OPTIONAL
# path to databases
decman.aur.database_path = "/var/lib/pacman/"
```
There are some options related to building packages.
@@ -117,25 +123,6 @@ from decman.plugins import aur
import decman
class MyAurAndPacmanCommands(aur.AurCommands):
def list_orphans_foreign(self) -> list[str]:
"""
Running this command outputs a newline seperated list of orphaned foreign packages.
"""
return ["pacman", "-Qmdtq", "--color=never"]
def list_foreign_versioned(self) -> list[str]:
"""
Running this command outputs a newline seperated list of installed packages and their
versions that are not from pacman repositories.
"""
return ["pacman", "-Qm", "--color=never"]
def is_installable(self, pkg: str) -> list[str]:
"""
This command exits with code 0 when a package is installable from pacman repositories.
"""
return ["pacman", "-Sddp", pkg]
def install_as_dependencies(self, pkgs: set[str]) -> list[str]:
"""
Running this command installs the given packages from pacman repositories.
+10 -25
View File
@@ -2,7 +2,7 @@
Pacman plugin can be used to manage pacman packages. The pacman plugin manages only native packages found in arch repositories. All foreign (AUR) packages are ignored by this plugin.
This plugin will ensure that explicitly installed packages match those defined in the decman source. If your system has explicitly installed package A, but it is not included in the source, it will be uninstalled. You don't need to list dependencies in your source as those will be handeled by pacman automatically. However, if you have inluded package B in your source and that package depends on A, this plugin will not remove A. Instead it will demote A to a dependency. This plugin will also remove all orphaned packages automatically.
This plugin will ensure that explicitly installed packages match those defined in the decman source. If your system has explicitly installed package A, but it is not included in the source, it will be uninstalled. You don't need to list dependencies in your source as those will be handeled by pacman automatically. However, if you have inluded package B in your source and that package depends on A, this plugin will not remove A. Instead it will demote A to a dependency. This plugin will also remove all orphaned packages automatically. **Packages that are only optionally required by other packages are considered orphans.** This way this plugin can ensure that your system truly matches your source. You cannot install an optional dependency, and forget about it later.
Please keep in mind that decman doesn't play well with package groups, since all packages part of that group will be installed explicitly. After the initial run decman will now try to remove those packages since it only knows that the group itself should be explicitly installed. Instead of package groups, use meta packages.
@@ -54,6 +54,12 @@ decman.pacman.keywords = {"pacsave", "pacnew", "warning"}
# disable the feature
decman.pacman.print_highlights = False
# signature level for querying existing databases
decman.pacman.database_signature_level = 2048 # pyalpm.SIG_DATABASE_OPTIONAL
# path to databases
decman.pacman.database_path = "/var/lib/pacman/"
```
Additionally it's possible to override the commands this plugin uses. Create your own `PacmanCommands` class and override methods returning commands. These are the defaults.
@@ -62,32 +68,11 @@ Additionally it's possible to override the commands this plugin uses. Create you
from decman.plugins import pacman
class MyCommands(pacman.PacmanCommands):
def list_explicit_native(self) -> list[str]:
def list_pacman_repos(self) -> list[str]:
"""
Running this command outputs a newline seperated list of explicitly installed native
packages.
Running this command prints a newline seperated list of pacman repositories.
"""
return ["pacman", "-Qeqn", "--color=never"]
def list_explicit_foreign(self) -> list[str]:
"""
Running this command outputs a newline seperated list of explicitly installed foreign
packages.
"""
return ["pacman", "-Qeqm", "--color=never"]
def list_orphans_native(self) -> list[str]:
"""
Running this command outputs a newline seperated list of orphaned native packages.
"""
return ["pacman", "-Qndtq", "--color=never"]
def list_dependants(self, pkg: str) -> list[str]:
"""
Running this command outputs a newline seperated list of packages that depend on the given
package.
"""
return ["pacman", "-Rc", "--print", "--print-format", "%n", pkg]
return ["pacman-conf", "--repo-list"]
def install(self, pkgs: set[str]) -> list[str]:
"""