mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-22 09:39:30 +00:00
Compare commits
4
Commits
2.23.6
...
a10b1a9364
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a10b1a9364 | ||
|
|
f0d523492d | ||
|
|
dc4f2be65b | ||
|
|
9ba74413e3 |
No files matched your search
@@ -103,11 +103,11 @@ jobs:
|
||||
|
||||
- name: Update packages
|
||||
run: |
|
||||
sudo -u ahriman ahriman \
|
||||
! sudo -u ahriman ahriman \
|
||||
--log-handler "$AHRIMAN_OUTPUT" \
|
||||
repo-update \
|
||||
--exit-code \
|
||||
|| true
|
||||
--refresh
|
||||
|
||||
- name: Add patch
|
||||
run: |
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#
|
||||
# Copyright (c) 2021-2026 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
import sys
|
||||
|
||||
from ahriman.application.ahriman import run
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run())
|
||||
@@ -22,7 +22,7 @@ from collections.abc import Callable, Iterable
|
||||
from ahriman.application.application.application_packages import ApplicationPackages
|
||||
from ahriman.application.application.application_repository import ApplicationRepository
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.result import Result
|
||||
|
||||
@@ -95,43 +95,39 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
"""
|
||||
self.repository.triggers.on_stop()
|
||||
|
||||
def print_updates(self, packages: list[Package], *, log_fn: Callable[[str], None]) -> None:
|
||||
def print_updates(self, plan: BuildPlan, log_fn: Callable[[str], None], *, bump_pkgrel: bool = True) -> None:
|
||||
"""
|
||||
print list of packages to be built. This method will build dependency tree and print updates accordingly
|
||||
print packages and their reasons, grouped by dependency step
|
||||
|
||||
Args:
|
||||
packages(list[Package]): package list to be printed
|
||||
plan(BuildPlan): packages and selection reasons to be printed
|
||||
log_fn(Callable[[str], None]): logger function to log updates
|
||||
bump_pkgrel(bool, optional): whether duplicate releases are expected to increment
|
||||
"""
|
||||
local_versions = {package.base: package.version for package in self.repository.packages()}
|
||||
UpdatePrinter(plan, local_versions, bump_pkgrel=bump_pkgrel)(verbose=True, log_fn=log_fn)
|
||||
|
||||
tree = Tree.resolve(packages)
|
||||
for level in tree:
|
||||
for package in level:
|
||||
UpdatePrinter(package, local_versions.get(package.base))(verbose=True, log_fn=log_fn, separator=" -> ")
|
||||
|
||||
def with_dependencies(self, packages: list[Package], *, process_dependencies: bool) -> list[Package]:
|
||||
def with_dependencies(self, plan: BuildPlan, *, process_dependencies: bool) -> BuildPlan:
|
||||
"""
|
||||
add missing dependencies to list of packages. This will extract known packages, check dependencies of
|
||||
the supplied packages and add packages which are not presented in the list of known packages.
|
||||
add missing dependencies to a build plan and record which packages require them
|
||||
|
||||
Args:
|
||||
packages(list[Package]): list of source packages of which dependencies have to be processed
|
||||
plan(BuildPlan): selected packages and their reasons
|
||||
process_dependencies(bool): if set to ``False``, dependencies will not be processed
|
||||
|
||||
Returns:
|
||||
list[Package]: updated packages list. Packager for dependencies will be copied from the original package
|
||||
BuildPlan: selected packages and their dependencies
|
||||
|
||||
Examples:
|
||||
In the most cases, in order to avoid build failure, it is required to add missing packages, which can be
|
||||
done by calling::
|
||||
|
||||
>>> application = ...
|
||||
>>> packages = application.with_dependencies(packages, process_dependencies=True)
|
||||
>>> application.print_updates(packages, log_fn=print)
|
||||
>>> plan = application.with_dependencies(plan, process_dependencies=True)
|
||||
>>> application.update(plan)
|
||||
"""
|
||||
if not process_dependencies or not packages:
|
||||
return packages
|
||||
if not process_dependencies or not plan:
|
||||
return plan
|
||||
|
||||
def missing_dependencies(sources: Iterable[Package]) -> dict[str, str | None]:
|
||||
# append list of known packages with packages which are in current sources
|
||||
@@ -157,20 +153,29 @@ class Application(ApplicationPackages, ApplicationRepository):
|
||||
leaf = Package.from_build(source_dir, self.repository.repository_id.architecture, packager)
|
||||
else:
|
||||
leaf = Package.from_aur(package_name, packager, include_provides=True)
|
||||
portion[leaf.base] = leaf
|
||||
# for split packages we need to load all available subpackages here
|
||||
if (existing := portion.get(leaf.base)) is not None:
|
||||
leaf.packages.update(existing.packages)
|
||||
|
||||
portion[leaf.base] = leaf
|
||||
# register package in the database
|
||||
self.reporter.set_unknown(leaf)
|
||||
|
||||
return portion
|
||||
|
||||
known_packages = self._known_packages()
|
||||
with_dependencies: dict[str, Package] = {}
|
||||
for package in packages:
|
||||
for package in plan:
|
||||
with self.in_package_context(package.base, package.version): # use the same context for the logger
|
||||
try:
|
||||
with_dependencies |= new_packages(package)
|
||||
packages = new_packages(package)
|
||||
except Exception:
|
||||
self.logger.exception("could not process dependencies of %s, skip the package", package.base)
|
||||
continue
|
||||
|
||||
return list(with_dependencies.values())
|
||||
# update existing package
|
||||
item = plan.item(package.base)
|
||||
plan.add(packages.pop(package.base), item.reason, item.requester)
|
||||
# append dependencies
|
||||
plan.update(packages.values(), BuildPlanReason.RequiredBy, package.base)
|
||||
|
||||
return plan
|
||||
@@ -23,6 +23,7 @@ from ahriman.application.application.application_properties import ApplicationPr
|
||||
from ahriman.application.application.workers import Updater
|
||||
from ahriman.core.build_tools.sources import Sources
|
||||
from ahriman.core.exceptions import UnknownPackageError
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
@@ -182,7 +183,7 @@ class ApplicationRepository(ApplicationProperties):
|
||||
return result
|
||||
|
||||
def updates(self, filter_packages: Iterable[str], *,
|
||||
aur: bool, local: bool, manual: bool, vcs: bool, check_files: bool) -> list[Package]:
|
||||
aur: bool, local: bool, manual: bool, vcs: bool, check_files: bool) -> BuildPlan:
|
||||
"""
|
||||
get list of packages to run update process
|
||||
|
||||
@@ -193,25 +194,21 @@ class ApplicationRepository(ApplicationProperties):
|
||||
manual(bool): include or exclude manual updates
|
||||
vcs(bool): enable or disable checking of VCS packages
|
||||
check_files(bool): check for broken dependencies
|
||||
|
||||
Returns:
|
||||
list[Package]: list of out-of-dated packages
|
||||
BuildPlan: selected packages and their reasons
|
||||
"""
|
||||
updates = {}
|
||||
plan = BuildPlan()
|
||||
|
||||
# always add already built packages, because they will be always added
|
||||
updates.update({
|
||||
package.base: package
|
||||
for package in self.repository.load_archives(self.repository.packages_built())
|
||||
})
|
||||
plan.update(self.repository.load_archives(self.repository.packages_built()), BuildPlanReason.PreBuilt)
|
||||
|
||||
if aur:
|
||||
updates.update({package.base: package for package in self.repository.updates_aur(filter_packages, vcs=vcs)})
|
||||
plan.update(self.repository.updates_aur(filter_packages, vcs=vcs), BuildPlanReason.RegularUpdate)
|
||||
if local:
|
||||
updates.update({package.base: package for package in self.repository.updates_local(vcs=vcs)})
|
||||
plan.update(self.repository.updates_local(vcs=vcs), BuildPlanReason.LocalSourceUpdate)
|
||||
if manual:
|
||||
updates.update({package.base: package for package in self.repository.updates_manual()})
|
||||
plan.update(self.repository.updates_manual(), BuildPlanReason.QueuedRequest)
|
||||
if check_files:
|
||||
updates.update({package.base: package for package in self.repository.updates_dependencies(filter_packages)})
|
||||
plan.update(self.repository.updates_dependencies(filter_packages), BuildPlanReason.BrokenImplicitDependency)
|
||||
|
||||
return [package for _, package in sorted(updates.items())]
|
||||
return plan
|
||||
@@ -21,8 +21,10 @@ import argparse
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||
from ahriman.application.handlers.update import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.utils import extract_user
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
@@ -52,12 +54,14 @@ class Rebuild(Handler):
|
||||
packages = Rebuild.extract_packages(application, args.status, from_database=args.from_database)
|
||||
packages = application.repository.packages_depend_on(packages, args.depends_on)
|
||||
|
||||
Rebuild.check_status(args.exit_code, packages)
|
||||
plan = BuildPlan().update(packages, BuildPlanReason.Rebuild)
|
||||
application.print_updates(plan, Update.log_fn(application, dry_run=args.dry_run), bump_pkgrel=args.increment)
|
||||
|
||||
if args.dry_run:
|
||||
application.print_updates(packages, log_fn=print)
|
||||
Rebuild.check_status(args.exit_code, plan)
|
||||
return
|
||||
|
||||
result = application.update(packages, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
result = application.update(plan, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
Rebuild.check_status(args.exit_code, not result.is_empty)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -23,6 +23,7 @@ from ahriman import __version__
|
||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.repository_id import RepositoryId
|
||||
|
||||
@@ -56,7 +57,8 @@ class ServiceUpdates(Handler):
|
||||
if same_version:
|
||||
return
|
||||
|
||||
UpdatePrinter(remote, local_version)(verbose=True, separator=" -> ")
|
||||
plan = BuildPlan().update([remote], BuildPlanReason.RegularUpdate)
|
||||
UpdatePrinter(plan, {remote.base: local_version})(verbose=True)
|
||||
ServiceUpdates.check_status(args.exit_code, same_version)
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -147,20 +147,19 @@ class Update(Handler):
|
||||
application(Application): application instance
|
||||
args(argparse.Namespace): command line args
|
||||
"""
|
||||
packages = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||
check_files=args.check_files)
|
||||
plan = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||
check_files=args.check_files)
|
||||
plan = application.with_dependencies(plan, process_dependencies=args.dependencies)
|
||||
if args.changes: # generate changes if requested
|
||||
application.changes(packages)
|
||||
application.changes(plan)
|
||||
|
||||
application.print_updates(plan, Update.log_fn(application, dry_run=args.dry_run), bump_pkgrel=args.increment)
|
||||
if args.dry_run: # exit from application if no build requested
|
||||
Update.check_status(args.exit_code, packages) # status code check
|
||||
Update.check_status(args.exit_code, plan) # status code check
|
||||
return
|
||||
|
||||
packages = application.with_dependencies(packages, process_dependencies=args.dependencies)
|
||||
packagers = Packagers(args.username, {package.base: package.packager for package in packages})
|
||||
|
||||
application.print_updates(packages, log_fn=application.logger.info)
|
||||
result = application.update(packages, packagers, bump_pkgrel=args.increment)
|
||||
packagers = Packagers(args.username, {package.base: package.packager for package in plan})
|
||||
result = application.update(plan, packagers, bump_pkgrel=args.increment)
|
||||
Update.check_status(args.exit_code, not result.is_empty)
|
||||
|
||||
arguments = [
|
||||
|
||||
@@ -46,7 +46,7 @@ class Printer:
|
||||
if not verbose and not prop.is_required:
|
||||
continue
|
||||
indent = "\t" * prop.indent
|
||||
log_fn(f"{indent}{prop.name}{separator}{prop.value}")
|
||||
log_fn(f"{indent}{prop.name}{separator if prop.separator is None else prop.separator}{prop.value}")
|
||||
|
||||
def properties(self) -> list[Property]:
|
||||
"""
|
||||
|
||||
@@ -17,30 +17,38 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from collections.abc import Iterator
|
||||
|
||||
from ahriman.core.formatters.string_printer import StringPrinter
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.core.utils import full_version, parse_version
|
||||
from ahriman.models.build_plan import BuildPlan
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
class UpdatePrinter(StringPrinter):
|
||||
"""
|
||||
print content of the package update
|
||||
print content of the packages update
|
||||
|
||||
Attributes:
|
||||
package(Package): remote (new) package object
|
||||
local_version(str | None): local version of the package if any
|
||||
plan(BuildPlan): plan to display
|
||||
local_versions(dict[str, str]): published package versions indexed by base
|
||||
bump_pkgrel(bool): whether duplicate package releases are expected to increment
|
||||
"""
|
||||
|
||||
def __init__(self, remote: Package, local_version: str | None) -> None:
|
||||
def __init__(self, plan: BuildPlan, local_versions: dict[str, str], *, bump_pkgrel: bool = True) -> None:
|
||||
"""
|
||||
Args:
|
||||
remote(Package): remote (new) package object
|
||||
local_version(str | None): local version of the package if any
|
||||
plan(BuildPlan): plan to display
|
||||
local_versions(dict[str, str]): published package versions indexed by base
|
||||
bump_pkgrel(bool, optional): whether duplicate package releases are expected to increment
|
||||
(Default value = True)
|
||||
"""
|
||||
StringPrinter.__init__(self, remote.base)
|
||||
self.package = remote
|
||||
self.local_version = local_version
|
||||
StringPrinter.__init__(self, "Build plan" if plan else "No packages selected")
|
||||
self.plan = plan
|
||||
self.local_versions = local_versions
|
||||
self.bump_pkgrel = bump_pkgrel
|
||||
|
||||
def properties(self) -> list[Property]:
|
||||
"""
|
||||
@@ -49,9 +57,48 @@ class UpdatePrinter(StringPrinter):
|
||||
Returns:
|
||||
list[Property]: list of content properties
|
||||
"""
|
||||
if (pkgrel := self.package.next_pkgrel(self.local_version)) is not None:
|
||||
epoch, pkgver, _ = parse_version(self.package.version)
|
||||
return [
|
||||
prop
|
||||
for level in Tree.resolve(self.plan)
|
||||
for package in level
|
||||
for prop in self.properties_package(package)
|
||||
]
|
||||
|
||||
def properties_package(self, package: Package) -> Iterator[Property]:
|
||||
"""
|
||||
generate list of properties for the specific package
|
||||
|
||||
Args:
|
||||
package(Package): package object
|
||||
|
||||
Yields:
|
||||
Property: list of properties belonging to the package
|
||||
"""
|
||||
# package header
|
||||
yield Property(package.base, "", is_required=True)
|
||||
|
||||
# set version update message
|
||||
local_version, remote_version = self.versions(package)
|
||||
yield Property(local_version, remote_version, is_required=True, indent=2, separator=" -> ")
|
||||
|
||||
# set reason
|
||||
item = self.plan.item(package.base)
|
||||
reason = item.reason.value if item.requester is None else f"{item.reason} {item.requester}"
|
||||
yield Property("Reason", reason, indent=2)
|
||||
|
||||
def versions(self, package: Package) -> tuple[str, str]:
|
||||
"""
|
||||
generate version property
|
||||
|
||||
Returns:
|
||||
tuple[str, str]: extract current and updated versions for the package
|
||||
"""
|
||||
local_version = self.local_versions.get(package.base)
|
||||
|
||||
if self.bump_pkgrel and (pkgrel := package.next_pkgrel(local_version)) is not None:
|
||||
epoch, pkgver, _ = parse_version(package.version)
|
||||
effective_new_version = full_version(epoch, pkgver, pkgrel)
|
||||
else:
|
||||
effective_new_version = self.package.version
|
||||
return [Property(self.local_version or "N/A", effective_new_version, is_required=True)]
|
||||
effective_new_version = package.version
|
||||
|
||||
return local_version or "N/A", effective_new_version
|
||||
@@ -188,6 +188,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
||||
self.reporter.set_pending(local.base)
|
||||
self.event(local.base, EventType.PackageOutdated, "Locally pulled sources are outdated")
|
||||
result.append(remote)
|
||||
|
||||
except Exception:
|
||||
self.logger.exception("could not process package at %s", cache_dir)
|
||||
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
#
|
||||
# Copyright (c) 2021-2026 ahriman team.
|
||||
#
|
||||
# This file is part of ahriman
|
||||
# (see https://github.com/arcan1s/ahriman).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from collections.abc import Iterable, Iterator
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
from typing import Any, Self
|
||||
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
class BuildPlanReason(StrEnum):
|
||||
"""
|
||||
reason why package was selected for a build plan
|
||||
|
||||
Attributes:
|
||||
BrokenImplicitDependency(BuildPlanReason): package has a broken implicit dependency
|
||||
LocalSourceUpdate(BuildPlanReason): locally sourced package has an update
|
||||
PreBuilt(BuildPlanReason): package has already been built
|
||||
QueuedRequest(BuildPlanReason): package was manually queued
|
||||
Rebuild(BuildPlanReason): package was selected for rebuild
|
||||
RegularUpdate(BuildPlanReason): package has an AUR update
|
||||
RequiredBy(BuildPlanReason): package is required by another selected package
|
||||
"""
|
||||
|
||||
BrokenImplicitDependency = "broken implicit dependency"
|
||||
LocalSourceUpdate = "local source update"
|
||||
PreBuilt = "pre-built"
|
||||
QueuedRequest = "queued request"
|
||||
Rebuild = "rebuild"
|
||||
RegularUpdate = "regular update"
|
||||
RequiredBy = "required by"
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class BuildPlanItem:
|
||||
"""
|
||||
one package and the reason it appears in a build plan
|
||||
|
||||
Attributes:
|
||||
package(Package): package selected for the plan
|
||||
reason(BuildPlanReason): why the package was selected
|
||||
requester(str | None): package that requires this package
|
||||
"""
|
||||
|
||||
package: Package
|
||||
reason: BuildPlanReason
|
||||
requester: str | None = None
|
||||
|
||||
|
||||
class BuildPlan(Iterable[Package]):
|
||||
"""
|
||||
in-memory preview of the packages selected for a build operation
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
initialize an empty build plan
|
||||
"""
|
||||
self._items: dict[str, BuildPlanItem] = {}
|
||||
|
||||
@property
|
||||
def items(self) -> list[BuildPlanItem]:
|
||||
"""
|
||||
get plan items in stable package-base order
|
||||
|
||||
Returns:
|
||||
list[BuildPlanItem]: selected plan items
|
||||
"""
|
||||
return [self._items[base] for base in sorted(self._items)]
|
||||
|
||||
@property
|
||||
def packages(self) -> list[Package]:
|
||||
"""
|
||||
get packages in stable package-base order
|
||||
|
||||
Returns:
|
||||
list[Package]: selected packages
|
||||
"""
|
||||
return [item.package for item in self.items]
|
||||
|
||||
def add(self, package: Package, reason: BuildPlanReason, requester: str | None = None) -> BuildPlanItem:
|
||||
"""
|
||||
add or update a package in the plan
|
||||
|
||||
Args:
|
||||
package(Package): package selected for the plan
|
||||
reason(BuildPlanReason): reason for selecting it
|
||||
requester(str | None, optional): package requiring this dependency (Default value = None)
|
||||
|
||||
Returns:
|
||||
BuildPlanItem: plan item for the package
|
||||
"""
|
||||
item = self._items[package.base] = BuildPlanItem(package, reason, requester)
|
||||
return item
|
||||
|
||||
def item(self, package_base: str) -> BuildPlanItem:
|
||||
"""
|
||||
get a plan item by package base
|
||||
|
||||
Args:
|
||||
package_base(str): package base to look up
|
||||
|
||||
Returns:
|
||||
BuildPlanItem: matching item
|
||||
"""
|
||||
return self._items[package_base]
|
||||
|
||||
def update(self, packages: Iterable[Package], reason: BuildPlanReason, requester: str | None = None) -> Self:
|
||||
"""
|
||||
bulk update packages with the same reason
|
||||
|
||||
Args:
|
||||
packages(Iterable[Package]): list of new packages to be added
|
||||
reason(BuildPlanReason): reason for selecting them
|
||||
requester(str | None, optional): package requiring these dependencies (Default value = None)
|
||||
|
||||
Returns:
|
||||
Self: updated plan instance
|
||||
"""
|
||||
for package in packages:
|
||||
self.add(package, reason, requester)
|
||||
return self
|
||||
|
||||
def __contains__(self, item: Package) -> bool:
|
||||
"""
|
||||
check whether plan holds a package or not
|
||||
|
||||
Args:
|
||||
item(Package): package to lookup
|
||||
|
||||
Returns:
|
||||
bool: ``True`` in case if the package is already in the plan and ``False`` otherwise
|
||||
"""
|
||||
return item.base in self._items
|
||||
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
"""
|
||||
check if other is the same object
|
||||
|
||||
Args:
|
||||
other(Any): other object instance
|
||||
|
||||
Returns:
|
||||
bool: ``True`` if the other object is the same and ``False`` otherwise
|
||||
"""
|
||||
if not isinstance(other, BuildPlan):
|
||||
return False
|
||||
return self.items == other.items
|
||||
|
||||
def __iter__(self) -> Iterator[Package]:
|
||||
"""
|
||||
iterate over selected packages in stable package-base order
|
||||
|
||||
Returns:
|
||||
Package: selected package
|
||||
"""
|
||||
return iter(self.packages)
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""
|
||||
get number of selected packages
|
||||
|
||||
Returns:
|
||||
int: number of selected packages
|
||||
"""
|
||||
return len(self._items)
|
||||
@@ -31,9 +31,11 @@ class Property:
|
||||
value(Any): property value
|
||||
is_required(bool): if set to ``True`` then this property is required
|
||||
indent(int): property indentation level
|
||||
separator(str | None): optional override for separator
|
||||
"""
|
||||
|
||||
name: str
|
||||
value: Any
|
||||
is_required: bool = field(default=False, kw_only=True)
|
||||
indent: int = 1
|
||||
separator: str | None = None
|
||||
@@ -4,8 +4,10 @@ from typing import Any
|
||||
from unittest.mock import MagicMock, call as MockCall
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.core.tree import Leaf, Tree
|
||||
from ahriman.core.tree import Tree
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.package_description import PackageDescription
|
||||
from ahriman.models.result import Result
|
||||
|
||||
|
||||
@@ -54,13 +56,11 @@ def test_print_updates(application: Application, package_ahriman: Package, mocke
|
||||
"""
|
||||
must print updates
|
||||
"""
|
||||
tree = Tree([Leaf(package_ahriman)])
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.core.tree.Tree.resolve", return_value=tree.levels())
|
||||
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||
|
||||
application.print_updates([package_ahriman], log_fn=print)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=print, separator=" -> ")
|
||||
application.print_updates(BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate), log_fn=print)
|
||||
print_mock.assert_called_once_with(verbose=True, log_fn=print, separator=": ")
|
||||
|
||||
|
||||
def test_with_dependencies(application: Application, package_ahriman: Package, package_python_schedule: Package,
|
||||
@@ -99,8 +99,11 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
return_value={"devtools", "python-build", "python-pytest"})
|
||||
status_client_mock = mocker.patch("ahriman.core.status.Client.set_unknown")
|
||||
|
||||
result = application.with_dependencies([package_ahriman], process_dependencies=True)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
result = application.with_dependencies(plan, process_dependencies=True)
|
||||
assert {package.base: package for package in result} == packages
|
||||
assert result.item(package_ahriman.base).requester is None
|
||||
assert result.item(package_python_schedule.base).requester == package_ahriman.base
|
||||
package_aur_mock.assert_has_calls([
|
||||
MockCall(package_python_schedule.base, package_ahriman.packager, include_provides=True),
|
||||
MockCall("python-installer", package_ahriman.packager, include_provides=True),
|
||||
@@ -117,6 +120,42 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
||||
], any_order=True)
|
||||
|
||||
|
||||
def test_with_dependencies_split(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must preserve resolved subpackages during dependency resolution
|
||||
"""
|
||||
def package(base: str, name: str, dependencies: list[str]) -> Package:
|
||||
return Package(
|
||||
base=base,
|
||||
version="1-1",
|
||||
remote=package_ahriman.remote,
|
||||
packages={name: PackageDescription(depends=dependencies)},
|
||||
)
|
||||
|
||||
packages = {
|
||||
"ahriman-core": package("ahriman", "ahriman-core", ["python-tree-sitter-bash"]),
|
||||
"ahriman-web": package("ahriman", "ahriman-web", ["ahriman-core"]),
|
||||
"python-tree-sitter-bash": package("python-tree-sitter-bash", "python-tree-sitter-bash", []),
|
||||
}
|
||||
mocker.patch("ahriman.application.application.Application._known_packages", return_value=set())
|
||||
mocker.patch("pathlib.Path.is_dir", return_value=False)
|
||||
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda name, *args, **kwargs: packages[name])
|
||||
mocker.patch("ahriman.core.status.Client.set_unknown")
|
||||
|
||||
plan = BuildPlan().update([
|
||||
package("ahriman", "ahriman", ["ahriman-core", "ahriman-web"])
|
||||
], BuildPlanReason.QueuedRequest)
|
||||
result = application.with_dependencies(plan, process_dependencies=True)
|
||||
assert [[item.base for item in level] for level in Tree.resolve(result)] == [
|
||||
["python-tree-sitter-bash"], ["ahriman"],
|
||||
]
|
||||
|
||||
plan_item = result.item("ahriman")
|
||||
assert plan_item.package.packages.keys() == {"ahriman", "ahriman-core", "ahriman-web"}
|
||||
assert plan_item.reason == BuildPlanReason.QueuedRequest
|
||||
assert plan_item.requester is None
|
||||
|
||||
|
||||
def test_with_dependencies_exception(application: Application, package_ahriman: Package,
|
||||
package_python_schedule: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
@@ -148,7 +187,10 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
|
||||
mocker.patch("ahriman.application.application.Application._known_packages",
|
||||
return_value={"devtools", "python-build", "python-pytest"})
|
||||
|
||||
assert not application.with_dependencies([package_ahriman], process_dependencies=True)
|
||||
plan = BuildPlan()
|
||||
plan.add(package_ahriman, BuildPlanReason.RegularUpdate)
|
||||
assert application.with_dependencies(plan, process_dependencies=True) is plan
|
||||
assert plan.packages == [package_ahriman]
|
||||
|
||||
|
||||
def test_with_dependencies_skip(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
@@ -157,8 +199,9 @@ def test_with_dependencies_skip(application: Application, package_ahriman: Packa
|
||||
"""
|
||||
packages_mock = mocker.patch("ahriman.application.application.Application._known_packages")
|
||||
|
||||
assert application.with_dependencies([package_ahriman], process_dependencies=False) == [package_ahriman]
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
assert application.with_dependencies(plan, process_dependencies=False).packages == [package_ahriman]
|
||||
packages_mock.assert_not_called()
|
||||
|
||||
assert application.with_dependencies([], process_dependencies=True) == []
|
||||
assert not application.with_dependencies(BuildPlan(), process_dependencies=True)
|
||||
packages_mock.assert_not_called()
|
||||
@@ -2,12 +2,12 @@ import argparse
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
from unittest.mock import call as MockCall
|
||||
|
||||
from ahriman.application.application import Application
|
||||
from ahriman.application.handlers.rebuild import Rebuild
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.packagers import Packagers
|
||||
@@ -48,15 +48,18 @@ def test_run(args: argparse.Namespace, package_ahriman: Package, configuration:
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on",
|
||||
return_value=[package_ahriman])
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.Rebuild)
|
||||
extract_mock.assert_called_once_with(pytest.helpers.anyvar(int), args.status, from_database=args.from_database)
|
||||
application_packages_mock.assert_called_once_with([package_ahriman], None)
|
||||
application_mock.assert_called_once_with([package_ahriman], Packagers(args.username), bump_pkgrel=args.increment)
|
||||
check_mock.assert_has_calls([MockCall(False, [package_ahriman]), MockCall(False, True)])
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
application_mock.assert_called_once_with(plan, Packagers(args.username), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(False, True)
|
||||
on_start_mock.assert_called_once_with()
|
||||
|
||||
|
||||
@@ -94,8 +97,9 @@ def test_run_dry_run(args: argparse.Namespace, configuration: Configuration, rep
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
application_mock.assert_not_called()
|
||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
||||
print_mock.assert_called_once_with([package_ahriman], log_fn=pytest.helpers.anyvar(int))
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.Rebuild)
|
||||
check_mock.assert_called_once_with(False, plan)
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
|
||||
|
||||
def test_run_filter(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@@ -109,6 +113,7 @@ def test_run_filter(args: argparse.Namespace, configuration: Configuration, repo
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
@@ -125,6 +130,7 @@ def test_run_without_filter(args: argparse.Namespace, configuration: Configurati
|
||||
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
@@ -147,7 +153,7 @@ def test_run_update_empty_exception(args: argparse.Namespace, configuration: Con
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
check_mock.assert_called_once_with(True, [])
|
||||
check_mock.assert_called_once_with(True, BuildPlan())
|
||||
|
||||
|
||||
def test_run_build_empty_exception(args: argparse.Namespace, configuration: Configuration, repository: Repository,
|
||||
@@ -161,11 +167,12 @@ def test_run_build_empty_exception(args: argparse.Namespace, configuration: Conf
|
||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages")
|
||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
_, repository_id = configuration.check_loaded()
|
||||
Rebuild.run(args, repository_id, configuration, report=False)
|
||||
check_mock.assert_has_calls([MockCall(True, [package_ahriman]), MockCall(True, False)])
|
||||
check_mock.assert_called_once_with(True, False)
|
||||
|
||||
|
||||
def test_extract_packages(application: Application, mocker: MockerFixture) -> None:
|
||||
|
||||
@@ -39,7 +39,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
||||
_, repository_id = configuration.check_loaded()
|
||||
ServiceUpdates.run(args, repository_id, configuration, report=False)
|
||||
package_mock.assert_called_once_with(package_ahriman.base, None)
|
||||
application_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" -> ")
|
||||
application_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=": ")
|
||||
check_mock.assert_called_once_with(args.exit_code, False)
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from ahriman.application.handlers.update import Update
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.repository import Repository
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.packagers import Packagers
|
||||
from ahriman.models.result import Result
|
||||
|
||||
@@ -65,22 +66,23 @@ def test_perform_action(args: argparse.Namespace, application: Application, pack
|
||||
result.add_updated(package_ahriman)
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
|
||||
return_value=[package_ahriman])
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
return_value=plan)
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
application_mock.assert_called_once_with([package_ahriman],
|
||||
application_mock.assert_called_once_with(plan,
|
||||
Packagers(args.username, {package_ahriman.base: "packager"}),
|
||||
bump_pkgrel=args.increment)
|
||||
updates_mock.assert_called_once_with(
|
||||
args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs, check_files=args.check_files)
|
||||
changes_mock.assert_called_once_with([package_ahriman])
|
||||
dependencies_mock.assert_called_once_with([package_ahriman], process_dependencies=args.dependencies)
|
||||
changes_mock.assert_called_once_with(plan)
|
||||
dependencies_mock.assert_called_once_with(plan, process_dependencies=args.dependencies)
|
||||
check_mock.assert_called_once_with(False, True)
|
||||
print_mock.assert_called_once_with([package_ahriman], log_fn=pytest.helpers.anyvar(int))
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
|
||||
|
||||
def test_perform_action_empty_exception(args: argparse.Namespace, application: Application,
|
||||
@@ -91,11 +93,13 @@ def test_perform_action_empty_exception(args: argparse.Namespace, application: A
|
||||
args = _default_args(args)
|
||||
args.exit_code = True
|
||||
args.dry_run = True
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=[])
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=BuildPlan())
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
check_mock.assert_called_once_with(True, [])
|
||||
print_mock.assert_called_once_with(BuildPlan(), pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(True, BuildPlan())
|
||||
|
||||
|
||||
def test_perform_action_update_empty_exception(args: argparse.Namespace, application: Application,
|
||||
@@ -106,10 +110,11 @@ def test_perform_action_update_empty_exception(args: argparse.Namespace, applica
|
||||
args = _default_args(args)
|
||||
args.exit_code = True
|
||||
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=[package_ahriman])
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=plan)
|
||||
mocker.patch("ahriman.application.application.Application.changes")
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
@@ -125,15 +130,21 @@ def test_perform_action_dry_run(args: argparse.Namespace, application: Applicati
|
||||
args.dry_run = True
|
||||
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
|
||||
return_value=plan)
|
||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
updates_mock.assert_called_once_with(
|
||||
args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs, check_files=args.check_files)
|
||||
application_mock.assert_not_called()
|
||||
changes_mock.assert_called_once_with([package_ahriman])
|
||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
||||
changes_mock.assert_called_once_with(plan)
|
||||
dependencies_mock.assert_called_once_with(plan, process_dependencies=args.dependencies)
|
||||
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||
check_mock.assert_called_once_with(False, plan)
|
||||
|
||||
|
||||
def test_perform_action_no_changes(args: argparse.Namespace, application: Application, mocker: MockerFixture) -> None:
|
||||
@@ -145,7 +156,9 @@ def test_perform_action_no_changes(args: argparse.Namespace, application: Applic
|
||||
args.changes = False
|
||||
mocker.patch("ahriman.application.application.Application.update")
|
||||
mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||
mocker.patch("ahriman.application.application.Application.updates")
|
||||
mocker.patch("ahriman.application.application.Application.updates", return_value=BuildPlan())
|
||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=BuildPlan())
|
||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||
|
||||
Update.perform_action(application, args)
|
||||
|
||||
@@ -23,6 +23,7 @@ from ahriman.core.formatters import (
|
||||
VersionPrinter
|
||||
)
|
||||
from ahriman.models.aur_package import AURPackage
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.build_status import BuildStatus
|
||||
from ahriman.models.changes import Changes
|
||||
from ahriman.models.package import Package
|
||||
@@ -219,7 +220,8 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
|
||||
Returns:
|
||||
UpdatePrinter: update printer test instance
|
||||
"""
|
||||
return UpdatePrinter(package_ahriman, None)
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
return UpdatePrinter(plan, {})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -53,6 +53,18 @@ def test_print_indent(mocker: MockerFixture) -> None:
|
||||
log_mock.assert_has_calls([MockCall("key: value"), MockCall("\tkey: value"), MockCall("\t\tkey: value")])
|
||||
|
||||
|
||||
def test_print_separator(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must use property separator instead of default separator
|
||||
"""
|
||||
log_mock = MagicMock()
|
||||
|
||||
mocker.patch("ahriman.core.formatters.Printer.properties", return_value=[Property("key", "value", separator=" ")])
|
||||
Printer().print(verbose=True, log_fn=log_mock)
|
||||
|
||||
log_mock.assert_called_once_with("\tkey value")
|
||||
|
||||
|
||||
def test_properties() -> None:
|
||||
"""
|
||||
must return empty properties list
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from ahriman.core.formatters import UpdatePrinter
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
from ahriman.models.property import Property
|
||||
|
||||
|
||||
@@ -13,25 +15,52 @@ def test_properties_na(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must return N/A if local version is unknown
|
||||
"""
|
||||
assert update_printer.properties() == [Property("N/A", update_printer.package.version, is_required=True)]
|
||||
package = update_printer.plan.packages[0]
|
||||
assert update_printer.properties() == [
|
||||
Property(package.base, "", is_required=True),
|
||||
Property("N/A", package.version, is_required=True, indent=2, separator=" -> "),
|
||||
Property("Reason", BuildPlanReason.RegularUpdate.value, indent=2),
|
||||
]
|
||||
|
||||
|
||||
def test_properties_bump_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
def test_properties_package_required_by(package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must include requestee package to properties
|
||||
"""
|
||||
plan = BuildPlan()
|
||||
plan.add(package_python_schedule, BuildPlanReason.RequiredBy, requester="ahriman")
|
||||
|
||||
properties = list(UpdatePrinter(plan, {}, bump_pkgrel=False).properties_package(package_python_schedule))
|
||||
assert properties[-1].value == "required by ahriman"
|
||||
|
||||
|
||||
def test_versions_bump_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must bump pkgrel if local version is the same
|
||||
"""
|
||||
update_printer.local_version = update_printer.package.version
|
||||
assert update_printer.properties() == [Property(update_printer.package.version, "2.6.0-1.1", is_required=True)]
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = package.version
|
||||
assert update_printer.versions(package) == (package.version, "2.6.0-1.1")
|
||||
|
||||
|
||||
def test_properties_keep_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
def test_versions_keep_pkgrel(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must keep pkgrel if local version is not the same
|
||||
"""
|
||||
update_printer.local_version = "2.5.0-1"
|
||||
assert update_printer.properties() == [
|
||||
Property(update_printer.local_version, update_printer.package.version, is_required=True),
|
||||
]
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = "2.5.0-1"
|
||||
assert update_printer.versions(package) == ("2.5.0-1", package.version)
|
||||
|
||||
|
||||
def test_versions_no_increment(update_printer: UpdatePrinter) -> None:
|
||||
"""
|
||||
must preserve the package version when release incrementing is disabled
|
||||
"""
|
||||
package = update_printer.plan.packages[0]
|
||||
update_printer.local_versions[package.base] = package.version
|
||||
update_printer.bump_pkgrel = False
|
||||
|
||||
assert update_printer.versions(package) == (package.version, package.version)
|
||||
|
||||
|
||||
def test_title(update_printer: UpdatePrinter) -> None:
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_add(package_ahriman: Package, package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must replace the package and reason for the same base
|
||||
"""
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
plan.add(package_ahriman, BuildPlanReason.QueuedRequest)
|
||||
plan.add(package_python_schedule, BuildPlanReason.LocalSourceUpdate)
|
||||
|
||||
assert package_ahriman in plan
|
||||
assert package_python_schedule in plan
|
||||
assert plan.item(package_ahriman.base).reason == BuildPlanReason.QueuedRequest
|
||||
|
||||
|
||||
def test_add_with_requester(package_python_schedule: Package) -> None:
|
||||
"""
|
||||
must keep the last requester for a dependency
|
||||
"""
|
||||
plan = BuildPlan()
|
||||
plan.add(package_python_schedule, BuildPlanReason.RequiredBy, requester="ahriman")
|
||||
plan.add(package_python_schedule, BuildPlanReason.RequiredBy, requester="python-ahriman")
|
||||
|
||||
assert plan.item(package_python_schedule.base).requester == "python-ahriman"
|
||||
|
||||
|
||||
def test_update(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must update instance with new packages
|
||||
"""
|
||||
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
assert package_ahriman in plan
|
||||
|
||||
|
||||
def test_eq(package_ahriman: Package) -> None:
|
||||
"""
|
||||
must compare two plans
|
||||
"""
|
||||
plan1 = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||
assert plan1 == plan1
|
||||
|
||||
plan2 = BuildPlan().update([package_ahriman], BuildPlanReason.QueuedRequest)
|
||||
assert plan1 != plan2
|
||||
|
||||
|
||||
def test_eq_other() -> None:
|
||||
"""
|
||||
must return False in case if object is not an instance of build plan
|
||||
"""
|
||||
assert BuildPlan() != 42
|
||||
@@ -0,0 +1,15 @@
|
||||
import runpy
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
|
||||
def test_main(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run the application and exit with its status
|
||||
"""
|
||||
run = mocker.patch("ahriman.application.ahriman.run", return_value=42)
|
||||
exit_mock = mocker.patch("sys.exit")
|
||||
|
||||
runpy.run_module("ahriman", run_name="__main__")
|
||||
run.assert_called_once_with()
|
||||
exit_mock.assert_called_once_with(42)
|
||||
+4
-3
@@ -7,14 +7,15 @@ ARG BUILD_DATE
|
||||
## create build user
|
||||
RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build
|
||||
|
||||
## extract container creation date and set mirror for this timestamp, set PKGEXT and refresh database next
|
||||
RUN echo "Server = https://archive.archlinux.org/repos/${BUILD_DATE//-//}/\$repo/os/\$arch" > "/etc/pacman.d/mirrorlist" && \
|
||||
pacman -Syyuu --noconfirm
|
||||
## extract container creation date and set mirror for this timestamp
|
||||
RUN echo "Server = https://archive.archlinux.org/repos/${BUILD_DATE//-//}/\$repo/os/\$arch" > "/etc/pacman.d/mirrorlist"
|
||||
## setup package cache
|
||||
RUN runuser -u build -- mkdir "/tmp/pkg" && \
|
||||
echo "PKGDEST=/tmp/pkg" >> "/etc/makepkg.conf" && \
|
||||
echo "[options]" >> "/etc/pacman.conf" && \
|
||||
echo "CacheDir = /tmp/pkg/" >> "/etc/pacman.conf"
|
||||
## refresh root image
|
||||
RUN pacman -Syyuu --noconfirm
|
||||
|
||||
## install anc configure sudo
|
||||
RUN pacman -S --noconfirm --asdeps sudo && \
|
||||
|
||||
@@ -28,6 +28,14 @@ ahriman.models.auth\_settings module
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
ahriman.models.build\_plan module
|
||||
---------------------------------
|
||||
|
||||
.. automodule:: ahriman.models.build_plan
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
ahriman.models.build\_status module
|
||||
-----------------------------------
|
||||
|
||||
|
||||
+7
-1
@@ -29,6 +29,8 @@ def _test_path(source_root: Path, source_file: Path) -> Path:
|
||||
return relative_path.parent / f"test_{source_name}"
|
||||
else:
|
||||
return relative_path.parent / f"test_view_{source_name}"
|
||||
case (*_, source_name) if source_name.startswith("__"):
|
||||
return relative_path.parent / f"test_{source_name.replace("__", "")}"
|
||||
case _:
|
||||
return relative_path.parent / f"test_{source_file.name}"
|
||||
|
||||
@@ -37,6 +39,10 @@ def test_test_coverage() -> None:
|
||||
"""
|
||||
must have test files for each source file
|
||||
"""
|
||||
def filter_files(filename: str) -> bool:
|
||||
return filename.suffix == ".py" \
|
||||
and filename.name not in ("__init__.py",)
|
||||
|
||||
package_roots = [
|
||||
Path("ahriman-core"),
|
||||
Path("ahriman-triggers"),
|
||||
@@ -46,6 +52,6 @@ def test_test_coverage() -> None:
|
||||
for package_root in package_roots:
|
||||
source_root = package_root / "src"
|
||||
|
||||
for source_file in filter(lambda fn: fn.suffix == ".py" and fn.name != "__init__.py", walk(source_root)):
|
||||
for source_file in filter(filter_files, walk(source_root)):
|
||||
test_file = package_root / "tests" / _test_path(source_root, source_file)
|
||||
assert test_file.is_file(), test_file
|
||||
Reference in new issue
Block a user