From 6e7651a1761462b0c6dcf5bc1c2e45ceaea8d0c6 Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Mon, 19 Oct 2026 23:25:22 +0300 Subject: [PATCH] fix: handle version subcommand correctly After package split it was looking for metapackage and lookup was broken because it doesn't contain any python metadata --- .../ahriman/application/handlers/versions.py | 20 ++++++++----------- .../handlers/test_handler_versions.py | 4 ++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/ahriman-core/src/ahriman/application/handlers/versions.py b/ahriman-core/src/ahriman/application/handlers/versions.py index 135f190f..c9baf4b2 100644 --- a/ahriman-core/src/ahriman/application/handlers/versions.py +++ b/ahriman-core/src/ahriman/application/handlers/versions.py @@ -23,7 +23,6 @@ import sys from collections.abc import Iterator from importlib import metadata -from typing import ClassVar from ahriman import __version__ from ahriman.application.handlers.handler import Handler, SubParserAction @@ -35,13 +34,10 @@ from ahriman.models.repository_id import RepositoryId class Versions(Handler): """ version handler - - Attributes: - PEP423_PACKAGE_NAME(re.Pattern[str]): (class attribute) special regex for valid PEP423 package name """ ALLOW_MULTI_ARCHITECTURE_RUN = False # system-wide action - PEP423_PACKAGE_NAME: ClassVar[re.Pattern[str]] = re.compile(r"^[A-Za-z0-9._-]+") + _PEP423_PACKAGE_NAME = re.compile(r"^[A-Za-z0-9._-]+") @classmethod def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *, @@ -57,7 +53,7 @@ class Versions(Handler): """ VersionPrinter(f"Module version {__version__}", {"Python": sys.version})(verbose=False, separator=" ") - packages = Versions.package_dependencies("ahriman") + packages = Versions.package_dependencies("ahriman-core", "ahriman-triggers", "ahriman-web") VersionPrinter("Installed packages", dict(packages))(verbose=False, separator=" ") @staticmethod @@ -77,15 +73,15 @@ class Versions(Handler): return parser @staticmethod - def package_dependencies(root: str) -> Iterator[tuple[str, str]]: + def package_dependencies(*roots: str) -> Iterator[tuple[str, str]]: """ - extract list of ahriman package dependencies installed into system with their versions + extract installed root packages and their dependencies with their versions Args: - root(str): root package name + *roots(str): root package names Yields: - tuple[str, str]: map of installed dependency to its version + tuple[str, str]: map of installed package to its version """ def dependencies_by_key(key: str) -> Iterator[str]: # in importlib it returns requires in the following format @@ -95,10 +91,10 @@ class Versions(Handler): except metadata.PackageNotFoundError: return for entry in requires or []: - yield from Versions.PEP423_PACKAGE_NAME.findall(entry) + yield from Versions._PEP423_PACKAGE_NAME.findall(entry) keys: list[str] = [] - portion = set(dependencies_by_key(root)) + portion = set(roots) while portion: keys.extend(portion) portion = { diff --git a/ahriman-core/tests/ahriman/application/handlers/test_handler_versions.py b/ahriman-core/tests/ahriman/application/handlers/test_handler_versions.py index ec1c7b51..894f4611 100644 --- a/ahriman-core/tests/ahriman/application/handlers/test_handler_versions.py +++ b/ahriman-core/tests/ahriman/application/handlers/test_handler_versions.py @@ -17,7 +17,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc _, repository_id = configuration.check_loaded() Versions.run(args, repository_id, configuration, report=False) - application_mock.assert_called_once_with("ahriman") + application_mock.assert_called_once_with("ahriman-core", "ahriman-triggers", "ahriman-web") print_mock.assert_has_calls([ MockCall(verbose=False, log_fn=pytest.helpers.anyvar(int), separator=" "), MockCall(verbose=False, log_fn=pytest.helpers.anyvar(int), separator=" "), @@ -37,7 +37,7 @@ def test_package_dependencies_missing() -> None: """ must extract package dependencies even if some of them are missing """ - packages = dict(Versions.package_dependencies("ahriman")) + packages = dict(Versions.package_dependencies("ahriman-core")) assert packages assert packages.get("pyalpm") is not None assert packages.get("Sphinx") is None