Compare commits

...
6 Commits
Author SHA1 Message Date
arcanis a428b62993 docs: fix types in docstrings 2026-11-19 15:50:36 +02:00
arcanis 0bd22a049c type: add type annotation pylint check
Also run pylint against tests tree
2026-11-18 14:30:17 +02:00
arcanis 71c5d58264 fix: remove packages with broken dependencies from build plan and mark
them as failed
2026-11-18 11:20:43 +02:00
arcanis 22c763ed52 build: update frontend dependencies 2026-11-18 10:36:39 +02:00
arcanis 36b7972b26 style: add more pylint checks and update code for them 2026-11-18 10:36:19 +02:00
arcanis 4f839a7e6a feat: simplify buildplan api and keep original reasons 2026-11-18 10:35:46 +02:00
260 changed files with 1296 additions and 1128 deletions

No files matched your search

+21 -23
View File
@@ -1,10 +1,14 @@
[tool.pylint.main] [tool.pylint.main]
init-hook = "sys.path.append('tools')" init-hook = "sys.path.append('tools')"
load-plugins = [ load-plugins = [
"pylint.extensions.docparams",
"pylint.extensions.bad_builtin", "pylint.extensions.bad_builtin",
"pylint.extensions.check_elif",
"pylint.extensions.docparams",
"pylint.extensions.overlapping_exceptions",
"pylint.extensions.typing",
"pylint_plugins.definition_order", "pylint_plugins.definition_order",
"pylint_plugins.import_order", "pylint_plugins.import_order",
"pylint_plugins.type_annotations",
] ]
[tool.pylint.classes] [tool.pylint.classes]
@@ -17,29 +21,23 @@ max-parents = 15
[tool.pylint."messages control"] [tool.pylint."messages control"]
disable = [ disable = [
"raw-checker-failed",
"bad-inline-option",
"locally-disabled",
"file-ignored",
"suppressed-message",
"useless-suppression",
"deprecated-pragma",
"use-symbolic-message-instead",
"use-implicit-booleaness-not-comparison-to-string",
"use-implicit-booleaness-not-comparison-to-zero",
"missing-module-docstring",
"line-too-long",
"no-name-in-module",
"import-outside-toplevel",
"invalid-name",
"raise-missing-from",
"wrong-import-order",
"too-few-public-methods",
"too-many-instance-attributes",
"broad-exception-caught", "broad-exception-caught",
"fixme",
"too-many-arguments",
"duplicate-code",
"cyclic-import", "cyclic-import",
"duplicate-code",
"fixme",
"import-outside-toplevel",
"line-too-long",
"missing-module-docstring",
"no-name-in-module",
"raise-missing-from",
"raw-checker-failed",
"suppressed-message",
"too-few-public-methods",
"too-many-arguments",
"too-many-instance-attributes",
"too-many-positional-arguments", "too-many-positional-arguments",
"wrong-import-order",
] ]
[tool.pylint.string]
check-quote-consistency = true
@@ -45,7 +45,7 @@ class Application(ApplicationPackages, ApplicationRepository):
>>> application.add(["ahriman"], PackageSource.AUR) >>> application.add(["ahriman"], PackageSource.AUR)
>>> >>>
>>> # check for updates >>> # check for updates
>>> updates = application.updates([], aur=True, local=True, manual=True, vcs=True) >>> updates = application.updates([], aur=True, local=True, manual=True, vcs=True, check_files=False)
>>> # updates for specified packages >>> # updates for specified packages
>>> application.update(updates) >>> application.update(updates)
@@ -170,12 +170,13 @@ class Application(ApplicationPackages, ApplicationRepository):
packages = 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)
plan.remove(package.base)
self.reporter.set_failed(package.base)
continue continue
# update existing package # update existing package
item = plan.item(package.base) plan.add(packages.pop(package.base))
plan.add(packages.pop(package.base), item.reason, item.requester)
# append dependencies # append dependencies
plan.update(packages.values(), BuildPlanReason.RequiredBy, package.base) plan.update(packages.values(), BuildPlanReason.REQUIRED_BY, package.base)
return plan return plan
@@ -38,14 +38,14 @@ class ApplicationProperties(LazyLogging):
""" """
def __init__(self, repository_id: RepositoryId, configuration: Configuration, *, report: bool, def __init__(self, repository_id: RepositoryId, configuration: Configuration, *, report: bool,
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.Disabled) -> None: refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.DISABLED) -> None:
""" """
Args: Args:
repository_id(RepositoryId): repository unique identifier repository_id(RepositoryId): repository unique identifier
configuration(Configuration): configuration instance configuration(Configuration): configuration instance
report(bool): force enable or disable reporting report(bool): force enable or disable reporting
refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level
(Default value = PacmanSynchronization.Disabled) (Default value = PacmanSynchronization.DISABLED)
""" """
self.configuration = configuration self.configuration = configuration
self.repository_id = repository_id self.repository_id = repository_id
@@ -200,15 +200,18 @@ class ApplicationRepository(ApplicationProperties):
plan = BuildPlan() plan = BuildPlan()
# always add already built packages, because they will be always added # always add already built packages, because they will be always added
plan.update(self.repository.load_archives(self.repository.packages_built()), BuildPlanReason.PreBuilt) plan.update(self.repository.load_archives(self.repository.packages_built()), BuildPlanReason.PRE_BUILT)
if aur:
plan.update(self.repository.updates_aur(filter_packages, vcs=vcs), BuildPlanReason.RegularUpdate)
if local:
plan.update(self.repository.updates_local(vcs=vcs), BuildPlanReason.LocalSourceUpdate)
if manual: if manual:
plan.update(self.repository.updates_manual(), BuildPlanReason.QueuedRequest) plan.update(self.repository.updates_manual(), BuildPlanReason.MANUAL_REQUEST)
if aur:
plan.update(self.repository.updates_aur(filter_packages, vcs=vcs), BuildPlanReason.REGULAR_UPDATE)
if local:
plan.update(self.repository.updates_local(vcs=vcs), BuildPlanReason.LOCAL_SOURCE_UPDATE)
if check_files: if check_files:
plan.update(self.repository.updates_dependencies(filter_packages), BuildPlanReason.BrokenImplicitDependency) plan.update(
self.repository.updates_dependencies(filter_packages),
BuildPlanReason.BROKEN_IMPLICIT_DEPENDENCY,
)
return plan return plan
@@ -41,7 +41,7 @@ class UpdatesIterator(Iterator[list[str] | None]):
Typical usage of this class is something like: Typical usage of this class is something like:
>>> application = ... >>> application = ...
>>> iterator = UpdatesIterator(application, None) >>> iterator = UpdatesIterator(application, 3600)
>>> >>>
>>> for updates in iterator: >>> for updates in iterator:
>>> print(updates) >>> print(updates)
@@ -85,7 +85,7 @@ class Add(Handler):
action=argparse.BooleanOptionalAction, default=True) action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("-n", "--now", help="run update function after", action="store_true") parser.add_argument("-n", "--now", help="run update function after", action="store_true")
parser.add_argument("-s", "--source", help="explicitly specify the package source for this command", parser.add_argument("-s", "--source", help="explicitly specify the package source for this command",
type=PackageSource, choices=tuple(PackageSource), default=PackageSource.Auto) type=PackageSource, choices=tuple(PackageSource), default=PackageSource.AUTO)
parser.add_argument("-u", "--username", help="build as user", default=extract_user()) parser.add_argument("-u", "--username", help="build as user", default=extract_user())
parser.add_argument("-v", "--variable", help="apply specified makepkg variables to the next build", parser.add_argument("-v", "--variable", help="apply specified makepkg variables to the next build",
action="append") action="append")
@@ -50,10 +50,10 @@ class Archives(Handler):
application = Application(repository_id, configuration, report=True) application = Application(repository_id, configuration, report=True)
match args.action: match args.action:
case Action.List: case Action.LIST:
archives = application.repository.package_archives(args.package) archives = application.repository.package_archives(args.package)
for package in archives: for package in archives:
PackagePrinter(package, BuildStatus(BuildStatusEnum.Success))(verbose=args.info) PackagePrinter(package, BuildStatus(BuildStatusEnum.SUCCESS))(verbose=args.info)
Archives.check_status(args.exit_code, bool(archives)) Archives.check_status(args.exit_code, bool(archives))
@@ -75,7 +75,7 @@ class Archives(Handler):
action="store_true") action="store_true")
parser.add_argument("--info", help="show additional package information", parser.add_argument("--info", help="show additional package information",
action=argparse.BooleanOptionalAction, default=False) action=argparse.BooleanOptionalAction, default=False)
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
arguments = [_set_package_archives_parser] arguments = [_set_package_archives_parser]
@@ -50,11 +50,11 @@ class Change(Handler):
client = Application(repository_id, configuration, report=True).reporter client = Application(repository_id, configuration, report=True).reporter
match args.action: match args.action:
case Action.List: case Action.LIST:
changes = client.package_changes_get(args.package) changes = client.package_changes_get(args.package)
ChangesPrinter(changes)(verbose=True, separator="") ChangesPrinter(changes)(verbose=True, separator="")
Change.check_status(args.exit_code, changes.changes is not None) Change.check_status(args.exit_code, changes.changes is not None)
case Action.Remove: case Action.REMOVE:
client.package_changes_update(args.package, Changes()) client.package_changes_update(args.package, Changes())
@staticmethod @staticmethod
@@ -75,7 +75,7 @@ class Change(Handler):
parser.add_argument("package", help="package base") parser.add_argument("package", help="package base")
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty", parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
action="store_true") action="store_true")
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -92,7 +92,7 @@ class Change(Handler):
parser = root.add_parser("package-changes-remove", help="remove package changes", parser = root.add_parser("package-changes-remove", help="remove package changes",
description="remove the package changes stored remotely") description="remove the package changes stored remotely")
parser.add_argument("package", help="package base") parser.add_argument("package", help="package base")
parser.set_defaults(action=Action.Remove, exit_code=False, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.REMOVE, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
arguments = [_set_package_changes_parser, _set_package_changes_remove_parser] arguments = [_set_package_changes_parser, _set_package_changes_remove_parser]
@@ -103,7 +103,7 @@ class Copy(Handler):
for source in package.packages.values() for source in package.packages.values()
if source.filename is not None if source.filename is not None
] ]
application.add(source_paths, PackageSource.Archive) application.add(source_paths, PackageSource.ARCHIVE)
# copy metadata # copy metadata
application.reporter.package_changes_update( application.reporter.package_changes_update(
@@ -112,6 +112,6 @@ class Copy(Handler):
application.reporter.package_dependencies_update( application.reporter.package_dependencies_update(
package.base, source_application.reporter.package_dependencies_get(package.base) package.base, source_application.reporter.package_dependencies_get(package.base)
) )
application.reporter.package_update(package, BuildStatusEnum.Pending) application.reporter.package_update(package, BuildStatusEnum.PENDING)
arguments = [_set_package_copy_parser] arguments = [_set_package_copy_parser]
@@ -46,10 +46,10 @@ class Hold(Handler):
client = Application(repository_id, configuration, report=True).reporter client = Application(repository_id, configuration, report=True).reporter
match args.action: match args.action:
case Action.Remove: case Action.REMOVE:
for package in args.package: for package in args.package:
client.package_hold_update(package, enabled=False) client.package_hold_update(package, enabled=False)
case Action.Update: case Action.UPDATE:
for package in args.package: for package in args.package:
client.package_hold_update(package, enabled=True) client.package_hold_update(package, enabled=True)
@@ -67,7 +67,7 @@ class Hold(Handler):
parser = root.add_parser("package-hold", help="hold package", parser = root.add_parser("package-hold", help="hold package",
description="hold package from automatic updates") description="hold package from automatic updates")
parser.add_argument("package", help="package base", nargs="+") parser.add_argument("package", help="package base", nargs="+")
parser.set_defaults(action=Action.Update, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.UPDATE, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -84,7 +84,7 @@ class Hold(Handler):
parser = root.add_parser("package-unhold", help="unhold package", parser = root.add_parser("package-unhold", help="unhold package",
description="remove package hold, allowing automatic updates") description="remove package hold, allowing automatic updates")
parser.add_argument("package", help="package base", nargs="+") parser.add_argument("package", help="package base", nargs="+")
parser.set_defaults(action=Action.Remove, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.REMOVE, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
arguments = [ arguments = [
@@ -56,15 +56,15 @@ class Patch(Handler):
application.on_start() application.on_start()
match args.action: match args.action:
case Action.Update if args.variable is not None: case Action.UPDATE if args.variable is not None:
patch = Patch.patch_create_from_function(args.variable, args.patch) patch = Patch.patch_create_from_function(args.variable, args.patch)
Patch.patch_set_create(application, args.package, patch) Patch.patch_set_create(application, args.package, patch)
case Action.Update: case Action.UPDATE:
package_base, patch = Patch.patch_create_from_diff(args.package, repository_id.architecture, args.track) package_base, patch = Patch.patch_create_from_diff(args.package, repository_id.architecture, args.track)
Patch.patch_set_create(application, package_base, patch) Patch.patch_set_create(application, package_base, patch)
case Action.List: case Action.LIST:
Patch.patch_set_list(application, args.package, args.variable, args.exit_code) Patch.patch_set_list(application, args.package, args.variable, args.exit_code)
case Action.Remove: case Action.REMOVE:
Patch.patch_set_remove(application, args.package, args.variable) Patch.patch_set_remove(application, args.package, args.variable)
@staticmethod @staticmethod
@@ -89,7 +89,7 @@ class Patch(Handler):
"it must end with ()") "it must end with ()")
parser.add_argument("patch", help="path to file which contains function or variable value. If not set, " parser.add_argument("patch", help="path to file which contains function or variable value. If not set, "
"the value will be read from stdin", type=Path, nargs="?") "the value will be read from stdin", type=Path, nargs="?")
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, report=False, parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, report=False,
repository="") repository="")
return parser return parser
@@ -111,7 +111,7 @@ class Patch(Handler):
action="store_true") action="store_true")
parser.add_argument("-v", "--variable", help="if set, show only patches for specified PKGBUILD variables", parser.add_argument("-v", "--variable", help="if set, show only patches for specified PKGBUILD variables",
action="append") action="append")
parser.set_defaults(action=Action.List, architecture="", lock=None, report=False, repository="", unsafe=True) parser.set_defaults(action=Action.LIST, architecture="", lock=None, report=False, repository="", unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -132,7 +132,7 @@ class Patch(Handler):
"to remove only specified PKGBUILD variables. In case if not set, " "to remove only specified PKGBUILD variables. In case if not set, "
"it will remove all patches related to the package", "it will remove all patches related to the package",
action="append") action="append")
parser.set_defaults(action=Action.Remove, architecture="", exit_code=False, lock=None, report=False, parser.set_defaults(action=Action.REMOVE, architecture="", exit_code=False, lock=None, report=False,
repository="") repository="")
return parser return parser
@@ -157,7 +157,7 @@ class Patch(Handler):
parser.add_argument("package", help="path to directory with changed files for patch addition/update", type=Path) parser.add_argument("package", help="path to directory with changed files for patch addition/update", type=Path)
parser.add_argument("-t", "--track", help="files which has to be tracked", action="append", parser.add_argument("-t", "--track", help="files which has to be tracked", action="append",
default=["*.diff", "*.patch"]) default=["*.diff", "*.patch"])
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, report=False, parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, report=False,
repository="", variable=None) repository="", variable=None)
return parser return parser
@@ -51,11 +51,11 @@ class Pkgbuild(Handler):
client = Application(repository_id, configuration, report=True).reporter client = Application(repository_id, configuration, report=True).reporter
match args.action: match args.action:
case Action.List: case Action.LIST:
changes = client.package_changes_get(args.package) changes = client.package_changes_get(args.package)
PkgbuildPrinter(changes)(verbose=True, separator="") PkgbuildPrinter(changes)(verbose=True, separator="")
Pkgbuild.check_status(args.exit_code, changes.pkgbuild is not None) Pkgbuild.check_status(args.exit_code, changes.pkgbuild is not None)
case Action.Remove: case Action.REMOVE:
changes = client.package_changes_get(args.package) changes = client.package_changes_get(args.package)
client.package_changes_update(args.package, replace(changes, pkgbuild=None)) client.package_changes_update(args.package, replace(changes, pkgbuild=None))
@@ -77,7 +77,7 @@ class Pkgbuild(Handler):
parser.add_argument("package", help="package base") parser.add_argument("package", help="package base")
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty", parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
action="store_true") action="store_true")
parser.set_defaults(action=Action.List, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.LIST, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -94,7 +94,7 @@ class Pkgbuild(Handler):
parser = root.add_parser("package-pkgbuild-remove", help="remove package pkgbuild", parser = root.add_parser("package-pkgbuild-remove", help="remove package pkgbuild",
description="remove the package PKGBUILD stored remotely") description="remove the package PKGBUILD stored remotely")
parser.add_argument("package", help="package base") parser.add_argument("package", help="package base")
parser.set_defaults(action=Action.Remove, exit_code=False, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.REMOVE, exit_code=False, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
arguments = [_set_package_pkgbuild_parser, _set_package_pkgbuild_remove_parser] arguments = [_set_package_pkgbuild_parser, _set_package_pkgbuild_remove_parser]
@@ -54,7 +54,7 @@ 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)
plan = BuildPlan().update(packages, BuildPlanReason.Rebuild) plan = BuildPlan().update(packages, BuildPlanReason.REBUILD)
application.print_updates(plan, Update.log_fn(application, dry_run=args.dry_run), bump_pkgrel=args.increment) 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:
@@ -82,7 +82,7 @@ class Rollback(Handler):
parser.add_argument("-u", "--username", help="build as user", default=extract_user()) parser.add_argument("-u", "--username", help="build as user", default=extract_user())
parser.set_defaults(aur=False, changes=False, check_files=False, dependencies=False, dry_run=False, parser.set_defaults(aur=False, changes=False, check_files=False, dependencies=False, dry_run=False,
exit_code=True, increment=False, now=True, local=False, manual=False, refresh=False, exit_code=True, increment=False, now=True, local=False, manual=False, refresh=False,
source=PackageSource.Archive, variable=None, vcs=False) source=PackageSource.ARCHIVE, variable=None, vcs=False)
return parser return parser
@staticmethod @staticmethod
@@ -57,7 +57,7 @@ class ServiceUpdates(Handler):
if same_version: if same_version:
return return
plan = BuildPlan().update([remote], BuildPlanReason.RegularUpdate) plan = BuildPlan().update([remote], BuildPlanReason.REGULAR_UPDATE)
UpdatePrinter(plan, {remote.base: local_version})(verbose=True) UpdatePrinter(plan, {remote.base: local_version})(verbose=True)
ServiceUpdates.check_status(args.exit_code, same_version) ServiceUpdates.check_status(args.exit_code, same_version)
@@ -85,7 +85,7 @@ class Statistics(Handler):
parser.add_argument("package", help="fetch only events for the specified package", nargs="?") parser.add_argument("package", help="fetch only events for the specified package", nargs="?")
parser.add_argument("--chart", help="create updates chart and save it to the specified path", type=Path) parser.add_argument("--chart", help="create updates chart and save it to the specified path", type=Path)
parser.add_argument("-e", "--event", help="event type filter", parser.add_argument("-e", "--event", help="event type filter",
type=EventType, choices=tuple(EventType), default=EventType.PackageUpdated) type=EventType, choices=tuple(EventType), default=EventType.PACKAGE_UPDATED)
parser.add_argument("--from-date", help="only fetch events which are newer than the date") parser.add_argument("--from-date", help="only fetch events which are newer than the date")
parser.add_argument("--limit", help="limit response by specified amount of events", type=int, default=-1) parser.add_argument("--limit", help="limit response by specified amount of events", type=int, default=-1)
parser.add_argument("--offset", help="skip specified amount of events", type=int, default=0) parser.add_argument("--offset", help="skip specified amount of events", type=int, default=0)
@@ -158,7 +158,7 @@ class Statistics(Handler):
Args: Args:
event_type(str): event type event_type(str): event type
events(list[Event]): list of events events(list[Event]): list of events
chart_path(Path): path to save plot if any chart_path(Path | None): path to save plot if any
""" """
# event statistics # event statistics
Statistics.event_stats(event_type, events) Statistics.event_stats(event_type, events)
@@ -175,7 +175,7 @@ class Statistics(Handler):
Args: Args:
event_type(str): event type event_type(str): event type
events(list[Event]): list of events events(list[Event]): list of events
chart_path(Path): path to save plot if any chart_path(Path | None): path to save plot if any
""" """
key: Callable[[Event], str] = lambda event: event.object_id key: Callable[[Event], str] = lambda event: event.object_id
by_object_id = { by_object_id = {
@@ -49,14 +49,14 @@ class StatusUpdate(Handler):
client = Application(repository_id, configuration, report=True).reporter client = Application(repository_id, configuration, report=True).reporter
match args.action: match args.action:
case Action.Update if args.package: case Action.UPDATE if args.package:
# update packages statuses # update packages statuses
for package in args.package: for package in args.package:
client.package_status_update(package, args.status) client.package_status_update(package, args.status)
case Action.Update: case Action.UPDATE:
# update service status # update service status
client.status_update(args.status) client.status_update(args.status)
case Action.Remove: case Action.REMOVE:
for package in args.package: for package in args.package:
client.package_remove(package) client.package_remove(package)
@@ -76,7 +76,7 @@ class StatusUpdate(Handler):
epilog="Please note that this subcommand does not remove the package itself, it just " epilog="Please note that this subcommand does not remove the package itself, it just "
"clears the status page.") "clears the status page.")
parser.add_argument("package", help="remove specified packages from status page", nargs="+") parser.add_argument("package", help="remove specified packages from status page", nargs="+")
parser.set_defaults(action=Action.Remove, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.REMOVE, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -96,8 +96,8 @@ class StatusUpdate(Handler):
"If no packages supplied, service status will be updated", "If no packages supplied, service status will be updated",
nargs="*") nargs="*")
parser.add_argument("-s", "--status", help="new package build status", parser.add_argument("-s", "--status", help="new package build status",
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.Success) type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.SUCCESS)
parser.set_defaults(action=Action.Update, lock=None, quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.UPDATE, lock=None, quiet=True, report=False, unsafe=True)
return parser return parser
@staticmethod @staticmethod
@@ -114,8 +114,8 @@ class StatusUpdate(Handler):
parser = root.add_parser("repo-status-update", help="update repository status", parser = root.add_parser("repo-status-update", help="update repository status",
description="update repository status on the status page") description="update repository status on the status page")
parser.add_argument("-s", "--status", help="new status", parser.add_argument("-s", "--status", help="new status",
type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.Success) type=BuildStatusEnum, choices=tuple(BuildStatusEnum), default=BuildStatusEnum.SUCCESS)
parser.set_defaults(action=Action.Update, lock=None, package=[], quiet=True, report=False, unsafe=True) parser.set_defaults(action=Action.UPDATE, lock=None, package=[], quiet=True, report=False, unsafe=True)
return parser return parser
arguments = [ arguments = [
@@ -77,7 +77,7 @@ class UnsafeCommands(Handler):
check if command is unsafe check if command is unsafe
Args: Args:
command(str): command to check command(list[str]): command and arguments to check
unsafe_commands(list[str]): list of unsafe commands unsafe_commands(list[str]): list of unsafe commands
parser(argparse.ArgumentParser): generated argument parser parser(argparse.ArgumentParser): generated argument parser
""" """
@@ -53,17 +53,17 @@ class Users(Handler):
database = SQLite.load(configuration) database = SQLite.load(configuration)
match args.action: match args.action:
case Action.Update: case Action.UPDATE:
user = Users.user_create(args) user = Users.user_create(args)
# if password is left blank we are not going to require salt to be set # if password is left blank we are not going to require salt to be set
salt = configuration.get("auth", "salt", fallback="") if user.password else "" salt = configuration.get("auth", "salt", fallback="") if user.password else ""
database.user_update(user.hash_password(salt)) database.user_update(user.hash_password(salt))
case Action.List: case Action.LIST:
users = database.user_list(args.username, args.role) users = database.user_list(args.username, args.role)
for user in users: for user in users:
UserPrinter(user)(verbose=True) UserPrinter(user)(verbose=True)
Users.check_status(args.exit_code, users) Users.check_status(args.exit_code, users)
case Action.Remove: case Action.REMOVE:
database.user_remove(args.username) database.user_remove(args.username)
@staticmethod @staticmethod
@@ -88,8 +88,8 @@ class Users(Handler):
"-p", "--password", help="user password. Blank password will be treated as empty password, " "-p", "--password", help="user password. Blank password will be treated as empty password, "
"which is in particular must be used for OAuth2 authorization type.") "which is in particular must be used for OAuth2 authorization type.")
parser.add_argument("-R", "--role", help="user access level", parser.add_argument("-R", "--role", help="user access level",
type=UserAccess, choices=tuple(UserAccess), default=UserAccess.Read) type=UserAccess, choices=tuple(UserAccess), default=UserAccess.READ)
parser.set_defaults(action=Action.Update, architecture="", exit_code=False, lock=None, quiet=True, parser.set_defaults(action=Action.UPDATE, architecture="", exit_code=False, lock=None, quiet=True,
report=False, repository="") report=False, repository="")
return parser return parser
@@ -110,7 +110,7 @@ class Users(Handler):
parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty", parser.add_argument("-e", "--exit-code", help="return non-zero exit status if result is empty",
action="store_true") action="store_true")
parser.add_argument("-R", "--role", help="filter users by role", type=UserAccess, choices=tuple(UserAccess)) parser.add_argument("-R", "--role", help="filter users by role", type=UserAccess, choices=tuple(UserAccess))
parser.set_defaults(action=Action.List, architecture="", lock=None, quiet=True, report=False, repository="", parser.set_defaults(action=Action.LIST, architecture="", lock=None, quiet=True, report=False, repository="",
unsafe=True) unsafe=True)
return parser return parser
@@ -128,7 +128,7 @@ class Users(Handler):
parser = root.add_parser("user-remove", help="remove user", parser = root.add_parser("user-remove", help="remove user",
description="remove user from the user mapping and update the configuration") description="remove user from the user mapping and update the configuration")
parser.add_argument("username", help="username for web service") parser.add_argument("username", help="username for web service")
parser.set_defaults(action=Action.Remove, architecture="", exit_code=False, lock=None, quiet=True, parser.set_defaults(action=Action.REMOVE, architecture="", exit_code=False, lock=None, quiet=True,
report=False, repository="") report=False, repository="")
return parser return parser
+2 -2
View File
@@ -209,7 +209,7 @@ class Lock(LazyLogging):
self.check_user() self.check_user()
self.check_version() self.check_version()
self.lock() self.lock()
self.reporter.status_update(BuildStatusEnum.Building) self.reporter.status_update(BuildStatusEnum.BUILDING)
return self return self
def __exit__(self, exc_type: type[Exception] | None, exc_val: Exception | None, def __exit__(self, exc_type: type[Exception] | None, exc_val: Exception | None,
@@ -226,6 +226,6 @@ class Lock(LazyLogging):
Literal[False]: always ``False`` (do not suppress any exception) Literal[False]: always ``False`` (do not suppress any exception)
""" """
self.clear() self.clear()
status = BuildStatusEnum.Success if exc_val is None else BuildStatusEnum.Failed status = BuildStatusEnum.SUCCESS if exc_val is None else BuildStatusEnum.FAILED
self.reporter.status_update(status) self.reporter.status_update(status)
return False return False
+1 -1
View File
@@ -88,7 +88,7 @@ class _Context:
iterate over keys in local storage iterate over keys in local storage
Returns: Returns:
str: context key iterator Iterator[str]: context key iterator
""" """
return iter(self._content) return iter(self._content)
+1 -1
View File
@@ -96,7 +96,7 @@ class Pacman(LazyLogging):
self.database_init(handle, self.repository_id.name, self.repository_id.architecture) self.database_init(handle, self.repository_id.name, self.repository_id.architecture)
if use_ahriman_cache and refresh_database: if use_ahriman_cache and refresh_database:
self.database_sync(handle, force=refresh_database == PacmanSynchronization.Force) self.database_sync(handle, force=refresh_database == PacmanSynchronization.FORCE)
return handle return handle
@@ -35,32 +35,32 @@ class PkgbuildNodeType(StrEnum):
tree-sitter node types used by parser tree-sitter node types used by parser
Attributes: Attributes:
Append(PkgbuildNodeType): append node APPEND(PkgbuildNodeType): append node
Array(PkgbuildNodeType): array node ARRAY(PkgbuildNodeType): array node
Comment(PkgbuildNodeType): comment node COMMENT(PkgbuildNodeType): comment node
Concatenation(PkgbuildNodeType): concatenation node CONCATENATION(PkgbuildNodeType): concatenation node
Error(PkgbuildNodeType): syntax error node ERROR(PkgbuildNodeType): syntax error node
FunctionDefinition(PkgbuildNodeType): function definition node FUNCTION_DEFINITION(PkgbuildNodeType): function definition node
Number(PkgbuildNodeType): numeric word node NUMBER(PkgbuildNodeType): numeric word node
RawString(PkgbuildNodeType): single-quoted string node RAW_STRING(PkgbuildNodeType): single-quoted string node
String(PkgbuildNodeType): double-quoted string node STRING(PkgbuildNodeType): double-quoted string node
StringContent(PkgbuildNodeType): string content node STRING_CONTENT(PkgbuildNodeType): string content node
VariableAssignment(PkgbuildNodeType): assignment node VARIABLE_ASSIGNMENT(PkgbuildNodeType): assignment node
Word(PkgbuildNodeType): word node WORD(PkgbuildNodeType): word node
""" """
Append = "+=" APPEND = "+="
Array = "array" ARRAY = "array"
Comment = "comment" COMMENT = "comment"
Concatenation = "concatenation" CONCATENATION = "concatenation"
Error = "ERROR" ERROR = "ERROR"
FunctionDefinition = "function_definition" FUNCTION_DEFINITION = "function_definition"
Number = "number" NUMBER = "number"
RawString = "raw_string" RAW_STRING = "raw_string"
String = "string" STRING = "string"
StringContent = "string_content" STRING_CONTENT = "string_content"
VariableAssignment = "variable_assignment" VARIABLE_ASSIGNMENT = "variable_assignment"
Word = "word" WORD = "word"
class PkgbuildNodeField(StrEnum): class PkgbuildNodeField(StrEnum):
@@ -68,14 +68,14 @@ class PkgbuildNodeField(StrEnum):
tree-sitter node fields used by parser tree-sitter node fields used by parser
Attributes: Attributes:
Body(PkgbuildNodeField): function body field BODY(PkgbuildNodeField): function body field
Name(PkgbuildNodeField): variable or function name field NAME(PkgbuildNodeField): variable or function name field
Value(PkgbuildNodeField): assignment value field VALUE(PkgbuildNodeField): assignment value field
""" """
Body = "body" BODY = "body"
Name = "name" NAME = "name"
Value = "value" VALUE = "value"
class PkgbuildParser(Iterable[PkgbuildPatch]): class PkgbuildParser(Iterable[PkgbuildPatch]):
@@ -169,17 +169,17 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
source = source.replace(original, replacement) source = source.replace(original, replacement)
return source return source
if node.type == PkgbuildNodeType.Concatenation: if node.type == PkgbuildNodeType.CONCATENATION:
return "".join(PkgbuildParser.value(child) for child in node.named_children) return "".join(PkgbuildParser.value(child) for child in node.named_children)
value = PkgbuildParser.text(node) value = PkgbuildParser.text(node)
match node.type: match node.type:
case PkgbuildNodeType.String | PkgbuildNodeType.StringContent: case PkgbuildNodeType.STRING | PkgbuildNodeType.STRING_CONTENT:
if node.type == PkgbuildNodeType.String: if node.type == PkgbuildNodeType.STRING:
value = PkgbuildParser.unquote(value) value = PkgbuildParser.unquote(value)
# protect escaped backslashes from being interpreted a second time. # protect escaped backslashes from being interpreted a second time.
return "\\".join(unescape(part) for part in value.split("\\\\")) return "\\".join(unescape(part) for part in value.split("\\\\"))
case PkgbuildNodeType.Number | PkgbuildNodeType.RawString | PkgbuildNodeType.Word: case PkgbuildNodeType.NUMBER | PkgbuildNodeType.RAW_STRING | PkgbuildNodeType.WORD:
return PkgbuildParser.unquote(value) return PkgbuildParser.unquote(value)
case _: case _:
return value return value
@@ -194,17 +194,17 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
Returns: Returns:
PkgbuildPatch: parsed assignment PkgbuildPatch: parsed assignment
""" """
key = self.text(cast(Node, node.child_by_field_name(PkgbuildNodeField.Name))) key = self.text(cast(Node, node.child_by_field_name(PkgbuildNodeField.NAME)))
value = node.child_by_field_name(PkgbuildNodeField.Value) value = node.child_by_field_name(PkgbuildNodeField.VALUE)
# bash permits assignments without a value (for example ``IFS=``). # bash permits assignments without a value (for example ``IFS=``).
# tree-sitter represents those assignments without a value node. # tree-sitter represents those assignments without a value node.
if value is None: if value is None:
return PkgbuildPatch(key, "") return PkgbuildPatch(key, "")
match value.type: match value.type:
case PkgbuildNodeType.Array: case PkgbuildNodeType.ARRAY:
values = [] values = []
for element in filter(lambda child: child.type != PkgbuildNodeType.Comment, value.named_children): for element in filter(lambda child: child.type != PkgbuildNodeType.COMMENT, value.named_children):
values.extend(self._expand_array(element)) values.extend(self._expand_array(element))
return PkgbuildPatch(key, values) return PkgbuildPatch(key, values)
@@ -221,7 +221,7 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
Returns: Returns:
list[str]: expanded element values list[str]: expanded element values
""" """
if node.type != PkgbuildNodeType.Concatenation: if node.type != PkgbuildNodeType.CONCATENATION:
return [self.value(node)] return [self.value(node)]
values = [""] values = [""]
@@ -229,9 +229,9 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
while children: while children:
match children[:3]: match children[:3]:
case [ case [
Node(type=PkgbuildNodeType.Word, text=b"{"), Node(type=PkgbuildNodeType.WORD, text=b"{"),
Node(type=PkgbuildNodeType.Word) as content, Node(type=PkgbuildNodeType.WORD) as content,
Node(type=PkgbuildNodeType.Word, text=b"}"), Node(type=PkgbuildNodeType.WORD, text=b"}"),
] if "," in (escaped := self.text(content).replace("\\,", ShellInterpolator.DATA_LINK_ESCAPE)): ] if "," in (escaped := self.text(content).replace("\\,", ShellInterpolator.DATA_LINK_ESCAPE)):
parts = [ parts = [
self.unquote(part).replace(ShellInterpolator.DATA_LINK_ESCAPE, ",") self.unquote(part).replace(ShellInterpolator.DATA_LINK_ESCAPE, ",")
@@ -258,7 +258,7 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
PkgbuildPatch: parsed entries PkgbuildPatch: parsed entries
""" """
match node.type: match node.type:
case PkgbuildNodeType.VariableAssignment if any(child.type == PkgbuildNodeType.Append for child in node.children): case PkgbuildNodeType.VARIABLE_ASSIGNMENT if any(child.type == PkgbuildNodeType.APPEND for child in node.children):
patch = self._assignment(node) patch = self._assignment(node)
match values.get(patch.key), patch.value: match values.get(patch.key), patch.value:
case PkgbuildPatch(value=str() as previous), str() as appended: case PkgbuildPatch(value=str() as previous), str() as appended:
@@ -270,25 +270,25 @@ class PkgbuildParser(Iterable[PkgbuildPatch]):
values[patch.key] = patch values[patch.key] = patch
yield patch yield patch
case PkgbuildNodeType.VariableAssignment: case PkgbuildNodeType.VARIABLE_ASSIGNMENT:
patch = self._assignment(node) patch = self._assignment(node)
values[patch.key] = patch values[patch.key] = patch
yield patch yield patch
case PkgbuildNodeType.FunctionDefinition: case PkgbuildNodeType.FUNCTION_DEFINITION:
name = cast(Node, node.child_by_field_name(PkgbuildNodeField.Name)) name = cast(Node, node.child_by_field_name(PkgbuildNodeField.NAME))
body = cast(Node, node.child_by_field_name(PkgbuildNodeField.Body)) body = cast(Node, node.child_by_field_name(PkgbuildNodeField.BODY))
yield PkgbuildPatch(f"{self.text(name)}()", self.text(body)) yield PkgbuildPatch(f"{self.text(name)}()", self.text(body))
case _: case _:
# descend into statements, but skip command arguments and values # descend into statements, but skip command arguments and values
for child in node.named_children: for child in node.named_children:
if child.type not in ( if child.type not in (
PkgbuildNodeType.Array, PkgbuildNodeType.ARRAY,
PkgbuildNodeType.Comment, PkgbuildNodeType.COMMENT,
PkgbuildNodeType.RawString, PkgbuildNodeType.RAW_STRING,
PkgbuildNodeType.String, PkgbuildNodeType.STRING,
PkgbuildNodeType.Word, PkgbuildNodeType.WORD,
): ):
yield from self._read(child, values) yield from self._read(child, values)
@@ -134,7 +134,7 @@ class Configuration(configparser.RawConfigParser):
repository identifier repository identifier
Returns: Returns:
RepositoryId: repository unique identifier RepositoryId | None: repository unique identifier
""" """
return self._repository_id return self._repository_id
@@ -58,7 +58,7 @@ class Migrations(LazyLogging):
configuration(Configuration): configuration instance configuration(Configuration): configuration instance
Returns: Returns:
MigrationResult: current schema version MigrationResult: schema versions before and after migration
""" """
return Migrations(connection, configuration).run() return Migrations(connection, configuration).run()
@@ -144,8 +144,8 @@ class Migrations(LazyLogging):
""" """
perform migrations perform migrations
Return: Returns:
MigrationResult: current schema version MigrationResult: schema versions before and after migration
""" """
migrations = self.migrations() migrations = self.migrations()
@@ -35,7 +35,7 @@ class BuildOperations(Operations):
Args: Args:
package_base(str | None): optional filter by package base package_base(str | None): optional filter by package base
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -57,9 +57,9 @@ class BuildOperations(Operations):
retrieve packages from build queue retrieve packages from build queue
Args: Args:
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Return: Returns:
list[Package]: list of packages to be built list[Package]: list of packages to be built
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -81,7 +81,7 @@ class BuildOperations(Operations):
Args: Args:
package(Package): package to be inserted package(Package): package to be inserted
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -35,7 +35,7 @@ class ChangesOperations(Operations):
Args: Args:
package_base(str): package base to search package_base(str): package base to search
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Returns: Returns:
Changes: changes for the package base if available Changes: changes for the package base if available
@@ -69,7 +69,7 @@ class ChangesOperations(Operations):
Args: Args:
package_base(str): package base to insert package_base(str): package base to insert
changes(Changes): package changes (as in patch format) changes(Changes): package changes (as in patch format)
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -101,7 +101,7 @@ class ChangesOperations(Operations):
Args: Args:
package_base(str | None): optional filter by package base package_base(str | None): optional filter by package base
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -36,10 +36,10 @@ class DependenciesOperations(Operations):
Args: Args:
package_base(str | None): package base to search package_base(str | None): package base to search
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Returns: Returns:
Dependencies: dependencies for the package base if available dict[str, Dependencies]: dependencies keyed by package base, optionally filtered by package base
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -69,7 +69,7 @@ class DependenciesOperations(Operations):
Args: Args:
package_base(str): package base package_base(str): package base
dependencies(Dependencies): package dependencies dependencies(Dependencies): package dependencies
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -97,7 +97,7 @@ class DependenciesOperations(Operations):
Args: Args:
package_base(str | None): optional filter by package base package_base(str | None): optional filter by package base
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -42,7 +42,7 @@ class EventOperations(Operations):
to_date(int | float | None, optional): maximal creation date, exclusive (Default value = None) to_date(int | float | None, optional): maximal creation date, exclusive (Default value = None)
limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1) limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1)
offset(int, optional): records offset (Default value = 0) offset(int, optional): records offset (Default value = 0)
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Returns: Returns:
list[Event]: list of audit log events list[Event]: list of audit log events
@@ -84,7 +84,7 @@ class EventOperations(Operations):
Args: Args:
event(Event): event to insert event(Event): event to insert
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -40,9 +40,9 @@ class LogsOperations(Operations):
process_id(str | None, optional): process identifier to filter (Default value = None) process_id(str | None, optional): process identifier to filter (Default value = None)
limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1) limit(int, optional): limit records to the specified count, -1 means unlimited (Default value = -1)
offset(int, optional): records offset (Default value = 0) offset(int, optional): records offset (Default value = 0)
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Return: Returns:
list[LogRecord]: sorted package log records list[LogRecord]: sorted package log records
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -79,7 +79,7 @@ class LogsOperations(Operations):
Args: Args:
log_record(LogRecord): log record object log_record(LogRecord): log record object
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -106,7 +106,7 @@ class LogsOperations(Operations):
Args: Args:
package_base(str): package base to remove logs package_base(str): package base to remove logs
version(str | None): package version. If set it will remove only logs belonging to another version version(str | None): package version. If set it will remove only logs belonging to another version
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -133,7 +133,7 @@ class LogsOperations(Operations):
Args: Args:
keep_last_records(int): number of last records to keep keep_last_records(int): number of last records to keep
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -66,7 +66,7 @@ class Operations(LazyLogging):
dictionary factory based on official documentation dictionary factory based on official documentation
Args: Args:
cursor(Cursor): cursor descriptor cursor(sqlite3.Cursor): cursor descriptor
row(tuple[Any, ...]): fetched row row(tuple[Any, ...]): fetched row
Returns: Returns:
@@ -82,7 +82,7 @@ class Operations(LazyLogging):
perform operation in connection perform operation in connection
Args: Args:
query(Callable[[Connection], T]): function to be called with connection query(Callable[[sqlite3.Connection], T]): function to be called with connection
commit(bool, optional): if ``True`` commit() will be called on success (Default value = False) commit(bool, optional): if ``True`` commit() will be called on success (Default value = False)
Returns: Returns:
@@ -225,7 +225,7 @@ class PackageOperations(Operations):
Args: Args:
package_base(str): package base name package_base(str): package base name
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
enabled(bool): new hold status enabled(bool): new hold status
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -248,7 +248,7 @@ class PackageOperations(Operations):
Args: Args:
package_base(str): package base name package_base(str): package base name
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -264,7 +264,7 @@ class PackageOperations(Operations):
Args: Args:
package(Package): package properties package(Package): package properties
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -280,9 +280,9 @@ class PackageOperations(Operations):
get package list and their build statuses from database get package list and their build statuses from database
Args: Args:
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Return: Returns:
list[tuple[Package, BuildStatus]]: list of package properties and their statuses list[tuple[Package, BuildStatus]]: list of package properties and their statuses
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -303,7 +303,7 @@ class PackageOperations(Operations):
Args: Args:
package_base(str): package base name package_base(str): package base name
status(BuildStatus): new build status status(BuildStatus): new build status
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
""" """
repository_id = repository_id or self._repository_id repository_id = repository_id or self._repository_id
@@ -116,7 +116,7 @@ class SQLite(
Args: Args:
package_base(str): package base to remove package_base(str): package base to remove
repository_id(RepositoryId, optional): repository unique identifier override (Default value = None) repository_id(RepositoryId | None, optional): repository unique identifier override (Default value = None)
Examples: Examples:
This method completely removes the package from all tables and must be used, e.g. on package removal:: This method completely removes the package from all tables and must be used, e.g. on package removal::
+1 -1
View File
@@ -254,7 +254,7 @@ class PasswordError(ValueError):
def __init__(self, details: Any) -> None: def __init__(self, details: Any) -> None:
""" """
Args: Args:
details(Any); error details details(Any): error details
""" """
ValueError.__init__(self, f"Password error: {details}") ValueError.__init__(self, f"Password error: {details}")
@@ -35,6 +35,7 @@ class RepositoryStatsPrinter(StringPrinter):
def __init__(self, repository_id: RepositoryId, statistics: RepositoryStats) -> None: def __init__(self, repository_id: RepositoryId, statistics: RepositoryStats) -> None:
""" """
Args: Args:
repository_id(RepositoryId): repository unique identifier
statistics(RepositoryStats): repository statistics statistics(RepositoryStats): repository statistics
""" """
StringPrinter.__init__(self, str(repository_id)) StringPrinter.__init__(self, str(repository_id))
@@ -90,6 +90,9 @@ class UpdatePrinter(StringPrinter):
""" """
generate version property generate version property
Args:
package(Package): package whose current and updated versions are shown
Returns: Returns:
tuple[str, str]: extract current and updated versions for the package tuple[str, str]: extract current and updated versions for the package
""" """
@@ -55,7 +55,7 @@ class RemotePull(LazyLogging):
web_url="", web_url="",
path=".", path=".",
branch=configuration.get(section, "pull_branch", fallback="master"), branch=configuration.get(section, "pull_branch", fallback="master"),
source=PackageSource.Local, source=PackageSource.LOCAL,
) )
self.architecture = repository_id.architecture self.architecture = repository_id.architecture
self.repository_paths = configuration.repository_paths self.repository_paths = configuration.repository_paths
@@ -62,7 +62,7 @@ class RemotePush(LazyLogging):
web_url="", web_url="",
path=".", path=".",
branch=configuration.get(section, "push_branch", fallback="master"), branch=configuration.get(section, "push_branch", fallback="master"),
source=PackageSource.Local, source=PackageSource.LOCAL,
) )
def package_update(self, package: Package, target_dir: Path) -> str: def package_update(self, package: Package, target_dir: Path) -> str:
@@ -81,7 +81,7 @@ class SyncHttpClient(LazyLogging):
get or create session get or create session
Returns: Returns:
request.Session: created session object requests.Session: created session object
""" """
session = requests.Session() session = requests.Session()
@@ -52,9 +52,9 @@ class LogLoader:
""" """
try to guess default log handler. In case if ``selected`` is set, it will return specified value with appended try to guess default log handler. In case if ``selected`` is set, it will return specified value with appended
_handler suffix. Otherwise, it will try to import journald handler and returns _handler suffix. Otherwise, it will try to import journald handler and returns
:attr:`ahriman.models.log_handler.LogHandler.Journald` if library is available. Otherwise, it will check if :attr:`ahriman.models.log_handler.LogHandler.JOURNALD` if library is available. Otherwise, it will check if
there is ``/dev/log`` device and returns :attr:`ahriman.models.log_handler.LogHandler.Syslog` in this there is ``/dev/log`` device and returns :attr:`ahriman.models.log_handler.LogHandler.SYSLOG` in this
case. And, finally, it will fall back to :attr:`ahriman.models.log_handler.LogHandler.Console` case. And, finally, it will fall back to :attr:`ahriman.models.log_handler.LogHandler.CONSOLE`
if none were found if none were found
Args: Args:
@@ -67,10 +67,10 @@ class LogLoader:
return selected return selected
if optional_module("systemd.journal"): if optional_module("systemd.journal"):
return LogHandler.Journald # journald import was found return LogHandler.JOURNALD # journald import was found
if LogLoader.DEFAULT_SYSLOG_DEVICE.exists(): if LogLoader.DEFAULT_SYSLOG_DEVICE.exists():
return LogHandler.Syslog return LogHandler.SYSLOG
return LogHandler.Console return LogHandler.CONSOLE
@staticmethod @staticmethod
def load(repository_id: RepositoryId, configuration: Configuration, handler: LogHandler, *, def load(repository_id: RepositoryId, configuration: Configuration, handler: LogHandler, *,
@@ -107,10 +107,10 @@ class JinjaTemplate:
sort content before rendering sort content before rendering
Args: Args:
content(list[dict[str, str]]): content of the template content(list[dict[str, Any]]): content of the template
Returns: Returns:
list[dict[str, str]]: sorted content according to comparator defined list[dict[str, Any]]: sorted content according to comparator defined
""" """
comparator: Callable[[dict[str, str]], Comparable] = lambda item: item["filename"] comparator: Callable[[dict[str, str]], Comparable] = lambda item: item["filename"]
return sorted(content, key=comparator) return sorted(content, key=comparator)
@@ -122,6 +122,9 @@ class JinjaTemplate:
Args: Args:
result(Result): build result result(Result): build result
template_name(Path | str): name of the template or path to it (legacy configuration) template_name(Path | str): name of the template or path to it (legacy configuration)
Returns:
str: rendered report
""" """
templates = self.templates[:] templates = self.templates[:]
if isinstance(template_name, Path): if isinstance(template_name, Path):
@@ -155,8 +158,8 @@ class JinjaTemplate:
homepage=self.homepage, homepage=self.homepage,
last_update=self.format_datetime(utcnow()), last_update=self.format_datetime(utcnow()),
link_path=self.link_path, link_path=self.link_path,
has_package_signed=SignSettings.Packages in self.sign_targets, has_package_signed=SignSettings.PACKAGES in self.sign_targets,
has_repo_signed=SignSettings.Repository in self.sign_targets, has_repo_signed=SignSettings.REPOSITORY in self.sign_targets,
packages=self.sort_content(content), packages=self.sort_content(content),
pgp_key=self.default_pgp_key, pgp_key=self.default_pgp_key,
repository=self.name, repository=self.name,
@@ -81,19 +81,19 @@ class Report(LazyLogging):
case ReportSettings.HTML: case ReportSettings.HTML:
from ahriman.core.report.html import HTML from ahriman.core.report.html import HTML
return HTML(repository_id, configuration, section) return HTML(repository_id, configuration, section)
case ReportSettings.Email: case ReportSettings.EMAIL:
from ahriman.core.report.email import Email from ahriman.core.report.email import Email
return Email(repository_id, configuration, section) return Email(repository_id, configuration, section)
case ReportSettings.Console: case ReportSettings.CONSOLE:
from ahriman.core.report.console import Console from ahriman.core.report.console import Console
return Console(repository_id, configuration, section) return Console(repository_id, configuration, section)
case ReportSettings.Telegram: case ReportSettings.TELEGRAM:
from ahriman.core.report.telegram import Telegram from ahriman.core.report.telegram import Telegram
return Telegram(repository_id, configuration, section) return Telegram(repository_id, configuration, section)
case ReportSettings.RSS: case ReportSettings.RSS:
from ahriman.core.report.rss import RSS from ahriman.core.report.rss import RSS
return RSS(repository_id, configuration, section) return RSS(repository_id, configuration, section)
case ReportSettings.RemoteCall: case ReportSettings.REMOTE_CALL:
from ahriman.core.report.remote_call import RemoteCall from ahriman.core.report.remote_call import RemoteCall
return RemoteCall(repository_id, configuration, section) return RemoteCall(repository_id, configuration, section)
case _: case _:
+3 -3
View File
@@ -82,10 +82,10 @@ class RSS(Report, JinjaTemplate):
sort content before rendering sort content before rendering
Args: Args:
content(list[dict[str, str]]): content of the template content(list[dict[str, Any]]): content of the template
Returns: Returns:
list[dict[str, str]]: sorted content according to comparator defined list[dict[str, Any]]: sorted content according to comparator defined
""" """
comparator: Callable[[dict[str, str]], Comparable] = \ comparator: Callable[[dict[str, str]], Comparable] = \
lambda item: parsedate_to_datetime(item["build_date"]) lambda item: parsedate_to_datetime(item["build_date"])
@@ -103,7 +103,7 @@ class RSS(Report, JinjaTemplate):
""" """
ctx = context.get() ctx = context.get()
reporter = ctx.get(Client) reporter = ctx.get(Client)
events = reporter.event_get(EventType.PackageUpdated, None, limit=self.max_entries) events = reporter.event_get(EventType.PACKAGE_UPDATED, None, limit=self.max_entries)
known_packages = {package.base: package for package in packages} known_packages = {package.base: package for package in packages}
@@ -49,7 +49,7 @@ class EventLogger:
This method must be used as simple wrapper for :class:`ahriman.core.status.Client` methods, e.g.:: This method must be used as simple wrapper for :class:`ahriman.core.status.Client` methods, e.g.::
>>> do_something() >>> do_something()
>>> self.event(package_base, EventType.PackageUpdated) >>> self.event(package_base, EventType.PACKAGE_UPDATED)
""" """
self.reporter.event_add(Event(event, package_base, message)) self.reporter.event_add(Event(event, package_base, message))
@@ -68,7 +68,7 @@ class EventLogger:
Examples: Examples:
This method must be used to perform action in context with time measurement:: This method must be used to perform action in context with time measurement::
>>> with self.in_event(package_base, EventType.PackageUpdated): >>> with self.in_event(package_base, EventType.PACKAGE_UPDATED):
>>> do_something() >>> do_something()
Additional parameter ``failure`` can be set in order to emit an event on exception occurred. If none set Additional parameter ``failure`` can be set in order to emit an event on exception occurred. If none set
@@ -117,7 +117,7 @@ class Executor(PackageInfo, Cleaner):
package_base(str): package base name package_base(str): package base name
""" """
try: try:
with self.in_event(package_base, EventType.PackageRemoved): with self.in_event(package_base, EventType.PACKAGE_REMOVED):
self.reporter.package_remove(package_base) self.reporter.package_remove(package_base)
except Exception: except Exception:
self.logger.exception("could not remove base %s", package_base) self.logger.exception("could not remove base %s", package_base)
@@ -169,7 +169,7 @@ class Executor(PackageInfo, Cleaner):
with self.in_package_context(single.base, local_versions.get(single.base)), \ with self.in_package_context(single.base, local_versions.get(single.base)), \
TemporaryDirectory(ignore_cleanup_errors=True) as dir_name: TemporaryDirectory(ignore_cleanup_errors=True) as dir_name:
try: try:
with self.in_event(single.base, EventType.PackageUpdated, failure=EventType.PackageUpdateFailed): with self.in_event(single.base, EventType.PACKAGE_UPDATED, failure=EventType.PACKAGE_UPDATE_FAILED):
packager = self.packager(packagers, single.base) packager = self.packager(packagers, single.base)
local_version = local_versions.get(single.base) if bump_pkgrel else None local_version = local_versions.get(single.base) if bump_pkgrel else None
commit_sha = self._package_build(single, Path(dir_name), packager.packager_id, local_version) commit_sha = self._package_build(single, Path(dir_name), packager.packager_id, local_version)
@@ -57,7 +57,7 @@ class Repository(Executor, UpdateHandler):
@classmethod @classmethod
def load(cls, repository_id: RepositoryId, configuration: Configuration, database: SQLite, *, report: bool, def load(cls, repository_id: RepositoryId, configuration: Configuration, database: SQLite, *, report: bool,
refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.Disabled) -> Self: refresh_pacman_database: PacmanSynchronization = PacmanSynchronization.DISABLED) -> Self:
""" """
load instance from argument list load instance from argument list
@@ -67,7 +67,7 @@ class Repository(Executor, UpdateHandler):
database(SQLite): database instance database(SQLite): database instance
report(bool): force enable or disable reporting report(bool): force enable or disable reporting
refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level refresh_pacman_database(PacmanSynchronization, optional): pacman database synchronization level
(Default value = PacmanSynchronization.Disabled) (Default value = PacmanSynchronization.DISABLED)
Returns: Returns:
Self: fully loaded repository class instance Self: fully loaded repository class instance
@@ -86,13 +86,13 @@ class RepositoryProperties(EventLogger, LazyLogging):
package_base(str): package base to lookup package_base(str): package base to lookup
Returns: Returns:
User | None: user found in database if any and empty object otherwise User: user found in database if any and empty user object otherwise
""" """
username = packagers.for_base(package_base) username = packagers.for_base(package_base)
if username is None: # none to search if username is None: # none to search
return User(username="", password="", access=UserAccess.Read, packager_id=None, key=None) # nosec return User(username="", password="", access=UserAccess.READ, packager_id=None, key=None) # nosec
if (user := self.database.user_get(username)) is not None: # found user if (user := self.database.user_get(username)) is not None: # found user
return user return user
# empty user with the username # empty user with the username
return User(username=username, password="", access=UserAccess.Read, packager_id=None, key=None) # nosec return User(username=username, password="", access=UserAccess.READ, packager_id=None, key=None) # nosec
@@ -62,7 +62,7 @@ class UpdateHandler(PackageInfo, Cleaner):
# try to load package from base and if none found try to load by separated packages # try to load package from base and if none found try to load by separated packages
for probe in [package.base] + sorted(package.packages.keys()): for probe in [package.base] + sorted(package.packages.keys()):
try: try:
if package.remote.source == PackageSource.Repository: if package.remote.source == PackageSource.REPOSITORY:
return Package.from_official(probe, self.pacman, None) return Package.from_official(probe, self.pacman, None)
return Package.from_aur(probe, None) return Package.from_aur(probe, None)
except UnknownPackageError: except UnknownPackageError:
@@ -85,10 +85,10 @@ class UpdateHandler(PackageInfo, Cleaner):
if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs): if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs):
self.reporter.set_pending(local.base) self.reporter.set_pending(local.base)
self.event(local.base, EventType.PackageOutdated, "Remote version is newer than local") self.event(local.base, EventType.PACKAGE_OUTDATED, "Remote version is newer than local")
result.append(remote) result.append(remote)
else: else:
self.reporter.package_status_update(local.base, BuildStatusEnum.Success) self.reporter.package_status_update(local.base, BuildStatusEnum.SUCCESS)
except Exception: except Exception:
self.reporter.set_failed(local.base) self.reporter.set_failed(local.base)
self.logger.exception("could not load remote package %s", local.base) self.logger.exception("could not load remote package %s", local.base)
@@ -136,7 +136,7 @@ class UpdateHandler(PackageInfo, Cleaner):
# there are no packages found in filesystem with the same paths # there are no packages found in filesystem with the same paths
self.reporter.set_pending(local.base) self.reporter.set_pending(local.base)
self.event(local.base, EventType.PackageOutdated, "Implicit dependencies are broken") self.event(local.base, EventType.PACKAGE_OUTDATED, "Implicit dependencies are broken")
result.append(local) result.append(local)
break break
@@ -165,7 +165,7 @@ class UpdateHandler(PackageInfo, Cleaner):
with self.in_package_context(cache_dir.name, local_versions.get(cache_dir.name)): with self.in_package_context(cache_dir.name, local_versions.get(cache_dir.name)):
try: try:
source = RemoteSource( source = RemoteSource(
source=PackageSource.Local, source=PackageSource.LOCAL,
git_url=cache_dir.absolute().as_uri(), git_url=cache_dir.absolute().as_uri(),
web_url="", web_url="",
path=".", path=".",
@@ -186,7 +186,7 @@ class UpdateHandler(PackageInfo, Cleaner):
if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs): if PackageVersion(local).is_outdated(remote, self.configuration, calculate_version=vcs):
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.PACKAGE_OUTDATED, "Locally pulled sources are outdated")
result.append(remote) result.append(remote)
except Exception: except Exception:
@@ -211,7 +211,7 @@ class UpdateHandler(PackageInfo, Cleaner):
self.reporter.set_unknown(local) self.reporter.set_unknown(local)
else: else:
self.reporter.set_pending(local.base) self.reporter.set_pending(local.base)
self.event(local.base, EventType.PackageOutdated, "Manual update is requested") self.event(local.base, EventType.PACKAGE_OUTDATED, "Manual update is requested")
except Exception: except Exception:
self.logger.exception("could not load packages from database") self.logger.exception("could not load packages from database")
+5 -5
View File
@@ -53,7 +53,7 @@ class GPG(SyncHttpClient):
Returns: Returns:
list[str]: command line arguments for repo-add command to sign database list[str]: command line arguments for repo-add command to sign database
""" """
if SignSettings.Repository not in self.targets: if SignSettings.REPOSITORY not in self.targets:
return [] return []
if self.default_key is None: if self.default_key is None:
self.logger.error("no default key set, skip repository sign") self.logger.error("no default key set, skip repository sign")
@@ -88,7 +88,7 @@ class GPG(SyncHttpClient):
targets: set[SignSettings] = set() targets: set[SignSettings] = set()
for option in configuration.getlist("sign", "target", fallback=[]): for option in configuration.getlist("sign", "target", fallback=[]):
target = SignSettings.from_option(option) target = SignSettings.from_option(option)
if target == SignSettings.Disabled: if target == SignSettings.DISABLED:
continue continue
targets.add(target) targets.add(target)
default_key = configuration.get("sign", "key") if targets else None default_key = configuration.get("sign", "key") if targets else None
@@ -103,7 +103,7 @@ class GPG(SyncHttpClient):
filepath(Path): path to the file which will be signed filepath(Path): path to the file which will be signed
Returns: Returns:
str: path to signature file Path: path to signature file
""" """
return filepath.parent / f"{filepath.name}.sig" return filepath.parent / f"{filepath.name}.sig"
@@ -204,7 +204,7 @@ class GPG(SyncHttpClient):
# the file was already signed before, just use its signature # the file was already signed before, just use its signature
return [path, signature] return [path, signature]
if SignSettings.Packages not in self.targets: if SignSettings.PACKAGES not in self.targets:
return [path] return [path]
key = packager_key or self.default_key key = packager_key or self.default_key
@@ -226,7 +226,7 @@ class GPG(SyncHttpClient):
Returns: Returns:
list[Path]: list of generated files including original file list[Path]: list of generated files including original file
""" """
if SignSettings.Repository not in self.targets: if SignSettings.REPOSITORY not in self.targets:
return [path] return [path]
if self.default_key is None: if self.default_key is None:
self.logger.error("no default key set, skip repository sign") self.logger.error("no default key set, skip repository sign")
@@ -164,7 +164,7 @@ class Client:
package_base(str): package base to retrieve package_base(str): package base to retrieve
Returns: Returns:
list[Dependencies]: package implicit dependencies if available Dependencies: package implicit dependencies if available
Raises: Raises:
NotImplementedError: not implemented method NotImplementedError: not implemented method
@@ -341,7 +341,7 @@ class Client:
Args: Args:
package_base(str): package base to update package_base(str): package base to update
""" """
self.package_status_update(package_base, BuildStatusEnum.Building) self.package_status_update(package_base, BuildStatusEnum.BUILDING)
def set_failed(self, package_base: str) -> None: def set_failed(self, package_base: str) -> None:
""" """
@@ -350,7 +350,7 @@ class Client:
Args: Args:
package_base(str): package base to update package_base(str): package base to update
""" """
self.package_status_update(package_base, BuildStatusEnum.Failed) self.package_status_update(package_base, BuildStatusEnum.FAILED)
def set_pending(self, package_base: str) -> None: def set_pending(self, package_base: str) -> None:
""" """
@@ -359,7 +359,7 @@ class Client:
Args: Args:
package_base(str): package base to update package_base(str): package base to update
""" """
self.package_status_update(package_base, BuildStatusEnum.Pending) self.package_status_update(package_base, BuildStatusEnum.PENDING)
def set_success(self, package: Package) -> None: def set_success(self, package: Package) -> None:
""" """
@@ -368,7 +368,7 @@ class Client:
Args: Args:
package(Package): current package properties package(Package): current package properties
""" """
self.package_update(package, BuildStatusEnum.Success) self.package_update(package, BuildStatusEnum.SUCCESS)
def set_unknown(self, package: Package) -> None: def set_unknown(self, package: Package) -> None:
""" """
@@ -380,7 +380,7 @@ class Client:
""" """
if self.package_get(package.base): if self.package_get(package.base):
return # skip update in case if package is already known return # skip update in case if package is already known
self.package_update(package, BuildStatusEnum.Unknown) self.package_update(package, BuildStatusEnum.UNKNOWN)
def statistics(self) -> RepositoryStats: def statistics(self) -> RepositoryStats:
""" """
@@ -114,7 +114,7 @@ class LocalClient(Client):
package_base(str): package base to retrieve package_base(str): package base to retrieve
Returns: Returns:
list[Dependencies]: package implicit dependencies if available Dependencies: package implicit dependencies if available
""" """
return self.database.dependencies_get(package_base, self.repository_id).get(package_base, Dependencies()) return self.database.dependencies_get(package_base, self.repository_id).get(package_base, Dependencies())
@@ -151,7 +151,7 @@ class Watcher(LazyLogging):
package_base(str): package base to retrieve package_base(str): package base to retrieve
Returns: Returns:
list[Dependencies]: package implicit dependencies if available Dependencies: package implicit dependencies if available
""" """
return self.client.package_dependencies_get(package_base) return self.client.package_dependencies_get(package_base)
@@ -197,7 +197,7 @@ class Watcher(LazyLogging):
self._known[package_base] = (package, replace(status, is_held=enabled)) self._known[package_base] = (package, replace(status, is_held=enabled))
self.client.package_hold_update(package_base, enabled=enabled) self.client.package_hold_update(package_base, enabled=enabled)
await self.event_bus.broadcast(EventType.PackageHeld, package_base, is_held=enabled) await self.event_bus.broadcast(EventType.PACKAGE_HELD, package_base, is_held=enabled)
async def package_logs_add(self, log_record: LogRecord) -> None: async def package_logs_add(self, log_record: LogRecord) -> None:
""" """
@@ -208,7 +208,7 @@ class Watcher(LazyLogging):
""" """
self.client.package_logs_add(log_record) self.client.package_logs_add(log_record)
await self.event_bus.broadcast(EventType.BuildLog, log_record.log_record_id.package_base, **log_record.view()) await self.event_bus.broadcast(EventType.BUILD_LOG, log_record.log_record_id.package_base, **log_record.view())
async def package_logs_get(self, package_base: str, version: str | None = None, process_id: str | None = None, async def package_logs_get(self, package_base: str, version: str | None = None, process_id: str | None = None,
limit: int = -1, offset: int = 0) -> list[LogRecord]: limit: int = -1, offset: int = 0) -> list[LogRecord]:
@@ -281,7 +281,7 @@ class Watcher(LazyLogging):
self._known.pop(package_base, None) self._known.pop(package_base, None)
self.client.package_remove(package_base) self.client.package_remove(package_base)
await self.event_bus.broadcast(EventType.PackageRemoved, package_base) await self.event_bus.broadcast(EventType.PACKAGE_REMOVED, package_base)
async def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None: async def package_status_update(self, package_base: str, status: BuildStatusEnum) -> None:
""" """
@@ -296,7 +296,7 @@ class Watcher(LazyLogging):
self._known[package_base] = (package, BuildStatus(status, is_held=current_status.is_held)) self._known[package_base] = (package, BuildStatus(status, is_held=current_status.is_held))
self.client.package_status_update(package_base, status) self.client.package_status_update(package_base, status)
await self.event_bus.broadcast(EventType.PackageStatusChanged, package_base, status=status.value) await self.event_bus.broadcast(EventType.PACKAGE_STATUS_CHANGED, package_base, status=status.value)
async def package_update(self, package: Package, status: BuildStatusEnum) -> None: async def package_update(self, package: Package, status: BuildStatusEnum) -> None:
""" """
@@ -312,7 +312,7 @@ class Watcher(LazyLogging):
self.client.package_update(package, status) self.client.package_update(package, status)
await self.event_bus.broadcast( await self.event_bus.broadcast(
EventType.PackageUpdated, package.base, status=status.value, version=package.version, EventType.PACKAGE_UPDATED, package.base, status=status.value, version=package.version,
) )
async def packages(self) -> list[tuple[Package, BuildStatus]]: async def packages(self) -> list[tuple[Package, BuildStatus]]:
@@ -340,7 +340,7 @@ class Watcher(LazyLogging):
""" """
self.status = BuildStatus(status) self.status = BuildStatus(status)
await self.event_bus.broadcast(EventType.ServiceStatusChanged, None, status=status.value) await self.event_bus.broadcast(EventType.SERVICE_STATUS_CHANGED, None, status=status.value)
def __call__(self, package_base: str | None) -> Self: def __call__(self, package_base: str | None) -> Self:
""" """
@@ -269,7 +269,7 @@ class WebClient(Client, SyncAhrimanClient):
package_base(str): package base to retrieve package_base(str): package base to retrieve
Returns: Returns:
list[Dependencies]: package implicit dependencies if available Dependencies: package implicit dependencies if available
""" """
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
response = self.make_request("GET", self._dependencies_url(package_base), response = self.make_request("GET", self._dependencies_url(package_base),
@@ -57,7 +57,7 @@ class RemoteService(Upload, HttpUpload):
get or create session get or create session
Returns: Returns:
request.Session: created session object requests.Session: created session object
""" """
return self.client.session return self.client.session
@@ -79,16 +79,16 @@ class Upload(LazyLogging):
""" """
section, provider_name = configuration.gettype(target, repository_id) section, provider_name = configuration.gettype(target, repository_id)
match UploadSettings.from_option(provider_name): match UploadSettings.from_option(provider_name):
case UploadSettings.Rsync: case UploadSettings.RSYNC:
from ahriman.core.upload.rsync import Rsync from ahriman.core.upload.rsync import Rsync
return Rsync(repository_id, configuration, section) return Rsync(repository_id, configuration, section)
case UploadSettings.S3: case UploadSettings.S3:
from ahriman.core.upload.s3 import S3 from ahriman.core.upload.s3 import S3
return S3(repository_id, configuration, section) return S3(repository_id, configuration, section)
case UploadSettings.GitHub: case UploadSettings.GITHUB:
from ahriman.core.upload.github import GitHub from ahriman.core.upload.github import GitHub
return GitHub(repository_id, configuration, section) return GitHub(repository_id, configuration, section)
case UploadSettings.RemoteService: case UploadSettings.REMOTE_SERVICE:
from ahriman.core.upload.remote_service import RemoteService from ahriman.core.upload.remote_service import RemoteService
return RemoteService(repository_id, configuration, section) return RemoteService(repository_id, configuration, section)
case _: case _:
+2 -2
View File
@@ -101,8 +101,8 @@ def check_output(*args: str, exception: Exception | Callable[[int, list[str], st
Args: Args:
*args(str): command line arguments *args(str): command line arguments
exception(Exception | Callable[[int, list[str], str, str]] | None, optional): exception which has to be raised exception(Exception | Callable[[int, list[str], str, str], Exception] | None, optional): exception to raise
instead of default subprocess exception. If callable us is supplied, the instead of the default subprocess exception. If a callable is supplied, the
:exc:`subprocess.CalledProcessError` arguments will be passed (Default value = None) :exc:`subprocess.CalledProcessError` arguments will be passed (Default value = None)
cwd(Path | None, optional): current working directory (Default value = None) cwd(Path | None, optional): current working directory (Default value = None)
input_data(str | None, optional): data which will be written to command stdin (Default value = None) input_data(str | None, optional): data which will be written to command stdin (Default value = None)
+6 -6
View File
@@ -25,11 +25,11 @@ class Action(StrEnum):
base action enumeration base action enumeration
Attributes: Attributes:
List(Action): list available values LIST(Action): list available values
Remove(Action): remove everything from local storage REMOVE(Action): remove everything from local storage
Update(Action): update local storage or add to UPDATE(Action): update local storage or add to
""" """
List = "list" LIST = "list"
Remove = "remove" REMOVE = "remove"
Update = "update" UPDATE = "update"
@@ -69,11 +69,13 @@ class AURPackage:
>>> >>>
>>> from ahriman.core.alpm.pacman import Pacman >>> from ahriman.core.alpm.pacman import Pacman
>>> from ahriman.core.configuration import Configuration >>> from ahriman.core.configuration import Configuration
>>> from ahriman.models.pacman_synchronization import PacmanSynchronization
>>> from ahriman.models.repository_id import RepositoryId >>> from ahriman.models.repository_id import RepositoryId
>>> >>>
>>> configuration = Configuration() >>> configuration = Configuration()
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration) >>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration,
>>> metadata = pacman.package_get("pacman") >>> refresh_database=PacmanSynchronization.DISABLED)
>>> metadata = pacman.package("pacman")
>>> package = AURPackage.from_pacman(next(metadata)) # load package from pyalpm wrapper >>> package = AURPackage.from_pacman(next(metadata)) # load package from pyalpm wrapper
""" """
@@ -27,15 +27,15 @@ class AuthSettings(StrEnum):
web authorization type web authorization type
Attributes: Attributes:
Disabled(AuthSettings): authorization is disabled DISABLED(AuthSettings): authorization is disabled
Configuration(AuthSettings): configuration based authorization CONFIGURATION(AuthSettings): configuration based authorization
OAuth(AuthSettings): OAuth based provider OAUTH(AuthSettings): OAuth based provider
PAM(AuthSettings): PAM based provider PAM(AuthSettings): PAM based provider
""" """
Disabled = "disabled" DISABLED = "disabled"
Configuration = "configuration" CONFIGURATION = "configuration"
OAuth = "oauth2" OAUTH = "oauth2"
PAM = "pam" PAM = "pam"
@property @property
@@ -46,7 +46,7 @@ class AuthSettings(StrEnum):
Returns: Returns:
bool: ``False`` in case if authorization is disabled and ``True`` otherwise bool: ``False`` in case if authorization is disabled and ``True`` otherwise
""" """
return self != AuthSettings.Disabled return self != AuthSettings.DISABLED
@staticmethod @staticmethod
def from_option(value: str) -> AuthSettings: def from_option(value: str) -> AuthSettings:
@@ -61,10 +61,10 @@ class AuthSettings(StrEnum):
""" """
match value.lower(): match value.lower():
case "configuration" | "mapping": case "configuration" | "mapping":
return AuthSettings.Configuration return AuthSettings.CONFIGURATION
case "oauth" | "oauth2": case "oauth" | "oauth2":
return AuthSettings.OAuth return AuthSettings.OAUTH
case "pam": case "pam":
return AuthSettings.PAM return AuthSettings.PAM
case _: case _:
return AuthSettings.Disabled return AuthSettings.DISABLED
+33 -20
View File
@@ -30,22 +30,22 @@ class BuildPlanReason(StrEnum):
reason why package was selected for a build plan reason why package was selected for a build plan
Attributes: Attributes:
BrokenImplicitDependency(BuildPlanReason): package has a broken implicit dependency BROKEN_IMPLICIT_DEPENDENCY(BuildPlanReason): package has a broken implicit dependency
LocalSourceUpdate(BuildPlanReason): locally sourced package has an update LOCAL_SOURCE_UPDATE(BuildPlanReason): locally sourced package has an update
PreBuilt(BuildPlanReason): package has already been built MANUAL_REQUEST(BuildPlanReason): package was manually queued
QueuedRequest(BuildPlanReason): package was manually queued PRE_BUILT(BuildPlanReason): package has already been built
Rebuild(BuildPlanReason): package was selected for rebuild REBUILD(BuildPlanReason): package was selected for rebuild
RegularUpdate(BuildPlanReason): package has an AUR update REGULAR_UPDATE(BuildPlanReason): package has an AUR update
RequiredBy(BuildPlanReason): package is required by another selected package REQUIRED_BY(BuildPlanReason): package is required by another selected package
""" """
BrokenImplicitDependency = "broken implicit dependency" BROKEN_IMPLICIT_DEPENDENCY = "broken implicit dependency"
LocalSourceUpdate = "local source update" LOCAL_SOURCE_UPDATE = "local source update"
PreBuilt = "pre-built" MANUAL_REQUEST = "manual request"
QueuedRequest = "queued request" PRE_BUILT = "pre-built"
Rebuild = "rebuild" REBUILD = "rebuild"
RegularUpdate = "regular update" REGULAR_UPDATE = "regular update"
RequiredBy = "required by" REQUIRED_BY = "required by"
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -95,18 +95,21 @@ class BuildPlan(Iterable[Package]):
""" """
return [item.package for item in self.items] return [item.package for item in self.items]
def add(self, package: Package, reason: BuildPlanReason, requester: str | None = None) -> BuildPlanItem: def add(self, package: Package, reason: BuildPlanReason = BuildPlanReason.MANUAL_REQUEST,
requester: str | None = None) -> BuildPlanItem:
""" """
add or update a package in the plan add or update a package while preserving its first reason and requester
Args: Args:
package(Package): package selected for the plan package(Package): package selected for the plan
reason(BuildPlanReason): reason for selecting it reason(BuildPlanReason, optional): reason for selecting it (Default value = BuildPlanReason.MANUAL_REQUEST)
requester(str | None, optional): package requiring this dependency (Default value = None) requester(str | None, optional): package requiring this dependency (Default value = None)
Returns: Returns:
BuildPlanItem: plan item for the package BuildPlanItem: plan item for the package
""" """
if (existing := self._items.get(package.base)) is not None:
reason, requester = existing.reason, existing.requester
item = self._items[package.base] = BuildPlanItem(package, reason, requester) item = self._items[package.base] = BuildPlanItem(package, reason, requester)
return item return item
@@ -122,13 +125,23 @@ class BuildPlan(Iterable[Package]):
""" """
return self._items[package_base] return self._items[package_base]
def update(self, packages: Iterable[Package], reason: BuildPlanReason, requester: str | None = None) -> Self: def remove(self, package_base: str) -> None:
"""
remove a package from the plan
Args:
package_base(str): package base to remove
"""
del self._items[package_base]
def update(self, packages: Iterable[Package], reason: BuildPlanReason = BuildPlanReason.MANUAL_REQUEST,
requester: str | None = None) -> Self:
""" """
bulk update packages with the same reason bulk update packages with the same reason
Args: Args:
packages(Iterable[Package]): list of new packages to be added packages(Iterable[Package]): list of new packages to be added
reason(BuildPlanReason): reason for selecting them reason(BuildPlanReason, optional): reason for selecting it (Default value = BuildPlanReason.MANUAL_REQUEST)
requester(str | None, optional): package requiring these dependencies (Default value = None) requester(str | None, optional): package requiring these dependencies (Default value = None)
Returns: Returns:
@@ -169,7 +182,7 @@ class BuildPlan(Iterable[Package]):
iterate over selected packages in stable package-base order iterate over selected packages in stable package-base order
Returns: Returns:
Package: selected package Iterator[Package]: iterator over selected packages
""" """
return iter(self.packages) return iter(self.packages)
+11 -11
View File
@@ -29,18 +29,18 @@ class BuildStatusEnum(StrEnum):
build status enumeration build status enumeration
Attributes: Attributes:
Unknown(BuildStatusEnum): build status is unknown UNKNOWN(BuildStatusEnum): build status is unknown
Pending(BuildStatusEnum): package is out-of-dated and will be built soon PENDING(BuildStatusEnum): package is out-of-dated and will be built soon
Building(BuildStatusEnum): package is building right now BUILDING(BuildStatusEnum): package is building right now
Failed(BuildStatusEnum): package build failed FAILED(BuildStatusEnum): package build failed
Success(BuildStatusEnum): package has been built without errors SUCCESS(BuildStatusEnum): package has been built without errors
""" """
Unknown = "unknown" UNKNOWN = "unknown"
Pending = "pending" PENDING = "pending"
Building = "building" BUILDING = "building"
Failed = "failed" FAILED = "failed"
Success = "success" SUCCESS = "success"
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -54,7 +54,7 @@ class BuildStatus:
is_held(bool | None): whether package held or not is_held(bool | None): whether package held or not
""" """
status: BuildStatusEnum = BuildStatusEnum.Unknown status: BuildStatusEnum = BuildStatusEnum.UNKNOWN
timestamp: int = field(default_factory=lambda: int(utcnow().timestamp())) timestamp: int = field(default_factory=lambda: int(utcnow().timestamp()))
is_held: bool | None = field(default=None, kw_only=True) is_held: bool | None = field(default=None, kw_only=True)
+17 -17
View File
@@ -28,24 +28,24 @@ class EventType(StrEnum):
predefined event types predefined event types
Attributes: Attributes:
BuildLog(EventType): new build log line BUILD_LOG(EventType): new build log line
PackageHeld(EventType): package hold status has been changed PACKAGE_HELD(EventType): package hold status has been changed
PackageOutdated(EventType): package has been marked as out-of-date PACKAGE_OUTDATED(EventType): package has been marked as out-of-date
PackageRemoved(EventType): package has been removed PACKAGE_REMOVED(EventType): package has been removed
PackageStatusChanged(EventType): package build status has been changed PACKAGE_STATUS_CHANGED(EventType): package build status has been changed
PackageUpdateFailed(EventType): package update has been failed PACKAGE_UPDATE_FAILED(EventType): package update has been failed
PackageUpdated(EventType): package has been updated PACKAGE_UPDATED(EventType): package has been updated
ServiceStatusChanged(EventType): service status has been changed SERVICE_STATUS_CHANGED(EventType): service status has been changed
""" """
BuildLog = "build-log" BUILD_LOG = "build-log"
PackageHeld = "package-held" PACKAGE_HELD = "package-held"
PackageOutdated = "package-outdated" PACKAGE_OUTDATED = "package-outdated"
PackageRemoved = "package-removed" PACKAGE_REMOVED = "package-removed"
PackageStatusChanged = "package-status-changed" PACKAGE_STATUS_CHANGED = "package-status-changed"
PackageUpdateFailed = "package-update-failed" PACKAGE_UPDATE_FAILED = "package-update-failed"
PackageUpdated = "package-updated" PACKAGE_UPDATED = "package-updated"
ServiceStatusChanged = "service-status-changed" SERVICE_STATUS_CHANGED = "service-status-changed"
class Event: class Event:
@@ -61,7 +61,7 @@ class Event:
""" """
def __init__(self, event: str | EventType, object_id: str, message: str | None = None, created: int | None = None, def __init__(self, event: str | EventType, object_id: str, message: str | None = None, created: int | None = None,
**kwargs: Any): **kwargs: Any) -> None:
""" """
Args: Args:
event(str | EventType): event type event(str | EventType): event type
@@ -34,7 +34,7 @@ class FilesystemPackage:
Attributes: Attributes:
package_name(str): package name package_name(str): package name
depends(set[str]): list of package dependencies depends(set[str]): list of package dependencies
directories(set[Path]): list of directories this package contains directories(list[Path]): list of directories this package contains
files(list[Path]): list of files this package contains files(list[Path]): list of files this package contains
opt_depends(set[str]): list of package optional dependencies opt_depends(set[str]): list of package optional dependencies
""" """
@@ -80,7 +80,8 @@ class FilesystemPackage:
include_optional(bool): include optional dependencies to check include_optional(bool): include optional dependencies to check
Returns: Returns:
bool: whether this package depends on any other package in the list of packages bool: ``True`` if this package has no dependencies among the supplied packages, ignoring packages
that have a required dependency on this package
""" """
return not any( return not any(
package package
@@ -25,11 +25,11 @@ class LogHandler(StrEnum):
log handler as described by default configuration log handler as described by default configuration
Attributes: Attributes:
Console(LogHandler): write logs to console CONSOLE(LogHandler): write logs to console
Syslog(LogHandler): write logs to syslog device /dev/null SYSLOG(LogHandler): write logs to syslog device /dev/null
Journald(LogHandler): write logs to journald directly JOURNALD(LogHandler): write logs to journald directly
""" """
Console = "console" CONSOLE = "console"
Syslog = "syslog" SYSLOG = "syslog"
Journald = "journald" JOURNALD = "journald"
@@ -50,13 +50,8 @@ class LogRecord:
Returns: Returns:
Self: log record object Self: log record object
""" """
if "process_id" in dump:
log_record_id = LogRecordId(package_base, dump["version"], dump["process_id"])
else:
log_record_id = LogRecordId(package_base, dump["version"])
return cls( return cls(
log_record_id=log_record_id, log_record_id=LogRecordId(package_base, dump["version"], dump.get("process_id", "")),
created=dump["created"], created=dump["created"],
message=dump["message"], message=dump["message"],
) )
@@ -38,9 +38,9 @@ class MetricsTimer:
>>> with MetricsTimer() as timer: >>> with MetricsTimer() as timer:
>>> do_something() >>> do_something()
>>> print("Time elapsed for first function: %f", timer.elapsed) >>> print(f"Time elapsed for first function: {timer.elapsed:f}")
>>> do_something_different() >>> do_something_different()
>>> print("Time elapsed for all functions: %f", timer.elapsed) >>> print(f"Time elapsed for all functions: {timer.elapsed:f}")
""" """
def __init__(self) -> None: def __init__(self) -> None:
+9 -9
View File
@@ -44,8 +44,8 @@ class Package(LazyLogging):
Attributes: Attributes:
base(str): package base name base(str): package base name
packager(str | None): package packager if available packager(str | None): package packager if available
packages(dict[str, PackageDescription): map of package names to their properties. packages(dict[str, PackageDescription]): map of package names to their properties.
Filled only on load from archive Available properties depend on the source used to load the package
remote(RemoteSource): package remote source if applicable remote(RemoteSource): package remote source if applicable
version(str): package full version version(str): package full version
@@ -56,16 +56,16 @@ class Package(LazyLogging):
it will contain every data available in the JSON body. Otherwise, if generate package from local archive:: it will contain every data available in the JSON body. Otherwise, if generate package from local archive::
>>> package = Package.from_archive(local_path, pacman) >>> package = Package.from_archive(local_path)
it will probably miss file descriptions (in case if there are multiple packages which belong to the base). it will probably miss file descriptions (in case if there are multiple packages which belong to the base).
The specific class load method must be defined based on the source provided. The following methods (mostly) must The specific class load method must be defined based on the source provided. The following methods (mostly) must
be used: :func:`from_archive()`, :func:`from_aur()`, :func:`from_build()`, :func:`from_official()` for sources be used: :func:`from_archive()`, :func:`from_aur()`, :func:`from_build()`, :func:`from_official()` for sources
:attr:`ahriman.models.package_source.PackageSource.Archive`, :attr:`ahriman.models.package_source.PackageSource.ARCHIVE`,
:attr:`ahriman.models.package_source.PackageSource.AUR`, :attr:`ahriman.models.package_source.PackageSource.AUR`,
:attr:`ahriman.models.package_source.PackageSource.Local` and :attr:`ahriman.models.package_source.PackageSource.LOCAL` and
:attr:`ahriman.models.package_source.PackageSource.Repository` respectively: :attr:`ahriman.models.package_source.PackageSource.REPOSITORY` respectively:
>>> ahriman_package = Package.from_aur("ahriman") >>> ahriman_package = Package.from_aur("ahriman")
>>> pacman_package = Package.from_official("pacman", pacman) >>> pacman_package = Package.from_official("pacman", pacman)
@@ -192,7 +192,7 @@ class Package(LazyLogging):
return cls( return cls(
base=package.base or package.name, base=package.base or package.name,
version=package.version, version=package.version,
remote=RemoteSource(source=PackageSource.Archive), remote=RemoteSource(source=PackageSource.ARCHIVE),
packages={package.name: description}, packages={package.name: description},
packager=package.packager, packager=package.packager,
) )
@@ -255,7 +255,7 @@ class Package(LazyLogging):
version = full_version(pkgbuild.get("epoch"), pkgbuild["pkgver"], pkgbuild["pkgrel"]) version = full_version(pkgbuild.get("epoch"), pkgbuild["pkgver"], pkgbuild["pkgrel"])
remote = RemoteSource( remote = RemoteSource(
source=PackageSource.Local, source=PackageSource.LOCAL,
git_url=path.absolute().as_uri(), git_url=path.absolute().as_uri(),
web_url=None, web_url=None,
path=".", path=".",
@@ -315,7 +315,7 @@ class Package(LazyLogging):
package = impl.info(name, pacman=pacman, include_provides=include_provides) package = impl.info(name, pacman=pacman, include_provides=include_provides)
remote = RemoteSource( remote = RemoteSource(
source=PackageSource.Repository, source=PackageSource.REPOSITORY,
git_url=Official.remote_git_url(package.package_base, package.repository), git_url=Official.remote_git_url(package.package_base, package.repository),
web_url=Official.remote_web_url(package.package_base), web_url=Official.remote_web_url(package.package_base),
path=".", path=".",
@@ -57,11 +57,13 @@ class PackageDescription:
>>> from pathlib import Path >>> from pathlib import Path
>>> from ahriman.core.alpm.pacman import Pacman >>> from ahriman.core.alpm.pacman import Pacman
>>> from ahriman.core.configuration import Configuration >>> from ahriman.core.configuration import Configuration
>>> from ahriman.models.pacman_synchronization import PacmanSynchronization
>>> from ahriman.models.repository_id import RepositoryId >>> from ahriman.models.repository_id import RepositoryId
>>> >>>
>>> configuration = Configuration() >>> configuration = Configuration()
>>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration) >>> pacman = Pacman(RepositoryId("x86_64", "aur"), configuration,
>>> pyalpm_description = next(package for package in pacman.package_get("pacman")) >>> refresh_database=PacmanSynchronization.DISABLED)
>>> pyalpm_description = next(package for package in pacman.package("pacman"))
>>> description = PackageDescription.from_package( >>> description = PackageDescription.from_package(
>>> pyalpm_description, Path("/var/cache/pacman/pkg/pacman-6.0.1-4-x86_64.pkg.tar.zst")) >>> pyalpm_description, Path("/var/cache/pacman/pkg/pacman-6.0.1-4-x86_64.pkg.tar.zst"))
""" """
@@ -32,31 +32,31 @@ class PackageSource(StrEnum):
package source for addition enumeration package source for addition enumeration
Attributes: Attributes:
Auto(PackageSource): automatically determine type of the source AUTO(PackageSource): automatically determine type of the source
Archive(PackageSource): source is a package archive ARCHIVE(PackageSource): source is a package archive
AUR(PackageSource): source is an AUR package for which it should search AUR(PackageSource): source is an AUR package for which it should search
Directory(PackageSource): source is a directory which contains packages DIRECTORY(PackageSource): source is a directory which contains packages
Local(PackageSource): source is locally stored PKGBUILD LOCAL(PackageSource): source is locally stored PKGBUILD
Remote(PackageSource): source is remote (http, ftp etc...) link REMOTE(PackageSource): source is remote (http, ftp etc...) link
Repository(PackageSource): source is official repository REPOSITORY(PackageSource): source is official repository
Examples: Examples:
In case if source is unknown the :func:`resolve()` and the source In case if source is unknown the :func:`resolve()` and the source
descriptor is available method must be used:: descriptor is available method must be used::
>>> real_source = PackageSource.Auto.resolve("ahriman", configuration.repository_paths) >>> real_source = PackageSource.AUTO.resolve("ahriman", configuration.repository_paths)
the code above will ensure that the presudo-source :attr:`Auto` the code above will ensure that the presudo-source :attr:`AUTO`
will not be processed later. will not be processed later.
""" """
Auto = "auto" AUTO = "auto"
Archive = "archive" ARCHIVE = "archive"
AUR = "aur" AUR = "aur"
Directory = "directory" DIRECTORY = "directory"
Local = "local" LOCAL = "local"
Remote = "remote" REMOTE = "remote"
Repository = "repository" REPOSITORY = "repository"
def resolve(self, source: str, paths: RepositoryPaths) -> PackageSource: def resolve(self, source: str, paths: RepositoryPaths) -> PackageSource:
""" """
@@ -69,21 +69,21 @@ class PackageSource(StrEnum):
Returns: Returns:
PackageSource: non-auto type of the package source PackageSource: non-auto type of the package source
""" """
if self != PackageSource.Auto: if self != PackageSource.AUTO:
return self return self
maybe_url = urlparse(source) # handle file:// like paths maybe_url = urlparse(source) # handle file:// like paths
maybe_path = Path(maybe_url.path) maybe_path = Path(maybe_url.path)
if maybe_url.scheme and maybe_url.scheme not in ("data", "file") and package_like(maybe_path): if maybe_url.scheme and maybe_url.scheme not in ("data", "file") and package_like(maybe_path):
return PackageSource.Remote return PackageSource.REMOTE
try: try:
if (maybe_path / "PKGBUILD").is_file() or paths.cache_for(source).is_dir(): if (maybe_path / "PKGBUILD").is_file() or paths.cache_for(source).is_dir():
return PackageSource.Local return PackageSource.LOCAL
if maybe_path.is_dir(): if maybe_path.is_dir():
return PackageSource.Directory return PackageSource.DIRECTORY
if maybe_path.is_file() and package_like(maybe_path): if maybe_path.is_file() and package_like(maybe_path):
return PackageSource.Archive return PackageSource.ARCHIVE
except PermissionError: except PermissionError:
# in some cases (e.g. if you run from your home directory with sudo) # in some cases (e.g. if you run from your home directory with sudo)
# it will try to read files to which it has no access. # it will try to read files to which it has no access.
+1 -1
View File
@@ -27,7 +27,7 @@ class Packagers:
Attributes: Attributes:
default(str | None): default packager username if any to be used if no override for the specified base was found default(str | None): default packager username if any to be used if no override for the specified base was found
overrides: dict[str, str | None]: packager username override for specific package base overrides(dict[str, str | None]): packager username override for specific package base
""" """
default: str | None = None default: str | None = None
@@ -25,11 +25,11 @@ class PacmanSynchronization(IntEnum):
pacman database synchronization flag pacman database synchronization flag
Attributes: Attributes:
Disabled(PacmanSynchronization): do not synchronize local database DISABLED(PacmanSynchronization): do not synchronize local database
Enabled(PacmanSynchronization): synchronize local database (same as pacman -Sy) ENABLED(PacmanSynchronization): synchronize local database (same as pacman -Sy)
Force(PacmanSynchronization): force synchronize local database (same as pacman -Syy) FORCE(PacmanSynchronization): force synchronize local database (same as pacman -Syy)
""" """
Disabled = 0 DISABLED = 0
Enabled = 1 ENABLED = 1
Force = 2 FORCE = 2
@@ -20,9 +20,10 @@
import json import json
import shlex import shlex
from collections.abc import Iterator
from dataclasses import dataclass, fields from dataclasses import dataclass, fields
from pathlib import Path from pathlib import Path
from typing import Any, Iterator, Self from typing import Any, Self
from ahriman.core.configuration.shell_template import ShellTemplate from ahriman.core.configuration.shell_template import ShellTemplate
from ahriman.core.utils import dataclass_view, filter_json from ahriman.core.utils import dataclass_view, filter_json
@@ -108,7 +109,7 @@ class PkgbuildPatch:
Args: Args:
key(str | None): variable key key(str | None): variable key
source(str): source value string to parse source(str | list[str]): source string to parse or list to use as is
Returns: Returns:
Self: parsed patch object Self: parsed patch object
@@ -59,7 +59,7 @@ class RemoteSource:
Returns: Returns:
bool: ``True`` in case if package is well-known remote source (e.g. AUR) and ``False`` otherwise bool: ``True`` in case if package is well-known remote source (e.g. AUR) and ``False`` otherwise
""" """
return self.source in (PackageSource.AUR, PackageSource.Repository) return self.source in (PackageSource.AUR, PackageSource.REPOSITORY)
@property @property
def pkgbuild_dir(self) -> Path | None: def pkgbuild_dir(self) -> Path | None:
@@ -27,22 +27,22 @@ class ReportSettings(StrEnum):
report targets enumeration report targets enumeration
Attributes: Attributes:
Disabled(ReportSettings): option which generates no report for testing purpose DISABLED(ReportSettings): option which generates no report for testing purpose
HTML(ReportSettings): HTML report generation HTML(ReportSettings): HTML report generation
Email(ReportSettings): email report generation EMAIL(ReportSettings): email report generation
Console(ReportSettings): print result to console CONSOLE(ReportSettings): print result to console
Telegram(ReportSettings): Markdown report to telegram channel TELEGRAM(ReportSettings): Markdown report to telegram channel
RSS(ReportSettings): RSS report generation RSS(ReportSettings): RSS report generation
RemoteCall(ReportSettings): remote ahriman server call REMOTE_CALL(ReportSettings): remote ahriman server call
""" """
Disabled = "disabled" # for testing purpose DISABLED = "disabled" # for testing purpose
HTML = "html" HTML = "html"
Email = "email" EMAIL = "email"
Console = "console" CONSOLE = "console"
Telegram = "telegram" TELEGRAM = "telegram"
RSS = "rss" RSS = "rss"
RemoteCall = "remote-call" REMOTE_CALL = "remote-call"
@staticmethod @staticmethod
def from_option(value: str) -> ReportSettings: # pylint: disable=too-many-return-statements def from_option(value: str) -> ReportSettings: # pylint: disable=too-many-return-statements
@@ -59,14 +59,14 @@ class ReportSettings(StrEnum):
case "html": case "html":
return ReportSettings.HTML return ReportSettings.HTML
case "email": case "email":
return ReportSettings.Email return ReportSettings.EMAIL
case "console": case "console":
return ReportSettings.Console return ReportSettings.CONSOLE
case "telegram": case "telegram":
return ReportSettings.Telegram return ReportSettings.TELEGRAM
case "rss": case "rss":
return ReportSettings.RSS return ReportSettings.RSS
case "ahriman" | "remote-call": case "ahriman" | "remote-call":
return ReportSettings.RemoteCall return ReportSettings.REMOTE_CALL
case _: case _:
return ReportSettings.Disabled return ReportSettings.DISABLED
@@ -56,7 +56,7 @@ class RepositoryStats:
construct statistics from list of repository packages construct statistics from list of repository packages
Args: Args:
packages(list[Packages]): list of repository packages packages(list[Package]): list of repository packages
Returns: Returns:
Self: constructed statistics object Self: constructed statistics object
@@ -41,7 +41,7 @@ class ScanPaths:
compiled regular expressions compiled regular expressions
Returns: Returns:
list[re.Pattern]: a list of compiled regular expressions list[re.Pattern[str]]: a list of compiled regular expressions
""" """
return [re.compile(path) for path in self.paths] return [re.compile(path) for path in self.paths]
@@ -27,14 +27,14 @@ class SignSettings(StrEnum):
sign targets enumeration sign targets enumeration
Attributes: Attributes:
Disabled(SignSettings): option which generates no report for testing purpose DISABLED(SignSettings): option which generates no report for testing purpose
Packages(SignSettings): sign each package PACKAGES(SignSettings): sign each package
Repository(SignSettings): sign repository database file REPOSITORY(SignSettings): sign repository database file
""" """
Disabled = "disabled" DISABLED = "disabled"
Packages = "packages" PACKAGES = "packages"
Repository = "repository" REPOSITORY = "repository"
@staticmethod @staticmethod
def from_option(value: str) -> SignSettings: def from_option(value: str) -> SignSettings:
@@ -49,8 +49,8 @@ class SignSettings(StrEnum):
""" """
match value.lower(): match value.lower():
case "package" | "packages" | "sign-package": case "package" | "packages" | "sign-package":
return SignSettings.Packages return SignSettings.PACKAGES
case "repository" | "sign-repository": case "repository" | "sign-repository":
return SignSettings.Repository return SignSettings.REPOSITORY
case _: case _:
return SignSettings.Disabled return SignSettings.DISABLED
@@ -27,12 +27,12 @@ class SmtpSSLSettings(StrEnum):
SMTP SSL mode enumeration SMTP SSL mode enumeration
Attributes: Attributes:
Disabled(SmtpSSLSettings): no SSL enabled DISABLED(SmtpSSLSettings): no SSL enabled
SSL(SmtpSSLSettings): use SMTP_SSL instead of normal SMTP client SSL(SmtpSSLSettings): use SMTP_SSL instead of normal SMTP client
STARTTLS(SmtpSSLSettings): use STARTTLS in normal SMTP client STARTTLS(SmtpSSLSettings): use STARTTLS in normal SMTP client
""" """
Disabled = "disabled" DISABLED = "disabled"
SSL = "ssl" SSL = "ssl"
STARTTLS = "starttls" STARTTLS = "starttls"
@@ -53,4 +53,4 @@ class SmtpSSLSettings(StrEnum):
case "starttls": case "starttls":
return SmtpSSLSettings.STARTTLS return SmtpSSLSettings.STARTTLS
case _: case _:
return SmtpSSLSettings.Disabled return SmtpSSLSettings.DISABLED
@@ -27,18 +27,18 @@ class UploadSettings(StrEnum):
remote synchronization targets enumeration remote synchronization targets enumeration
Attributes: Attributes:
Disabled(UploadSettings): no sync will be performed, required for testing purpose DISABLED(UploadSettings): no sync will be performed, required for testing purpose
Rsync(UploadSettings): sync via rsync RSYNC(UploadSettings): sync via rsync
S3(UploadSettings): sync to Amazon S3 S3(UploadSettings): sync to Amazon S3
GitHub(UploadSettings): sync to GitHub releases page GITHUB(UploadSettings): sync to GitHub releases page
RemoteService(UploadSettings): sync to another ahriman instance REMOTE_SERVICE(UploadSettings): sync to another ahriman instance
""" """
Disabled = "disabled" # for testing purpose DISABLED = "disabled" # for testing purpose
Rsync = "rsync" RSYNC = "rsync"
S3 = "s3" S3 = "s3"
GitHub = "github" GITHUB = "github"
RemoteService = "remote-service" REMOTE_SERVICE = "remote-service"
@staticmethod @staticmethod
def from_option(value: str) -> UploadSettings: def from_option(value: str) -> UploadSettings:
@@ -53,12 +53,12 @@ class UploadSettings(StrEnum):
""" """
match value.lower(): match value.lower():
case "rsync": case "rsync":
return UploadSettings.Rsync return UploadSettings.RSYNC
case "s3": case "s3":
return UploadSettings.S3 return UploadSettings.S3
case "github": case "github":
return UploadSettings.GitHub return UploadSettings.GITHUB
case "ahriman" | "remote-service": case "ahriman" | "remote-service":
return UploadSettings.RemoteService return UploadSettings.REMOTE_SERVICE
case _: case _:
return UploadSettings.Disabled return UploadSettings.DISABLED
+2 -2
View File
@@ -43,7 +43,7 @@ class User:
Simply create user from database data and perform required validation:: Simply create user from database data and perform required validation::
>>> password = User.generate_password(24) >>> password = User.generate_password(24)
>>> user = User(username="ahriman", password=password, access=UserAccess.Full) >>> user = User(username="ahriman", password=password, access=UserAccess.FULL)
Since the password supplied may be plain text, the :func:`hash_password()` method can be used to hash Since the password supplied may be plain text, the :func:`hash_password()` method can be used to hash
the password:: the password::
@@ -59,7 +59,7 @@ class User:
...and finally access can be verified:: ...and finally access can be verified::
>>> if user.verify_access(UserAccess.Read): >>> if user.verify_access(UserAccess.READ):
>>> print(f"user {user.username} has read access") >>> print(f"user {user.username} has read access")
""" """
@@ -27,17 +27,17 @@ class UserAccess(StrEnum):
web user access enumeration web user access enumeration
Attributes: Attributes:
Unauthorized(UserAccess): user can access specific resources which are marked as available UNAUTHORIZED(UserAccess): user can access specific resources which are marked as available
without authorization (e.g. login, logout, static) without authorization (e.g. login, logout, static)
Read(UserAccess): user can read the page READ(UserAccess): user can read the page
Reporter(UserAccess): user can read everything and is able to perform some modifications REPORTER(UserAccess): user can read everything and is able to perform some modifications
Full(UserAccess): user has full access FULL(UserAccess): user has full access
""" """
Unauthorized = "unauthorized" UNAUTHORIZED = "unauthorized"
Read = "read" READ = "read"
Reporter = "reporter" REPORTER = "reporter"
Full = "full" FULL = "full"
def permits(self, other: UserAccess) -> bool: def permits(self, other: UserAccess) -> bool:
""" """
@@ -59,7 +59,7 @@ def test_print_updates(application: Application, package_ahriman: Package, mocke
mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman]) mocker.patch("ahriman.core.repository.repository.Repository.packages", return_value=[package_ahriman])
print_mock = mocker.patch("ahriman.core.formatters.Printer.print") print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
application.print_updates(BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate), log_fn=print) application.print_updates(BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE), 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=": ")
@@ -68,14 +68,14 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
""" """
must append list of missing dependencies must append list of missing dependencies
""" """
def create_package_mock(package_base) -> MagicMock: def package(package_base: str) -> MagicMock:
mock = MagicMock() mock = MagicMock()
mock.base = package_base mock.base = package_base
mock.depends_build = [] mock.depends_build = []
mock.packages_full = [package_base] mock.packages_full = [package_base]
return mock return mock
def get_package(name: str | Path, *args: Any, **kwargs: Any) -> Package: def get_package(name: str | Path, *_args: Any, **_kwargs: Any) -> Package:
name = name if isinstance(name, str) else name.name name = name if isinstance(name, str) else name.name
return packages[name] return packages[name]
@@ -88,8 +88,8 @@ def test_with_dependencies(application: Application, package_ahriman: Package, p
packages = { packages = {
package_ahriman.base: package_ahriman, package_ahriman.base: package_ahriman,
package_python_schedule.base: package_python_schedule, package_python_schedule.base: package_python_schedule,
"python": create_package_mock("python"), "python": package("python"),
"python-installer": create_package_mock("python-installer"), "python-installer": package("python-installer"),
} }
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python") mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python")
@@ -99,7 +99,7 @@ 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")
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
result = application.with_dependencies(plan, process_dependencies=True) 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_ahriman.base).requester is None
@@ -124,12 +124,12 @@ def test_with_dependencies_split(application: Application, package_ahriman: Pack
""" """
must preserve resolved subpackages during dependency resolution must preserve resolved subpackages during dependency resolution
""" """
def package(base: str, name: str, dependencies: list[str]) -> Package: def package(package_base: str, package_name: str, dependencies: list[str]) -> Package:
return Package( return Package(
base=base, base=package_base,
version="1-1", version="1-1",
remote=package_ahriman.remote, remote=package_ahriman.remote,
packages={name: PackageDescription(depends=dependencies)}, packages={package_name: PackageDescription(depends=dependencies)},
) )
packages = { packages = {
@@ -144,7 +144,7 @@ def test_with_dependencies_split(application: Application, package_ahriman: Pack
plan = BuildPlan().update([ plan = BuildPlan().update([
package("ahriman", "ahriman", ["ahriman-core", "ahriman-web"]) package("ahriman", "ahriman", ["ahriman-core", "ahriman-web"])
], BuildPlanReason.QueuedRequest) ], BuildPlanReason.MANUAL_REQUEST)
result = application.with_dependencies(plan, process_dependencies=True) result = application.with_dependencies(plan, process_dependencies=True)
assert [[item.base for item in level] for level in Tree.resolve(result)] == [ assert [[item.base for item in level] for level in Tree.resolve(result)] == [
["python-tree-sitter-bash"], ["ahriman"], ["python-tree-sitter-bash"], ["ahriman"],
@@ -152,7 +152,7 @@ def test_with_dependencies_split(application: Application, package_ahriman: Pack
plan_item = result.item("ahriman") plan_item = result.item("ahriman")
assert plan_item.package.packages.keys() == {"ahriman", "ahriman-core", "ahriman-web"} assert plan_item.package.packages.keys() == {"ahriman", "ahriman-core", "ahriman-web"}
assert plan_item.reason == BuildPlanReason.QueuedRequest assert plan_item.reason == BuildPlanReason.MANUAL_REQUEST
assert plan_item.requester is None assert plan_item.requester is None
@@ -161,7 +161,7 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
""" """
must skip packages if exception occurs must skip packages if exception occurs
""" """
def create_package_mock(package_base) -> MagicMock: def package(package_base: str) -> MagicMock:
mock = MagicMock() mock = MagicMock()
mock.base = package_base mock.base = package_base
mock.depends_build = [] mock.depends_build = []
@@ -171,26 +171,28 @@ def test_with_dependencies_exception(application: Application, package_ahriman:
package_python_schedule.packages = { package_python_schedule.packages = {
package_python_schedule.base: package_python_schedule.packages[package_python_schedule.base] package_python_schedule.base: package_python_schedule.packages[package_python_schedule.base]
} }
package_ahriman.packages[package_ahriman.base].depends = ["devtools", "python", package_python_schedule.base] package_ahriman.packages[package_ahriman.base].depends = ["devtools", package_python_schedule.base]
package_ahriman.packages[package_ahriman.base].make_depends = ["python-build", "python-installer"] package_ahriman.packages[package_ahriman.base].make_depends = ["python-build", "python-installer"]
package_python_installer = package("python-installer")
packages = { packages = {
package_ahriman.base: package_ahriman, package_ahriman.base: package_ahriman,
package_python_schedule.base: package_python_schedule, package_python_schedule.base: package_python_schedule,
"python": create_package_mock("python"), "python": package("python"),
"python-installer": create_package_mock("python-installer"), "python-installer": package_python_installer,
} }
mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python") mocker.patch("pathlib.Path.is_dir", autospec=True, side_effect=lambda p: p.name == "python")
mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda *args: packages[args[0]]) mocker.patch("ahriman.models.package.Package.from_aur", side_effect=lambda *args: packages[args[0]])
mocker.patch("ahriman.models.package.Package.from_build", side_effect=Exception) mocker.patch("ahriman.models.package.Package.from_build", side_effect=Exception)
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"})
failed_mock = mocker.patch("ahriman.core.status.Client.set_failed")
plan = BuildPlan() plan = BuildPlan().update([package_ahriman, package_python_installer], BuildPlanReason.REGULAR_UPDATE)
plan.add(package_ahriman, BuildPlanReason.RegularUpdate) application.with_dependencies(plan, process_dependencies=True)
assert application.with_dependencies(plan, process_dependencies=True) is plan assert plan.packages == [package_python_installer]
assert plan.packages == [package_ahriman] failed_mock.assert_called_once_with(package_ahriman.base)
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:
@@ -199,7 +201,7 @@ 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")
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
assert application.with_dependencies(plan, process_dependencies=False).packages == [package_ahriman] assert application.with_dependencies(plan, process_dependencies=False).packages == [package_ahriman]
packages_mock.assert_not_called() packages_mock.assert_not_called()
@@ -167,7 +167,7 @@ def test_add_add_archive(application_packages: ApplicationPackages, package_ahri
""" """
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_archive") add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_archive")
application_packages.add([package_ahriman.base], PackageSource.Archive, "packager") application_packages.add([package_ahriman.base], PackageSource.ARCHIVE, "packager")
add_mock.assert_called_once_with(package_ahriman.base, "packager") add_mock.assert_called_once_with(package_ahriman.base, "packager")
@@ -189,7 +189,7 @@ def test_add_add_directory(application_packages: ApplicationPackages, package_ah
""" """
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_directory") add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_directory")
application_packages.add([package_ahriman.base], PackageSource.Directory, "packager") application_packages.add([package_ahriman.base], PackageSource.DIRECTORY, "packager")
add_mock.assert_called_once_with(package_ahriman.base, "packager") add_mock.assert_called_once_with(package_ahriman.base, "packager")
@@ -200,7 +200,7 @@ def test_add_add_local(application_packages: ApplicationPackages, package_ahrima
""" """
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_local") add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_local")
application_packages.add([package_ahriman.base], PackageSource.Local, "packager") application_packages.add([package_ahriman.base], PackageSource.LOCAL, "packager")
add_mock.assert_called_once_with(package_ahriman.base, "packager") add_mock.assert_called_once_with(package_ahriman.base, "packager")
@@ -212,7 +212,7 @@ def test_add_add_remote(application_packages: ApplicationPackages, package_descr
add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_remote") add_mock = mocker.patch("ahriman.application.application.application_packages.ApplicationPackages._add_remote")
url = f"https://host/{package_description_ahriman.filename}" url = f"https://host/{package_description_ahriman.filename}"
application_packages.add([url], PackageSource.Remote, "packager") application_packages.add([url], PackageSource.REMOTE, "packager")
add_mock.assert_called_once_with(url, "packager") add_mock.assert_called_once_with(url, "packager")
@@ -16,7 +16,7 @@ def test_call(args: argparse.Namespace, configuration: Configuration, mocker: Mo
must call inside lock must call inside lock
""" """
args.configuration = Path("") args.configuration = Path("")
args.log_handler = LogHandler.Console args.log_handler = LogHandler.CONSOLE
args.quiet = False args.quiet = False
args.report = False args.report = False
mocker.patch("ahriman.application.handlers.handler.Handler.run") mocker.patch("ahriman.application.handlers.handler.Handler.run")
@@ -24,7 +24,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
args.package = ["ahriman"] args.package = ["ahriman"]
args.now = False args.now = False
args.refresh = 0 args.refresh = 0
args.source = PackageSource.Auto args.source = PackageSource.AUTO
args.username = "username" args.username = "username"
args.variable = None args.variable = None
return args return args
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
Returns: Returns:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.action = Action.List args.action = Action.LIST
args.exit_code = False args.exit_code = False
args.info = False args.info = False
args.package = "package" args.package = "package"
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
Returns: Returns:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.action = Action.List args.action = Action.LIST
args.exit_code = False args.exit_code = False
args.package = "package" args.package = "package"
return args return args
@@ -68,7 +68,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
must remove package changes must remove package changes
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Remove args.action = Action.REMOVE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update") update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_update")
@@ -102,9 +102,9 @@ def test_copy_package(package_ahriman: Package, application: Application, mocker
path = application.repository.paths.repository / package_ahriman.packages[package_ahriman.base].filename path = application.repository.paths.repository / package_ahriman.packages[package_ahriman.base].filename
Copy.copy_package(package_ahriman, application, application) Copy.copy_package(package_ahriman, application, application)
add_mock.assert_called_once_with([str(path)], PackageSource.Archive) add_mock.assert_called_once_with([str(path)], PackageSource.ARCHIVE)
changes_get_mock.assert_called_once_with(package_ahriman.base) changes_get_mock.assert_called_once_with(package_ahriman.base)
changes_update_mock.assert_called_once_with(package_ahriman.base, changes_get_mock.return_value) changes_update_mock.assert_called_once_with(package_ahriman.base, changes_get_mock.return_value)
deps_get_mock.assert_called_once_with(package_ahriman.base) deps_get_mock.assert_called_once_with(package_ahriman.base)
deps_update_mock.assert_called_once_with(package_ahriman.base, deps_get_mock.return_value) deps_update_mock.assert_called_once_with(package_ahriman.base, deps_get_mock.return_value)
package_update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.Pending) package_update_mock.assert_called_once_with(package_ahriman, BuildStatusEnum.PENDING)
@@ -1,5 +1,4 @@
import argparse import argparse
import pytest
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
@@ -29,7 +28,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
must run command must run command
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Update args.action = Action.UPDATE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update") hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update")
@@ -44,7 +43,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
must remove held status must remove held status
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Remove args.action = Action.REMOVE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update") hold_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_hold_update")
@@ -38,7 +38,7 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
must run command must run command
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Update args.action = Action.UPDATE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
patch_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_create_from_diff", patch_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_create_from_diff",
return_value=(args.package, PkgbuildPatch(None, "patch"))) return_value=(args.package, PkgbuildPatch(None, "patch")))
@@ -56,7 +56,7 @@ def test_run_function(args: argparse.Namespace, configuration: Configuration, re
must run command with patch function flag must run command with patch function flag
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Update args.action = Action.UPDATE
args.patch = "patch" args.patch = "patch"
args.variable = "version" args.variable = "version"
patch = PkgbuildPatch(args.variable, args.patch) patch = PkgbuildPatch(args.variable, args.patch)
@@ -77,7 +77,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, reposi
must run command with list flag must run command with list flag
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.List args.action = Action.LIST
args.variable = ["version"] args.variable = ["version"]
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list") application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_list")
@@ -93,7 +93,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
must run command with remove flag must run command with remove flag
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Remove args.action = Action.REMOVE
args.variable = ["version"] args.variable = ["version"]
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_remove") application_mock = mocker.patch("ahriman.application.handlers.patch.Patch.patch_set_remove")
@@ -169,7 +169,7 @@ def test_patch_set_list(application: Application, mocker: MockerFixture) -> None
Patch.patch_set_list(application, "ahriman", ["version"], False) Patch.patch_set_list(application, "ahriman", ["version"], False)
get_mock.assert_called_once_with("ahriman", None) get_mock.assert_called_once_with("ahriman", None)
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ") print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
check_mock.assert_called_once_with(False, [PkgbuildPatch(key='version', value='value')]) check_mock.assert_called_once_with(False, [PkgbuildPatch(key="version", value="value")])
def test_patch_set_list_all(application: Application, mocker: MockerFixture) -> None: def test_patch_set_list_all(application: Application, mocker: MockerFixture) -> None:
@@ -184,7 +184,7 @@ def test_patch_set_list_all(application: Application, mocker: MockerFixture) ->
Patch.patch_set_list(application, "ahriman", None, False) Patch.patch_set_list(application, "ahriman", None, False)
get_mock.assert_called_once_with("ahriman", None) get_mock.assert_called_once_with("ahriman", None)
print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ") print_mock.assert_called_once_with(verbose=True, log_fn=pytest.helpers.anyvar(int), separator=" = ")
check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value='patch')]) check_mock.assert_called_once_with(False, [PkgbuildPatch(key=None, value="patch")])
def test_patch_set_list_empty_exception(application: Application, mocker: MockerFixture) -> None: def test_patch_set_list_empty_exception(application: Application, mocker: MockerFixture) -> None:
@@ -21,7 +21,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
Returns: Returns:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.action = Action.List args.action = Action.LIST
args.exit_code = False args.exit_code = False
args.package = "package" args.package = "package"
return args return args
@@ -68,7 +68,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
must remove package pkgbuild must remove package pkgbuild
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Remove args.action = Action.REMOVE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
changes = Changes("sha", "change", "pkgbuild content") changes = Changes("sha", "change", "pkgbuild content")
mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes) mocker.patch("ahriman.core.status.local_client.LocalClient.package_changes_get", return_value=changes)
@@ -54,7 +54,7 @@ def test_run(args: argparse.Namespace, package_ahriman: Package, configuration:
_, 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) 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)
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment) print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
@@ -97,7 +97,7 @@ 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()
plan = BuildPlan().update([package_ahriman], BuildPlanReason.Rebuild) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REBUILD)
check_mock.assert_called_once_with(False, plan) check_mock.assert_called_once_with(False, plan)
print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment) print_mock.assert_called_once_with(plan, pytest.helpers.anyvar(int), bump_pkgrel=args.increment)
@@ -189,10 +189,10 @@ def test_extract_packages_by_status(application: Application, mocker: MockerFixt
must extract packages from database and filter them by status must extract packages from database and filter them by status
""" """
packages_mock = mocker.patch("ahriman.core.database.SQLite.packages_get", return_value=[ packages_mock = mocker.patch("ahriman.core.database.SQLite.packages_get", return_value=[
("package1", BuildStatus(BuildStatusEnum.Success)), ("package1", BuildStatus(BuildStatusEnum.SUCCESS)),
("package2", BuildStatus(BuildStatusEnum.Failed)), ("package2", BuildStatus(BuildStatusEnum.FAILED)),
]) ])
assert Rebuild.extract_packages(application, BuildStatusEnum.Failed, from_database=True) == ["package2"] assert Rebuild.extract_packages(application, BuildStatusEnum.FAILED, from_database=True) == ["package2"]
packages_mock.assert_called_once_with(application.repository_id) packages_mock.assert_called_once_with(application.repository_id)
@@ -39,7 +39,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
args.repository = "aur" args.repository = "aur"
args.server = None args.server = None
args.sign_key = "key" args.sign_key = "key"
args.sign_target = [SignSettings.Packages] args.sign_target = [SignSettings.PACKAGES]
args.web_port = 8080 args.web_port = 8080
args.web_unix_socket = Path("/var/lib/ahriman/ahriman-web.sock") args.web_unix_socket = Path("/var/lib/ahriman/ahriman-web.sock")
return args return args
@@ -244,7 +244,7 @@ def test_configuration_create_directory(configuration: Configuration, mocker: Mo
""" """
must create writable directory for includes must create writable directory for includes
""" """
configuration.set_option("settings", "include", f"/path1 /path2 /path3") configuration.set_option("settings", "include", "/path1 /path2 /path3")
mkdir_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.ensure_exists", mkdir_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.ensure_exists",
side_effect=[OSError, "/path2", "/path3"]) side_effect=[OSError, "/path2", "/path3"])
access_mock = mocker.patch("os.access", side_effect=[False, True]) access_mock = mocker.patch("os.access", side_effect=[False, True])
@@ -25,7 +25,7 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.chart = None args.chart = None
args.event = EventType.PackageUpdated args.event = EventType.PACKAGE_UPDATED
args.from_date = None args.from_date = None
args.limit = -1 args.limit = -1
args.offset = 0 args.offset = 0
@@ -37,8 +37,8 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
""" """
args = _default_args(args) args = _default_args(args)
packages = [ packages = [
(package_ahriman, BuildStatus(BuildStatusEnum.Success)), (package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS)),
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed)), (package_python_schedule, BuildStatus(BuildStatusEnum.FAILED)),
] ]
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
application_mock = mocker.patch("ahriman.core.status.Client.status_get") application_mock = mocker.patch("ahriman.core.status.Client.status_get")
@@ -83,7 +83,7 @@ def test_run_verbose(args: argparse.Namespace, configuration: Configuration, rep
args.info = True args.info = True
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
mocker.patch("ahriman.core.status.local_client.LocalClient.package_get", mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success))]) return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS))])
print_mock = mocker.patch("ahriman.core.formatters.Printer.print") print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
_, repository_id = configuration.check_loaded() _, repository_id = configuration.check_loaded()
@@ -103,7 +103,7 @@ def test_run_with_package_filter(args: argparse.Namespace, configuration: Config
args.package = [package_ahriman.base] args.package = [package_ahriman.base]
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
packages_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_get", packages_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success))]) return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS))])
_, repository_id = configuration.check_loaded() _, repository_id = configuration.check_loaded()
Status.run(args, repository_id, configuration, report=False) Status.run(args, repository_id, configuration, report=False)
@@ -116,10 +116,10 @@ def test_run_by_status(args: argparse.Namespace, configuration: Configuration, r
must filter packages by status must filter packages by status
""" """
args = _default_args(args) args = _default_args(args)
args.status = BuildStatusEnum.Failed args.status = BuildStatusEnum.FAILED
mocker.patch("ahriman.core.status.local_client.LocalClient.package_get", mocker.patch("ahriman.core.status.local_client.LocalClient.package_get",
return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.Success)), return_value=[(package_ahriman, BuildStatus(BuildStatusEnum.SUCCESS)),
(package_python_schedule, BuildStatus(BuildStatusEnum.Failed))]) (package_python_schedule, BuildStatus(BuildStatusEnum.FAILED))])
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
print_mock = mocker.patch("ahriman.core.formatters.Printer.print") print_mock = mocker.patch("ahriman.core.formatters.Printer.print")
@@ -22,8 +22,8 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.package = None args.package = None
args.action = Action.Update args.action = Action.UPDATE
args.status = BuildStatusEnum.Success args.status = BuildStatusEnum.SUCCESS
return args return args
@@ -63,7 +63,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, repo
""" """
args = _default_args(args) args = _default_args(args)
args.package = [package_ahriman.base] args.package = [package_ahriman.base]
args.action = Action.Remove args.action = Action.REMOVE
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository) mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_remove") update_mock = mocker.patch("ahriman.core.status.local_client.LocalClient.package_remove")
@@ -8,8 +8,8 @@ from ahriman.application.application import Application
from ahriman.application.handlers.update import Update 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.build_plan import BuildPlan, BuildPlanReason from ahriman.models.build_plan import BuildPlan, BuildPlanReason
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
@@ -66,7 +66,7 @@ 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) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies", dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
return_value=plan) return_value=plan)
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan) updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
@@ -110,7 +110,7 @@ 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())
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
mocker.patch("ahriman.application.application.Application.updates", return_value=plan) 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.with_dependencies", return_value=plan)
mocker.patch("ahriman.application.application.Application.changes") mocker.patch("ahriman.application.application.Application.changes")
@@ -131,7 +131,7 @@ def test_perform_action_dry_run(args: argparse.Namespace, application: Applicati
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")
print_mock = mocker.patch("ahriman.application.application.Application.print_updates") print_mock = mocker.patch("ahriman.application.application.Application.print_updates")
plan = BuildPlan().update([package_ahriman], BuildPlanReason.RegularUpdate) plan = BuildPlan().update([package_ahriman], BuildPlanReason.REGULAR_UPDATE)
dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies", dependencies_mock = mocker.patch("ahriman.application.application.Application.with_dependencies",
return_value=plan) return_value=plan)
updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan) updates_mock = mocker.patch("ahriman.application.application.Application.updates", return_value=plan)
@@ -24,12 +24,12 @@ def _default_args(args: argparse.Namespace) -> argparse.Namespace:
argparse.Namespace: generated arguments for these test cases argparse.Namespace: generated arguments for these test cases
""" """
args.username = "user" args.username = "user"
args.action = Action.Update args.action = Action.UPDATE
args.exit_code = False args.exit_code = False
args.key = "key" args.key = "key"
args.packager = "packager" args.packager = "packager"
args.password = "pa55w0rd" args.password = "pa55w0rd"
args.role = UserAccess.Reporter args.role = UserAccess.REPORTER
return args return args
@@ -97,7 +97,7 @@ def test_run_list(args: argparse.Namespace, configuration: Configuration, databa
must list available users must list available users
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.List args.action = Action.LIST
mocker.patch("ahriman.core.database.SQLite.load", return_value=database) mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status") check_mock = mocker.patch("ahriman.application.handlers.handler.Handler.check_status")
list_mock = mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[user]) list_mock = mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[user])
@@ -114,7 +114,7 @@ def test_run_empty_exception(args: argparse.Namespace, configuration: Configurat
must raise ExitCode exception on empty user list must raise ExitCode exception on empty user list
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.List args.action = Action.LIST
args.exit_code = True args.exit_code = True
mocker.patch("ahriman.core.database.SQLite.load", return_value=database) mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[]) mocker.patch("ahriman.core.database.SQLite.user_list", return_value=[])
@@ -131,7 +131,7 @@ def test_run_remove(args: argparse.Namespace, configuration: Configuration, data
must remove user if remove flag supplied must remove user if remove flag supplied
""" """
args = _default_args(args) args = _default_args(args)
args.action = Action.Remove args.action = Action.REMOVE
mocker.patch("ahriman.core.database.SQLite.load", return_value=database) mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
remove_mock = mocker.patch("ahriman.core.database.SQLite.user_remove") remove_mock = mocker.patch("ahriman.core.database.SQLite.user_remove")
@@ -288,7 +288,7 @@ def test_subparsers_package_archives(parser: argparse.ArgumentParser) -> None:
package-archives command must imply action, exit code, info, lock, quiet, report and unsafe package-archives command must imply action, exit code, info, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-archives", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-archives", "ahriman"])
assert args.action == Action.List assert args.action == Action.LIST
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert not args.exit_code assert not args.exit_code
assert not args.info assert not args.info
@@ -304,7 +304,7 @@ def test_subparsers_package_changes(parser: argparse.ArgumentParser) -> None:
package-changes command must imply action, exit code, lock, quiet, report and unsafe package-changes command must imply action, exit code, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes", "ahriman"])
assert args.action == Action.List assert args.action == Action.LIST
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -319,7 +319,7 @@ def test_subparsers_package_changes_remove(parser: argparse.ArgumentParser) -> N
package-changes-remove command must imply action, lock, quiet, report and unsafe package-changes-remove command must imply action, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes-remove", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes-remove", "ahriman"])
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
@@ -362,7 +362,7 @@ def test_subparsers_package_pkgbuild(parser: argparse.ArgumentParser) -> None:
package-pkgbuild command must imply action, exit code, lock, quiet, report and unsafe package-pkgbuild command must imply action, exit code, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild", "ahriman"])
assert args.action == Action.List assert args.action == Action.LIST
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -377,7 +377,7 @@ def test_subparsers_package_pkgbuild_remove(parser: argparse.ArgumentParser) ->
package-pkgbuild-remove command must imply action, lock, quiet, report and unsafe package-pkgbuild-remove command must imply action, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild-remove", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-pkgbuild-remove", "ahriman"])
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
@@ -496,7 +496,7 @@ def test_subparsers_package_status_remove(parser: argparse.ArgumentParser) -> No
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-remove", "ahriman"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-remove", "ahriman"])
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
assert not args.report assert not args.report
@@ -510,7 +510,7 @@ def test_subparsers_package_status_update(parser: argparse.ArgumentParser) -> No
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-update"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-update"])
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
assert not args.report assert not args.report
@@ -543,7 +543,7 @@ def test_subparsers_package_hold(parser: argparse.ArgumentParser) -> None:
package-hold command must imply action, lock, quiet, report and unsafe package-hold command must imply action, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["package-hold", "ahriman"]) args = parser.parse_args(["package-hold", "ahriman"])
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
assert not args.report assert not args.report
@@ -555,7 +555,7 @@ def test_subparsers_package_unhold(parser: argparse.ArgumentParser) -> None:
package-unhold command must imply action, lock, quiet, report and unsafe package-unhold command must imply action, lock, quiet, report and unsafe
""" """
args = parser.parse_args(["package-unhold", "ahriman"]) args = parser.parse_args(["package-unhold", "ahriman"])
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
assert not args.report assert not args.report
@@ -567,7 +567,7 @@ def test_subparsers_patch_add(parser: argparse.ArgumentParser) -> None:
patch-add command must imply action, architecture list, exit code, lock, report and repository patch-add command must imply action, architecture list, exit code, lock, report and repository
""" """
args = parser.parse_args(["patch-add", "ahriman", "version"]) args = parser.parse_args(["patch-add", "ahriman", "version"])
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.architecture == "" assert args.architecture == ""
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -596,7 +596,7 @@ def test_subparsers_patch_list(parser: argparse.ArgumentParser) -> None:
patch-list command must imply action, architecture list, lock, report, repository and unsafe patch-list command must imply action, architecture list, lock, report, repository and unsafe
""" """
args = parser.parse_args(["patch-list", "ahriman"]) args = parser.parse_args(["patch-list", "ahriman"])
assert args.action == Action.List assert args.action == Action.LIST
assert args.architecture == "" assert args.architecture == ""
assert args.lock is None assert args.lock is None
assert not args.report assert not args.report
@@ -651,7 +651,7 @@ def test_subparsers_patch_remove(parser: argparse.ArgumentParser) -> None:
patch-remove command must imply action, architecture list, exit code, lock, report and repository patch-remove command must imply action, architecture list, exit code, lock, report and repository
""" """
args = parser.parse_args(["patch-remove", "ahriman"]) args = parser.parse_args(["patch-remove", "ahriman"])
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.architecture == "" assert args.architecture == ""
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -706,7 +706,7 @@ def test_subparsers_patch_set_add(parser: argparse.ArgumentParser) -> None:
patch-set-add command must imply action, architecture list, exit code, lock, report, repository and variable patch-set-add command must imply action, architecture list, exit code, lock, report, repository and variable
""" """
args = parser.parse_args(["patch-set-add", "ahriman"]) args = parser.parse_args(["patch-set-add", "ahriman"])
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.architecture == "" assert args.architecture == ""
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -1172,7 +1172,7 @@ def test_subparsers_repo_status_update(parser: argparse.ArgumentParser) -> None:
""" """
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "repo-status-update"]) args = parser.parse_args(["-a", "x86_64", "-r", "repo", "repo-status-update"])
assert args.architecture == "x86_64" assert args.architecture == "x86_64"
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
assert not args.report assert not args.report
@@ -1537,7 +1537,7 @@ def test_subparsers_service_setup_option_sign_target_multiple(parser: argparse.A
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup", args = parser.parse_args(["-a", "x86_64", "-r", "repo", "service-setup",
"--packager", "ahriman bot <ahriman@example.com>", "--sign-target", "packages", "--packager", "ahriman bot <ahriman@example.com>", "--sign-target", "packages",
"--sign-target", "repository"]) "--sign-target", "repository"])
assert args.sign_target == [SignSettings.Packages, SignSettings.Repository] assert args.sign_target == [SignSettings.PACKAGES, SignSettings.REPOSITORY]
def test_subparsers_service_shell(parser: argparse.ArgumentParser) -> None: def test_subparsers_service_shell(parser: argparse.ArgumentParser) -> None:
@@ -1564,7 +1564,7 @@ def test_subparsers_user_add(parser: argparse.ArgumentParser) -> None:
user-add command must imply action, architecture, exit code, lock, quiet, report and repository user-add command must imply action, architecture, exit code, lock, quiet, report and repository
""" """
args = parser.parse_args(["user-add", "username"]) args = parser.parse_args(["user-add", "username"])
assert args.action == Action.Update assert args.action == Action.UPDATE
assert args.architecture == "" assert args.architecture == ""
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -1604,7 +1604,7 @@ def test_subparsers_user_list(parser: argparse.ArgumentParser) -> None:
user-list command must imply action, architecture, lock, quiet, report, repository and unsafe user-list command must imply action, architecture, lock, quiet, report, repository and unsafe
""" """
args = parser.parse_args(["user-list"]) args = parser.parse_args(["user-list"])
assert args.action == Action.List assert args.action == Action.LIST
assert args.architecture == "" assert args.architecture == ""
assert args.lock is None assert args.lock is None
assert args.quiet assert args.quiet
@@ -1652,7 +1652,7 @@ def test_subparsers_user_remove(parser: argparse.ArgumentParser) -> None:
user-remove command must imply action, architecture, exit code, lock, quiet, report and repository user-remove command must imply action, architecture, exit code, lock, quiet, report and repository
""" """
args = parser.parse_args(["user-remove", "username"]) args = parser.parse_args(["user-remove", "username"])
assert args.action == Action.Remove assert args.action == Action.REMOVE
assert args.architecture == "" assert args.architecture == ""
assert not args.exit_code assert not args.exit_code
assert args.lock is None assert args.lock is None
@@ -278,7 +278,7 @@ def test_enter(lock: Lock, mocker: MockerFixture) -> None:
check_user_mock.assert_called_once_with() check_user_mock.assert_called_once_with()
check_version_mock.assert_called_once_with() check_version_mock.assert_called_once_with()
lock_mock.assert_called_once_with() lock_mock.assert_called_once_with()
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Success)]) update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.BUILDING), MockCall(BuildStatusEnum.SUCCESS)])
def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None: def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
@@ -293,4 +293,4 @@ def test_exit_with_exception(lock: Lock, mocker: MockerFixture) -> None:
with pytest.raises(ValueError): with pytest.raises(ValueError):
with lock: with lock:
raise ValueError() raise ValueError()
update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.Building), MockCall(BuildStatusEnum.Failed)]) update_status_mock.assert_has_calls([MockCall(BuildStatusEnum.BUILDING), MockCall(BuildStatusEnum.FAILED)])
Loaded 100 of 260 files, more files were not shown because too many files have changed in this diff. Show more