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
+16 -4
View File
@@ -102,7 +102,7 @@ def test_apply_respects_ignored_packages_and_protects_their_dependencies(
# Fake pacman interface for foreign/native info
class FakePM:
def __init__(self, commands, print_highlights, keywords) -> None:
def __init__(self, commands, print_highlights, keywords, dbsiglevel, dbpath) -> None:
self.commands = commands
self.print_highlights = print_highlights
self.keywords = keywords
@@ -139,9 +139,15 @@ def test_apply_respects_ignored_packages_and_protects_their_dependencies(
def set_as_dependencies(self, pkgs: set[str]) -> None:
self.set_as_deps_called_with = pkgs
fake_pm = FakePM(None, None, None)
fake_pm = FakePM(None, None, None, None, None)
def fake_pm_ctor(commands, print_highlights, keywords) -> FakePM:
def fake_pm_ctor(
commands,
print_highlights,
keywords,
dbsiglevel,
dbpath,
) -> FakePM:
fake_pm.commands = commands
fake_pm.print_highlights = print_highlights
fake_pm.keywords = keywords
@@ -182,7 +188,13 @@ def test_apply_respects_ignored_packages_and_protects_their_dependencies(
fake_fpm = FakeFPM(None, None, None, None, None, None, None)
def fake_fpm_ctor(
store_arg, pm_arg, package_search_arg, commands_arg, cache_dir, build_dir, makepkg_user
store_arg,
pm_arg,
package_search_arg,
commands_arg,
cache_dir,
build_dir,
makepkg_user,
):
fake_fpm.store = store_arg
fake_fpm.pm = pm_arg
-18
View File
@@ -8,7 +8,6 @@ from decman.plugins.aur.package import (
CustomPackage,
PackageInfo,
PackageSearch,
strip_dependency,
)
@@ -24,23 +23,6 @@ def silence_output(monkeypatch):
)
# --- strip_dependency ------------------------------------------------------
@pytest.mark.parametrize(
"dep,expected",
[
("foo", "foo"),
("foo=1.0", "foo"),
("bar>=2", "bar"),
("baz<3", "baz"),
("multi=1.0-2", "multi"),
],
)
def test_strip_dependency(dep, expected):
assert strip_dependency(dep) == expected
# --- PackageInfo -----------------------------------------------------------
+28 -6
View File
@@ -5,6 +5,20 @@ import pytest
from decman.plugins import pacman as pacman_plugin
@pytest.mark.parametrize(
"dep,expected",
[
("foo", "foo"),
("foo=1.0", "foo"),
("bar>=2", "bar"),
("baz<3", "baz"),
("multi=1.0-2", "multi"),
],
)
def test_strip_dependency(dep, expected):
assert pacman_plugin.strip_dependency(dep) == expected
class FakeStore(dict):
def ensure(self, key: str, default: Any) -> None:
if key not in self:
@@ -59,7 +73,9 @@ def test_apply_dry_run_computes_sets_and_does_not_call_pacman(
# Fake PacmanInterface returned by plugin module
class FakePM:
def __init__(self, commands, print_highlights, keywords) -> None: # noqa: D401
def __init__(
self, commands, print_highlights, keywords, database_signature_level, database_path
) -> None: # noqa: D401
self.commands = commands
self.print_highlights = print_highlights
self.keywords = keywords
@@ -101,9 +117,11 @@ def test_apply_dry_run_computes_sets_and_does_not_call_pacman(
def install(self, pkgs: set[str]) -> None:
self.install_called_with = pkgs
fake_pm = FakePM(None, None, None)
fake_pm = FakePM(None, None, None, None, None)
def fake_pm_ctor(commands, print_highlights, keywords) -> FakePM:
def fake_pm_ctor(
commands, print_highlights, keywords, database_signature_level, database_path
) -> FakePM:
# constructor used in Pacman.apply
fake_pm.commands = commands
fake_pm.print_highlights = print_highlights
@@ -217,7 +235,9 @@ def test_ignored_packages_are_not_removed_or_installed(monkeypatch: pytest.Monke
pacman.ignored_packages = {"ignored-installed", "ignored-uninstalled"}
class FakePM:
def __init__(self, commands, print_highlights, keywords) -> None:
def __init__(
self, commands, print_highlights, keywords, database_signature_level, database_path
) -> None: # noqa: D401
self.commands = commands
self.print_highlights = print_highlights
self.keywords = keywords
@@ -252,9 +272,11 @@ def test_ignored_packages_are_not_removed_or_installed(monkeypatch: pytest.Monke
def install(self, pkgs: set[str]) -> None:
self.install_called_with = pkgs
fake_pm = FakePM(None, None, None)
fake_pm = FakePM(None, None, None, None, None)
def fake_pm_ctor(commands, print_highlights, keywords) -> FakePM:
def fake_pm_ctor(
commands, print_highlights, keywords, database_signature_level, database_path
) -> FakePM:
fake_pm.commands = commands
fake_pm.print_highlights = print_highlights
fake_pm.keywords = keywords