mirror of
https://github.com/arcan1s/ahriman.git
synced 2026-11-22 09:39:30 +00:00
feat: implement detailed build plan
This commit is contained in:
1 parent
dc4f2be65b
commit
56ee5d218f
21 files changed
+476
-113
No files matched your search
@@ -17,12 +17,12 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from ahriman.application.application.application_packages import ApplicationPackages
|
from ahriman.application.application.application_packages import ApplicationPackages
|
||||||
from ahriman.application.application.application_repository import ApplicationRepository
|
from ahriman.application.application.application_repository import ApplicationRepository
|
||||||
from ahriman.core.formatters import UpdatePrinter
|
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.package import Package
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
|
|
||||||
@@ -95,45 +95,41 @@ class Application(ApplicationPackages, ApplicationRepository):
|
|||||||
"""
|
"""
|
||||||
self.repository.triggers.on_stop()
|
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:
|
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
|
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()}
|
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)
|
def with_dependencies(self, plan: BuildPlan, *, process_dependencies: bool) -> BuildPlan:
|
||||||
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]:
|
|
||||||
"""
|
"""
|
||||||
add missing dependencies to list of packages. This will extract known packages, check dependencies of
|
add missing dependencies to a build plan and record which packages require them
|
||||||
the supplied packages and add packages which are not presented in the list of known packages.
|
|
||||||
|
|
||||||
Args:
|
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
|
process_dependencies(bool): if set to ``False``, dependencies will not be processed
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[Package]: updated packages list. Packager for dependencies will be copied from the original package
|
BuildPlan: selected packages and their dependencies
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
In the most cases, in order to avoid build failure, it is required to add missing packages, which can be
|
In the most cases, in order to avoid build failure, it is required to add missing packages, which can be
|
||||||
done by calling::
|
done by calling::
|
||||||
|
|
||||||
>>> application = ...
|
>>> application = ...
|
||||||
>>> packages = application.with_dependencies(packages, process_dependencies=True)
|
>>> plan = application.with_dependencies(plan, process_dependencies=True)
|
||||||
>>> application.print_updates(packages, log_fn=print)
|
>>> application.update(plan)
|
||||||
"""
|
"""
|
||||||
if not process_dependencies or not packages:
|
if not process_dependencies or not plan:
|
||||||
return packages
|
return plan
|
||||||
|
|
||||||
def missing_dependencies(sources: Iterable[Package]) -> dict[str, str | None]:
|
def missing_dependencies(sources: list[Package]) -> dict[str, str | None]:
|
||||||
# append list of known packages with packages which are in current sources
|
# append list of known packages with packages which are in current sources
|
||||||
satisfied_packages = known_packages | {
|
satisfied_packages = known_packages | {
|
||||||
single
|
single
|
||||||
@@ -148,9 +144,9 @@ class Application(ApplicationPackages, ApplicationRepository):
|
|||||||
if dependency not in satisfied_packages
|
if dependency not in satisfied_packages
|
||||||
}
|
}
|
||||||
|
|
||||||
def new_packages(root: Package) -> dict[str, Package]:
|
def new_packages(root: Package) -> list[Package]:
|
||||||
portion = {root.base: root}
|
portion = {root.base: root}
|
||||||
while missing := missing_dependencies(portion.values()):
|
while missing := missing_dependencies(list(portion.values())):
|
||||||
for package_name, packager in missing.items():
|
for package_name, packager in missing.items():
|
||||||
if (source_dir := self.repository.paths.cache_for(package_name)).is_dir():
|
if (source_dir := self.repository.paths.cache_for(package_name)).is_dir():
|
||||||
# there is local cache, load package from it
|
# there is local cache, load package from it
|
||||||
@@ -162,15 +158,17 @@ class Application(ApplicationPackages, ApplicationRepository):
|
|||||||
# register package in the database
|
# register package in the database
|
||||||
self.reporter.set_unknown(leaf)
|
self.reporter.set_unknown(leaf)
|
||||||
|
|
||||||
return portion
|
return [leaf for package_name, leaf in portion.items() if package_name != root.base]
|
||||||
|
|
||||||
known_packages = self._known_packages()
|
known_packages = self._known_packages()
|
||||||
with_dependencies: dict[str, Package] = {}
|
for package in plan:
|
||||||
for package in packages:
|
|
||||||
with self.in_package_context(package.base, package.version): # use the same context for the logger
|
with self.in_package_context(package.base, package.version): # use the same context for the logger
|
||||||
try:
|
try:
|
||||||
with_dependencies |= new_packages(package)
|
packages = new_packages(package)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception("could not process dependencies of %s, skip the package", package.base)
|
self.logger.exception("could not process dependencies of %s, skip the package", package.base)
|
||||||
|
continue
|
||||||
|
|
||||||
return list(with_dependencies.values())
|
plan.update(packages, 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.application.application.workers import Updater
|
||||||
from ahriman.core.build_tools.sources import Sources
|
from ahriman.core.build_tools.sources import Sources
|
||||||
from ahriman.core.exceptions import UnknownPackageError
|
from ahriman.core.exceptions import UnknownPackageError
|
||||||
|
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.packagers import Packagers
|
from ahriman.models.packagers import Packagers
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
@@ -182,7 +183,7 @@ class ApplicationRepository(ApplicationProperties):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def updates(self, filter_packages: Iterable[str], *,
|
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
|
get list of packages to run update process
|
||||||
|
|
||||||
@@ -193,25 +194,21 @@ class ApplicationRepository(ApplicationProperties):
|
|||||||
manual(bool): include or exclude manual updates
|
manual(bool): include or exclude manual updates
|
||||||
vcs(bool): enable or disable checking of VCS packages
|
vcs(bool): enable or disable checking of VCS packages
|
||||||
check_files(bool): check for broken dependencies
|
check_files(bool): check for broken dependencies
|
||||||
|
|
||||||
Returns:
|
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
|
# always add already built packages, because they will be always added
|
||||||
updates.update({
|
plan.update(self.repository.load_archives(self.repository.packages_built()), BuildPlanReason.PreBuilt)
|
||||||
package.base: package
|
|
||||||
for package in self.repository.load_archives(self.repository.packages_built())
|
|
||||||
})
|
|
||||||
|
|
||||||
if aur:
|
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:
|
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:
|
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:
|
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.application import Application
|
||||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||||
|
from ahriman.application.handlers.update import Update
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.utils import extract_user
|
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.build_status import BuildStatusEnum
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.packagers import Packagers
|
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 = Rebuild.extract_packages(application, args.status, from_database=args.from_database)
|
||||||
packages = application.repository.packages_depend_on(packages, args.depends_on)
|
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:
|
if args.dry_run:
|
||||||
application.print_updates(packages, log_fn=print)
|
Rebuild.check_status(args.exit_code, plan)
|
||||||
return
|
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)
|
Rebuild.check_status(args.exit_code, not result.is_empty)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from ahriman import __version__
|
|||||||
from ahriman.application.handlers.handler import Handler, SubParserAction
|
from ahriman.application.handlers.handler import Handler, SubParserAction
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.formatters import UpdatePrinter
|
from ahriman.core.formatters import UpdatePrinter
|
||||||
|
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.repository_id import RepositoryId
|
from ahriman.models.repository_id import RepositoryId
|
||||||
|
|
||||||
@@ -56,7 +57,8 @@ class ServiceUpdates(Handler):
|
|||||||
if same_version:
|
if same_version:
|
||||||
return
|
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)
|
ServiceUpdates.check_status(args.exit_code, same_version)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -147,20 +147,19 @@ class Update(Handler):
|
|||||||
application(Application): application instance
|
application(Application): application instance
|
||||||
args(argparse.Namespace): command line args
|
args(argparse.Namespace): command line args
|
||||||
"""
|
"""
|
||||||
packages = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
plan = application.updates(args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs,
|
||||||
check_files=args.check_files)
|
check_files=args.check_files)
|
||||||
|
plan = application.with_dependencies(plan, process_dependencies=args.dependencies)
|
||||||
if args.changes: # generate changes if requested
|
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
|
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
|
return
|
||||||
|
|
||||||
packages = application.with_dependencies(packages, process_dependencies=args.dependencies)
|
packagers = Packagers(args.username, {package.base: package.packager for package in plan})
|
||||||
packagers = Packagers(args.username, {package.base: package.packager for package in packages})
|
result = application.update(plan, packagers, bump_pkgrel=args.increment)
|
||||||
|
|
||||||
application.print_updates(packages, log_fn=application.logger.info)
|
|
||||||
result = application.update(packages, packagers, bump_pkgrel=args.increment)
|
|
||||||
Update.check_status(args.exit_code, not result.is_empty)
|
Update.check_status(args.exit_code, not result.is_empty)
|
||||||
|
|
||||||
arguments = [
|
arguments = [
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Printer:
|
|||||||
if not verbose and not prop.is_required:
|
if not verbose and not prop.is_required:
|
||||||
continue
|
continue
|
||||||
indent = "\t" * prop.indent
|
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]:
|
def properties(self) -> list[Property]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -17,30 +17,38 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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.formatters.string_printer import StringPrinter
|
||||||
|
from ahriman.core.tree import Tree
|
||||||
from ahriman.core.utils import full_version, parse_version
|
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.package import Package
|
||||||
from ahriman.models.property import Property
|
from ahriman.models.property import Property
|
||||||
|
|
||||||
|
|
||||||
class UpdatePrinter(StringPrinter):
|
class UpdatePrinter(StringPrinter):
|
||||||
"""
|
"""
|
||||||
print content of the package update
|
print content of the packages update
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
package(Package): remote (new) package object
|
plan(BuildPlan): plan to display
|
||||||
local_version(str | None): local version of the package if any
|
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:
|
Args:
|
||||||
remote(Package): remote (new) package object
|
plan(BuildPlan): plan to display
|
||||||
local_version(str | None): local version of the package if any
|
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)
|
StringPrinter.__init__(self, "Build plan" if plan else "No packages selected")
|
||||||
self.package = remote
|
self.plan = plan
|
||||||
self.local_version = local_version
|
self.local_versions = local_versions
|
||||||
|
self.bump_pkgrel = bump_pkgrel
|
||||||
|
|
||||||
def properties(self) -> list[Property]:
|
def properties(self) -> list[Property]:
|
||||||
"""
|
"""
|
||||||
@@ -49,9 +57,48 @@ class UpdatePrinter(StringPrinter):
|
|||||||
Returns:
|
Returns:
|
||||||
list[Property]: list of content properties
|
list[Property]: list of content properties
|
||||||
"""
|
"""
|
||||||
if (pkgrel := self.package.next_pkgrel(self.local_version)) is not None:
|
return [
|
||||||
epoch, pkgver, _ = parse_version(self.package.version)
|
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)
|
effective_new_version = full_version(epoch, pkgver, pkgrel)
|
||||||
else:
|
else:
|
||||||
effective_new_version = self.package.version
|
effective_new_version = package.version
|
||||||
return [Property(self.local_version or "N/A", effective_new_version, is_required=True)]
|
|
||||||
|
return local_version or "N/A", effective_new_version
|
||||||
@@ -188,6 +188,7 @@ class UpdateHandler(PackageInfo, Cleaner):
|
|||||||
self.reporter.set_pending(local.base)
|
self.reporter.set_pending(local.base)
|
||||||
self.event(local.base, EventType.PackageOutdated, "Locally pulled sources are outdated")
|
self.event(local.base, EventType.PackageOutdated, "Locally pulled sources are outdated")
|
||||||
result.append(remote)
|
result.append(remote)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
self.logger.exception("could not process package at %s", cache_dir)
|
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: list[Package], reason: BuildPlanReason, requester: str | None = None) -> Self:
|
||||||
|
"""
|
||||||
|
bulk update packages with the same reason
|
||||||
|
|
||||||
|
Args:
|
||||||
|
packages(list[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
|
value(Any): property value
|
||||||
is_required(bool): if set to ``True`` then this property is required
|
is_required(bool): if set to ``True`` then this property is required
|
||||||
indent(int): property indentation level
|
indent(int): property indentation level
|
||||||
|
separator(str | None): optional override for separator
|
||||||
"""
|
"""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
value: Any
|
value: Any
|
||||||
is_required: bool = field(default=False, kw_only=True)
|
is_required: bool = field(default=False, kw_only=True)
|
||||||
indent: int = 1
|
indent: int = 1
|
||||||
|
separator: str | None = None
|
||||||
@@ -4,7 +4,7 @@ from typing import Any
|
|||||||
from unittest.mock import MagicMock, call as MockCall
|
from unittest.mock import MagicMock, call as MockCall
|
||||||
|
|
||||||
from ahriman.application.application import Application
|
from ahriman.application.application import Application
|
||||||
from ahriman.core.tree import Leaf, Tree
|
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.result import Result
|
from ahriman.models.result import Result
|
||||||
|
|
||||||
@@ -54,13 +54,11 @@ def test_print_updates(application: Application, package_ahriman: Package, mocke
|
|||||||
"""
|
"""
|
||||||
must print updates
|
must print updates
|
||||||
"""
|
"""
|
||||||
tree = Tree([Leaf(package_ahriman)])
|
|
||||||
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[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")
|
print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
|
||||||
|
|
||||||
application.print_updates([package_ahriman], log_fn=print)
|
application.print_updates(BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate), log_fn=print)
|
||||||
print_mock.assert_called_once_with(verbose=True, log_fn=print, separator=" -> ")
|
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,
|
def test_with_dependencies(application: Application, package_ahriman: Package, package_python_schedule: Package,
|
||||||
@@ -99,8 +97,11 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
|
|||||||
return_value={"devtools", "python-build", "python-pytest"})
|
return_value={"devtools", "python-build", "python-pytest"})
|
||||||
status_client_mock = mocker.patch("ahriman.core.status.Client.set_unknown")
|
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 {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([
|
package_aur_mock.assert_has_calls([
|
||||||
MockCall(package_python_schedule.base, package_ahriman.packager, include_provides=True),
|
MockCall(package_python_schedule.base, package_ahriman.packager, include_provides=True),
|
||||||
MockCall("python-installer", package_ahriman.packager, include_provides=True),
|
MockCall("python-installer", package_ahriman.packager, include_provides=True),
|
||||||
@@ -148,7 +149,10 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
|
|||||||
mocker.patch("ahriman.application.application.Application._known_packages",
|
mocker.patch("ahriman.application.application.Application._known_packages",
|
||||||
return_value={"devtools", "python-build", "python-pytest"})
|
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:
|
def test_with_dependencies_skip(application: Application, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||||
@@ -157,8 +161,9 @@ def test_with_dependencies_skip(application: Application, package_ahriman: Packa
|
|||||||
"""
|
"""
|
||||||
packages_mock = mocker.patch("ahriman.application.application.Application._known_packages")
|
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()
|
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()
|
packages_mock.assert_not_called()
|
||||||
@@ -2,12 +2,12 @@ import argparse
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from unittest.mock import call as MockCall
|
|
||||||
|
|
||||||
from ahriman.application.application import Application
|
from ahriman.application.application import Application
|
||||||
from ahriman.application.handlers.rebuild import Rebuild
|
from ahriman.application.handlers.rebuild import Rebuild
|
||||||
from ahriman.core.configuration import Configuration
|
from ahriman.core.configuration import Configuration
|
||||||
from ahriman.core.repository import Repository
|
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.build_status import BuildStatus, BuildStatusEnum
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
from ahriman.models.packagers import Packagers
|
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",
|
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on",
|
||||||
return_value=[package_ahriman])
|
return_value=[package_ahriman])
|
||||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
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")
|
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||||
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
on_start_mock = mocker.patch("ahriman.application.application.Application.on_start")
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
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)
|
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_packages_mock.assert_called_once_with([package_ahriman], None)
|
||||||
application_mock.assert_called_once_with([package_ahriman], Packagers(args.username), bump_pkgrel=args.increment)
|
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
|
||||||
check_mock.assert_has_calls([MockCall(False, [package_ahriman]), MockCall(False, True)])
|
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()
|
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()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
Rebuild.run(args, repository_id, configuration, report=False)
|
||||||
application_mock.assert_not_called()
|
application_mock.assert_not_called()
|
||||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
plan = BuildPlan().update([package_ahriman], BuildPlanReason.Rebuild)
|
||||||
print_mock.assert_called_once_with([package_ahriman], log_fn=pytest.helpers.anyvar(int))
|
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,
|
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.core.repository.Repository.load", return_value=repository)
|
||||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
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()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
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.core.repository.Repository.load", return_value=repository)
|
||||||
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
mocker.patch("ahriman.application.handlers.rebuild.Rebuild.extract_packages", return_value=[])
|
||||||
application_packages_mock = mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on")
|
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()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
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()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
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,
|
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.application.handlers.rebuild.Rebuild.extract_packages")
|
||||||
mocker.patch("ahriman.core.repository.repository.Repository.packages_depend_on", return_value=[package_ahriman])
|
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.update", return_value=Result())
|
||||||
|
mocker.patch("ahriman.application.application.Application.print_updates")
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||||
|
|
||||||
_, repository_id = configuration.check_loaded()
|
_, repository_id = configuration.check_loaded()
|
||||||
Rebuild.run(args, repository_id, configuration, report=False)
|
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:
|
def test_extract_packages(application: Application, mocker: MockerFixture) -> None:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import pytest
|
|
||||||
|
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
|
|
||||||
@@ -39,7 +38,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
|
|||||||
_, repository_id = configuration.check_loaded()
|
_, repository_id = configuration.check_loaded()
|
||||||
ServiceUpdates.run(args, repository_id, configuration, report=False)
|
ServiceUpdates.run(args, repository_id, configuration, report=False)
|
||||||
package_mock.assert_called_once_with(package_ahriman.base, None)
|
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=print, separator=": ")
|
||||||
check_mock.assert_called_once_with(args.exit_code, False)
|
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.configuration import Configuration
|
||||||
from ahriman.core.repository import Repository
|
from ahriman.core.repository import Repository
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
|
from ahriman.models.build_plan import BuildPlan, BuildPlanReason
|
||||||
from ahriman.models.packagers import Packagers
|
from ahriman.models.packagers import Packagers
|
||||||
from ahriman.models.result import Result
|
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)
|
result.add_updated(package_ahriman)
|
||||||
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
application_mock = mocker.patch("ahriman.application.application.Application.update", return_value=result)
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
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",
|
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
|
||||||
return_value=[package_ahriman])
|
return_value=plan)
|
||||||
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||||
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||||
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
|
||||||
|
|
||||||
Update.perform_action(application, args)
|
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"}),
|
Packagers(args.username, {package_ahriman.base: "packager"}),
|
||||||
bump_pkgrel=args.increment)
|
bump_pkgrel=args.increment)
|
||||||
updates_mock.assert_called_once_with(
|
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)
|
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])
|
changes_mock.assert_called_once_with(plan)
|
||||||
dependencies_mock.assert_called_once_with([package_ahriman], process_dependencies=args.dependencies)
|
dependencies_mock.assert_called_once_with(plan, process_dependencies=args.dependencies)
|
||||||
check_mock.assert_called_once_with(False, True)
|
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,
|
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 = _default_args(args)
|
||||||
args.exit_code = True
|
args.exit_code = True
|
||||||
args.dry_run = 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")
|
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||||
|
|
||||||
Update.perform_action(application, args)
|
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,
|
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 = _default_args(args)
|
||||||
args.exit_code = True
|
args.exit_code = True
|
||||||
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
mocker.patch("ahriman.application.application.Application.update", return_value=Result())
|
||||||
mocker.patch("ahriman.application.application.Application.updates", return_value=[package_ahriman])
|
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||||
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=[package_ahriman])
|
mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
|
||||||
mocker.patch("ahriman.application.application.Application.print_updates")
|
mocker.patch("ahriman.application.application.Application.with_dependencies", return_value=plan)
|
||||||
mocker.patch("ahriman.application.application.Application.changes")
|
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")
|
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
||||||
|
|
||||||
Update.perform_action(application, args)
|
Update.perform_action(application, args)
|
||||||
@@ -125,15 +130,21 @@ def test_perform_action_dry_run(args: argparse.Namespace, application: Applicati
|
|||||||
args.dry_run = True
|
args.dry_run = True
|
||||||
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
application_mock = mocker.patch("ahriman.application.application.Application.update")
|
||||||
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
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")
|
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||||
|
|
||||||
Update.perform_action(application, args)
|
Update.perform_action(application, args)
|
||||||
updates_mock.assert_called_once_with(
|
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)
|
args.package, aur=args.aur, local=args.local, manual=args.manual, vcs=args.vcs, check_files=args.check_files)
|
||||||
application_mock.assert_not_called()
|
application_mock.assert_not_called()
|
||||||
changes_mock.assert_called_once_with([package_ahriman])
|
changes_mock.assert_called_once_with(plan)
|
||||||
check_mock.assert_called_once_with(False, [package_ahriman])
|
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:
|
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
|
args.changes = False
|
||||||
mocker.patch("ahriman.application.application.Application.update")
|
mocker.patch("ahriman.application.application.Application.update")
|
||||||
mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
|
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")
|
changes_mock = mocker.patch("ahriman.application.application.Application.changes")
|
||||||
|
|
||||||
Update.perform_action(application, args)
|
Update.perform_action(application, args)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from ahriman.core.formatters import (
|
|||||||
VersionPrinter
|
VersionPrinter
|
||||||
)
|
)
|
||||||
from ahriman.models.aur_package import AURPackage
|
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.build_status import BuildStatus
|
||||||
from ahriman.models.changes import Changes
|
from ahriman.models.changes import Changes
|
||||||
from ahriman.models.package import Package
|
from ahriman.models.package import Package
|
||||||
@@ -219,7 +220,8 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
|
|||||||
Returns:
|
Returns:
|
||||||
UpdatePrinter: update printer test instance
|
UpdatePrinter: update printer test instance
|
||||||
"""
|
"""
|
||||||
return UpdatePrinter(package_ahriman, None)
|
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate)
|
||||||
|
return UpdatePrinter(plan, {})
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@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")])
|
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:
|
def test_properties() -> None:
|
||||||
"""
|
"""
|
||||||
must return empty properties list
|
must return empty properties list
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
from ahriman.core.formatters import UpdatePrinter
|
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
|
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
|
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
|
must bump pkgrel if local version is the same
|
||||||
"""
|
"""
|
||||||
update_printer.local_version = update_printer.package.version
|
package = update_printer.plan.packages[0]
|
||||||
assert update_printer.properties() == [Property(update_printer.package.version, "2.6.0-1.1", is_required=True)]
|
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
|
must keep pkgrel if local version is not the same
|
||||||
"""
|
"""
|
||||||
update_printer.local_version = "2.5.0-1"
|
package = update_printer.plan.packages[0]
|
||||||
assert update_printer.properties() == [
|
update_printer.local_versions[package.base] = "2.5.0-1"
|
||||||
Property(update_printer.local_version, update_printer.package.version, is_required=True),
|
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:
|
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
|
||||||
+4
-3
@@ -7,14 +7,15 @@ ARG BUILD_DATE
|
|||||||
## create build user
|
## create build user
|
||||||
RUN useradd -m -d "/home/build" -s "/usr/bin/nologin" build
|
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
|
## 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" && \
|
RUN echo "Server = https://archive.archlinux.org/repos/${BUILD_DATE//-//}/\$repo/os/\$arch" > "/etc/pacman.d/mirrorlist"
|
||||||
pacman -Syyuu --noconfirm
|
|
||||||
## setup package cache
|
## setup package cache
|
||||||
RUN runuser -u build -- mkdir "/tmp/pkg" && \
|
RUN runuser -u build -- mkdir "/tmp/pkg" && \
|
||||||
echo "PKGDEST=/tmp/pkg" >> "/etc/makepkg.conf" && \
|
echo "PKGDEST=/tmp/pkg" >> "/etc/makepkg.conf" && \
|
||||||
echo "[options]" >> "/etc/pacman.conf" && \
|
echo "[options]" >> "/etc/pacman.conf" && \
|
||||||
echo "CacheDir = /tmp/pkg/" >> "/etc/pacman.conf"
|
echo "CacheDir = /tmp/pkg/" >> "/etc/pacman.conf"
|
||||||
|
## refresh root image
|
||||||
|
RUN pacman -Syyuu --noconfirm
|
||||||
|
|
||||||
## install anc configure sudo
|
## install anc configure sudo
|
||||||
RUN pacman -S --noconfirm --asdeps sudo && \
|
RUN pacman -S --noconfirm --asdeps sudo && \
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ ahriman.models.auth\_settings module
|
|||||||
:no-undoc-members:
|
:no-undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
|
ahriman.models.build\_plan module
|
||||||
|
---------------------------------
|
||||||
|
|
||||||
|
.. automodule:: ahriman.models.build_plan
|
||||||
|
:members:
|
||||||
|
:no-undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
ahriman.models.build\_status module
|
ahriman.models.build\_status module
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ In this scenario, the update process must be separated into several stages. Firs
|
|||||||
|
|
||||||
sudo -u ahriman ahriman repo-check
|
sudo -u ahriman ahriman repo-check
|
||||||
|
|
||||||
|
The command prints selected packages in dependency steps, with the old and proposed versions and the reason each package was selected. ``repo-update --dry-run`` uses the same preview. Proposed ``pkgrel`` values follow the ``--increment`` option. The preview describes current metadata; it does not freeze sources or guarantee later build inputs.
|
||||||
|
|
||||||
During the check process, the service will generate changes from the last known commit and will send it to remote service. In order to verify source files changes, the web interface or special subcommand can be used:
|
During the check process, the service will generate changes from the last known commit and will send it to remote service. In order to verify source files changes, the web interface or special subcommand can be used:
|
||||||
|
|
||||||
.. code-block:: shell
|
.. code-block:: shell
|
||||||
|
|||||||
Reference in new issue
Block a user