mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-10-20 11:47:57 +00:00
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
This commit is contained in:
1 parent
9e5468313e
commit
6e7651a176
2 files changed
+10
-14
No files matched your search
@@ -23,7 +23,6 @@ import sys
|
|||||||
|
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
from importlib import metadata
|
from importlib import metadata
|
||||||
from typing import ClassVar
|
|
||||||
|
|
||||||
from ahriman import __version__
|
from ahriman import __version__
|
||||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||||
@@ -35,13 +34,10 @@ from ahriman.models.repository_id import RepositoryId
|
|||||||
class Versions(Handler):
|
class Versions(Handler):
|
||||||
"""
|
"""
|
||||||
version 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
|
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
|
@classmethod
|
||||||
def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *,
|
def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *,
|
||||||
@@ -57,7 +53,7 @@ class Versions(Handler):
|
|||||||
"""
|
"""
|
||||||
VersionPrinter(f"Module version {__version__}",
|
VersionPrinter(f"Module version {__version__}",
|
||||||
{"Python": sys.version})(verbose=False, separator=" ")
|
{"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=" ")
|
VersionPrinter("Installed packages", dict(packages))(verbose=False, separator=" ")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -77,15 +73,15 @@ class Versions(Handler):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
@staticmethod
|
@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:
|
Args:
|
||||||
root(str): root package name
|
*roots(str): root package names
|
||||||
|
|
||||||
Yields:
|
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]:
|
def dependencies_by_key(key: str) -> Iterator[str]:
|
||||||
# in importlib it returns requires in the following format
|
# in importlib it returns requires in the following format
|
||||||
@@ -95,10 +91,10 @@ class Versions(Handler):
|
|||||||
except metadata.PackageNotFoundError:
|
except metadata.PackageNotFoundError:
|
||||||
return
|
return
|
||||||
for entry in requires or []:
|
for entry in requires or []:
|
||||||
yield from Versions.PEP423_PACKAGE_NAME.findall(entry)
|
yield from Versions._PEP423_PACKAGE_NAME.findall(entry)
|
||||||
|
|
||||||
keys: list[str] = []
|
keys: list[str] = []
|
||||||
portion = set(dependencies_by_key(root))
|
portion = set(roots)
|
||||||
while portion:
|
while portion:
|
||||||
keys.extend(portion)
|
keys.extend(portion)
|
||||||
portion = {
|
portion = {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, mocker: Moc
|
|||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
_, repository_id = configuration.check_loaded()
|
||||||
Versions.run(args, repository_id, configuration, report=False)
|
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([
|
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=" "),
|
||||||
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
|
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
|
||||||
assert packages.get("pyalpm") is not None
|
assert packages.get("pyalpm") is not None
|
||||||
assert packages.get("Sphinx") is None
|
assert packages.get("Sphinx") is None
|
||||||
|
|||||||
Reference in new issue
Block a user