Compare commits

..
9 Commits
Author SHA1 Message Date
arcanis 695424fa16 feat: remove makepkg.conf local configuration, use ahriman own
configuration instead

We used .makepkg.conf solely for two features - MAKEFLAGS and PACKAGER,
which could be actually easily implemented by using environment
variables
2026-08-13 16:39:13 +03:00
arcanis 255ebe117a feat: read includes from list of directories 2026-08-13 16:39:13 +03:00
arcanis a9a12cd247 feat: get rid of sudoers modification during setup command
This commit introduces small shell wrapper, which calls archbuild
mimicing symlinked command. It allows to distribute static sudoers file.

Additionally build_command option has been renamed to devtools_wrapper
in order to allow to keep backward compatibility
2026-08-13 14:26:49 +03:00
arcanis 8dc198aa2b build: tox cleanup 2026-08-13 14:26:49 +03:00
arcanis 1133b75c33 refactor: implement generic optional import mechanisms
this project is actively using optional imports, which leads to
duplicate handling here and there. This commit implements logic in
special method to reduce complexity and simplify tests paths
2026-08-13 14:26:49 +03:00
arcanis 777bedf772 build: handle local imports in pylint check correctly 2026-08-13 14:26:49 +03:00
arcanis cc6ca46342 build: fix mypy type install 2026-08-13 14:26:49 +03:00
arcanis 2eb51ba85a Release 2.21.1 2026-07-21 10:46:21 +03:00
arcanis 36e28aba99 fix: always load tab on remount
it fixes a bug, which leads to missing tab content load when opening
package info
2026-07-21 10:44:20 +03:00
48 changed files with 394 additions and 380 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ For installation details kindly refer to the [documentation](https://ahriman.rea
Every available option is described in the [documentation](https://ahriman.readthedocs.io/en/stable/configuration.html).
The application provides reasonable defaults which allow to use it out-of-box; however additional steps (like configuring build toolchain and sudoers) are recommended and can be easily achieved by following install instructions.
The application provides reasonable defaults which allow to use it out-of-box; however additional steps (like configuring build toolchain) are recommended and can be easily achieved by following install instructions.
## [FAQ](https://ahriman.readthedocs.io/en/stable/faq/index.html)
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
set -euo pipefail
usage() {
local cmd="${0##*/}"
echo "Usage: $cmd [options] -- [archbuild args]"
echo " -r <repository> Repository name"
echo " -a <architecture> Repository architecture"
exit 1
}
repository=
architecture=
while getopts ":r:a:" arg; do
case "$arg" in
r) repository="$OPTARG" ;;
a) architecture="$OPTARG" ;;
*) usage ;;
esac
done
if [[ -z $repository || -z $architecture ]]; then
usage
fi
source "/usr/share/devtools/lib/archroot.sh"
check_root "SOURCE_DATE_EPOCH,SRCDEST,SRCPKGDEST,PKGDEST,LOGDEST,NPROC,MAKEFLAGS,PACKAGER,GNUPGHOME" "${BASH_SOURCE[0]}" "$@"
exec bash -c '
source "$1" "${@:2}"
' "${repository}-${architecture}-build" "archbuild" "${@:$OPTIND}"
@@ -1,6 +1,6 @@
[settings]
; Relative path to directory with configuration files overrides. Overrides will be applied in alphabetic order.
include = ahriman.ini.d
include = ahriman.ini.d $HOME/.config/ahriman.ini.d
; Relative path to configuration used by logging package.
logging = ahriman.ini.d/logging.ini
; Perform database migrations on the application start. Do not touch this option unless you know what you are doing.
@@ -35,17 +35,21 @@ retry_backoff = 1.0
; List of additional flags passed to archbuild command.
;archbuild_flags =
; Path to build command.
;build_command =
devtools_wrapper = ahriman-archbuild
; List of packages to be ignored during automatic updates.
;ignore_packages =
; Include debug packages.
;include_debug_packages = yes
; List of additional flags passed to make via environment variable via makepkg command.
;make_flags =
; List of additional flags passed to makechrootpkg command.
;makechrootpkg_flags =
; Minimal age in seconds since the latest AUR package modification before automatic updates are allowed.
;min_age = 0
; List of additional flags passed to makepkg command.
makepkg_flags = --nocolor --ignorearch
; Minimal age in seconds since the latest AUR package modification before automatic updates are allowed.
;min_age = 0
; Default packager identifier to be used for package builds
;packager =
; List of paths to be used for implicit dependency scan. Regular expressions are supported.
scan_paths = ^usr/lib(?!/cmake).*$
; List of enabled triggers in the order of calls.
@@ -1,4 +1,4 @@
.TH AHRIMAN "1" "2026\-07\-21" "ahriman 2.21.0" "ArcH linux ReposItory MANager"
.TH AHRIMAN "1" "2026\-07\-21" "ahriman 2.21.1" "ArcH linux ReposItory MANager"
.SH NAME
ahriman \- ArcH linux ReposItory MANager
.SH SYNOPSIS
+1
View File
@@ -57,6 +57,7 @@ packages = [
]
[tool.hatch.build.targets.wheel.shared-data]
"package/bin" = "bin"
"package/lib" = "lib"
"package/share" = "share"
+1 -1
View File
@@ -17,4 +17,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__version__ = "2.21.0"
__version__ = "2.21.1"
@@ -18,9 +18,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import argparse
import multiprocessing
import os
from pathlib import Path
from pwd import getpwuid
from typing import ClassVar
from urllib.parse import quote_plus as url_encode
@@ -30,7 +31,6 @@ from ahriman.core.configuration import Configuration
from ahriman.core.exceptions import MissingArchitectureError
from ahriman.core.utils import enum_values
from ahriman.models.repository_id import RepositoryId
from ahriman.models.repository_paths import RepositoryPaths
from ahriman.models.sign_settings import SignSettings
from ahriman.models.user import User
@@ -40,16 +40,12 @@ class Setup(Handler):
setup handler
Attributes:
ARCHBUILD_COMMAND_PATH(Path): (class attribute) default devtools command
MIRRORLIST_PATH(Path): (class attribute) path to pacman default mirrorlist (used by multilib repository)
SUDOERS_DIR_PATH(Path): (class attribute) path to sudoers.d includes directory
"""
ALLOW_MULTI_ARCHITECTURE_RUN = False # conflicting io
ARCHBUILD_COMMAND_PATH: ClassVar[Path] = Path("/") / "usr" / "bin" / "archbuild"
MIRRORLIST_PATH: ClassVar[Path] = Path("/") / "etc" / "pacman.d" / "mirrorlist"
SUDOERS_DIR_PATH: ClassVar[Path] = Path("/") / "etc" / "sudoers.d"
@classmethod
def run(cls, args: argparse.Namespace, repository_id: RepositoryId, configuration: Configuration, *,
@@ -73,12 +69,9 @@ class Setup(Handler):
application = Application(repository_id, configuration, report=report)
# basically we create configuration here as root, but it is ok, because those files are only used for reading
Setup.configuration_create_makepkg(args.packager, args.makeflags_jobs, application.repository.paths)
Setup.executable_create(application.repository.paths, repository_id)
repository_server = f"file://{application.repository.paths.repository}" if args.server is None else args.server
Setup.configuration_create_devtools(
repository_id, args.from_configuration, args.mirror, args.multilib, repository_server)
Setup.configuration_create_sudo(application.repository.paths, repository_id)
# finish initialization
with application.repository.paths.preserve_owner():
@@ -124,20 +117,6 @@ class Setup(Handler):
parser.set_defaults(lock=None, quiet=True, report=False, unsafe=True)
return parser
@staticmethod
def build_command(root: Path, repository_id: RepositoryId) -> Path:
"""
generate build command name
Args:
root(Path): root directory for the build command (must be root of the repository)
repository_id(RepositoryId): repository unique identifier
Returns:
Path: valid devtools command name
"""
return root / f"{repository_id.name}-{repository_id.architecture}-build"
@staticmethod
def configuration_create_ahriman(args: argparse.Namespace, repository_id: RepositoryId,
root: Configuration) -> None:
@@ -151,10 +130,12 @@ class Setup(Handler):
"""
configuration = Configuration()
section = Configuration.section_name("build", repository_id.name, repository_id.architecture)
build_command = Setup.build_command(root.repository_paths.root, repository_id)
configuration.set_option(section, "build_command", str(build_command))
configuration.set_option("repository", "name", repository_id.name) # backward compatibility for docker
section = Configuration.section_name("build", repository_id.name, repository_id.architecture)
configuration.set_option(section, "packager", args.packager)
if args.makeflags_jobs:
configuration.set_option(section, "make_flags", f"-j{multiprocessing.cpu_count()}")
if args.build_as_user is not None:
configuration.set_option(section, "makechrootpkg_flags", f"-U {args.build_as_user}")
@@ -183,8 +164,9 @@ class Setup(Handler):
if args.generate_salt:
configuration.set_option("auth", "salt", User.generate_password(20))
(root.include / "00-setup-overrides.ini").unlink(missing_ok=True) # remove old-style configuration
target = root.include / f"00-setup-overrides-{repository_id.id}.ini"
include_path = next(path for path in root.getpathlist("settings", "include") if os.access(path, os.W_OK))
(include_path / "00-setup-overrides.ini").unlink(missing_ok=True) # remove old-style configuration
target = include_path / f"00-setup-overrides-{repository_id.id}.ini"
with target.open("w", encoding="utf8") as ahriman_configuration:
configuration.write(ahriman_configuration)
@@ -238,50 +220,4 @@ class Setup(Handler):
with target.open("w", encoding="utf8") as devtools_configuration:
configuration.write(devtools_configuration)
@staticmethod
def configuration_create_makepkg(packager: str, makeflags_jobs: bool, paths: RepositoryPaths) -> None:
"""
create configuration for makepkg
Args:
packager(str): packager identifier (e.g. name, email)
makeflags_jobs(bool): set MAKEFLAGS variable to number of cores
paths(RepositoryPaths): repository paths instance
"""
content = f"PACKAGER='{packager}'\n"
if makeflags_jobs:
content += "MAKEFLAGS=\"-j$(nproc)\"\n"
uid, _ = paths.root_owner
home_dir = Path(getpwuid(uid).pw_dir)
(home_dir / ".makepkg.conf").write_text(content, encoding="utf8")
@staticmethod
def configuration_create_sudo(paths: RepositoryPaths, repository_id: RepositoryId) -> None:
"""
create configuration to run build command with sudo without password
Args:
paths(RepositoryPaths): repository paths instance
repository_id(RepositoryId): repository unique identifier
"""
command = Setup.build_command(paths.root, repository_id)
sudoers_file = Setup.build_command(Setup.SUDOERS_DIR_PATH, repository_id)
sudoers_file.write_text(f"ahriman ALL=(ALL) NOPASSWD:SETENV: {command} *\n", encoding="utf8")
sudoers_file.chmod(0o400) # security!
@staticmethod
def executable_create(paths: RepositoryPaths, repository_id: RepositoryId) -> None:
"""
create executable for the service
Args:
paths(RepositoryPaths): repository paths instance
repository_id(RepositoryId): repository unique identifier
"""
command = Setup.build_command(paths.root, repository_id)
command.unlink(missing_ok=True)
command.symlink_to(Setup.ARCHBUILD_COMMAND_PATH)
arguments = [_set_service_setup_parser]
@@ -56,7 +56,7 @@ class PackageVersion(LazyLogging):
_, repository_id = configuration.check_loaded()
paths = configuration.repository_paths
task = Task(self.package, configuration, repository_id.architecture, paths)
task = Task(self.package, configuration, repository_id, paths)
try:
# create fresh chroot environment, fetch sources and - automagically - update PKGBUILD
@@ -27,6 +27,7 @@ from ahriman.core.log import LazyLogging
from ahriman.core.utils import check_output, package_like
from ahriman.models.package import Package
from ahriman.models.pkgbuild_patch import PkgbuildPatch
from ahriman.models.repository_id import RepositoryId
from ahriman.models.repository_paths import RepositoryPaths
@@ -36,33 +37,38 @@ class Task(LazyLogging):
Attributes:
archbuild_flags(list[str]): command flags for archbuild command
architecture(str): repository architecture
build_command(str): build command
build_command(list[str]): build command
include_debug_packages(bool): whether to include debug packages or not
make_flags(str): MAKEFLAGS variable for makepkg command
makechrootpkg_flags(list[str]): command flags for makechrootpkg command
makepkg_flags(list[str]): command flags for makepkg command
package(Package): package definitions
paths(RepositoryPaths): repository paths instance
repository_id(RepositoryId): repository unique identifier
uid(int): uid of the repository owner user
"""
def __init__(self, package: Package, configuration: Configuration, architecture: str,
def __init__(self, package: Package, configuration: Configuration, repository_id: RepositoryId,
paths: RepositoryPaths) -> None:
"""
Args:
package(Package): package definitions
configuration(Configuration): configuration instance
architecture(str): repository architecture
repository_id(RepositoryId): repository unique identifier
paths(RepositoryPaths): repository paths instance
"""
self.package = package
self.paths = paths
self.uid, _ = paths.root_owner
self.architecture = architecture
self.repository_id = repository_id
self.archbuild_flags = configuration.getlist("build", "archbuild_flags", fallback=[])
self.build_command = configuration.get("build", "build_command")
self.build_command = configuration.getlist("build", "devtools_wrapper")
self._legacy_build_command = configuration.getlist("build", "build_command", fallback=[])
self.include_debug_packages = configuration.getboolean("build", "include_debug_packages", fallback=True)
# even though this option is declared as list, there is no need to read it as list,
# because it will be converted back to the string anyway
self.make_flags = configuration.get("build", "make_flags", fallback=None)
self.makepkg_flags = configuration.getlist("build", "makepkg_flags", fallback=[])
self.makechrootpkg_flags = configuration.getlist("build", "makechrootpkg_flags", fallback=[])
@@ -108,12 +114,16 @@ class Task(LazyLogging):
Returns:
list[Path]: paths of produced packages
"""
command = [self.build_command, "-r", str(self.paths.chroot)]
command.extend(self.archbuild_flags)
command.extend(["--", "-D", str(self.paths.archive)] + self.makechrootpkg_flags)
command.extend(["--"] + self.makepkg_flags)
command = self._legacy_build_command[:]
if not command:
command = self.build_command + ["-r", self.repository_id.name, "-a", self.repository_id.architecture, "--"]
command.extend(["-r", str(self.paths.chroot)] + self.archbuild_flags) # archbuild flags
command.extend(["--", "-D", str(self.paths.archive)] + self.makechrootpkg_flags) # makechrootpkg flags
command.extend(["--"] + self.makepkg_flags) # makepkg flags
if dry_run:
command.extend(["--nobuild"])
self.logger.info("using %s for %s", command, self.package.base)
environment: dict[str, str] = {
@@ -121,6 +131,8 @@ class Task(LazyLogging):
for key, value in kwargs.items()
if value is not None
}
if self.make_flags is not None:
environment["MAKEFLAGS"] = self.make_flags
self.logger.info("using environment variables %s", environment)
source_files = list(sources_dir.iterdir())
@@ -156,7 +168,7 @@ class Task(LazyLogging):
return last_commit_sha
# load fresh package
loaded_package = Package.from_build(sources_dir, self.architecture, None)
loaded_package = Package.from_build(sources_dir, self.repository_id.architecture, None)
if (pkgrel := loaded_package.next_pkgrel(local_version)) is not None:
self.logger.info("package %s is the same as in repo, bumping pkgrel to %s", self.package.base, pkgrel)
patch = PkgbuildPatch("pkgrel", pkgrel)
@@ -108,16 +108,6 @@ class Configuration(configparser.RawConfigParser):
_, repository_id = self.check_loaded()
return repository_id.architecture
@property
def include(self) -> Path:
"""
get full path to include directory
Returns:
Path: path to directory with configuration includes
"""
return self.getpath("settings", "include")
@property
def logging_path(self) -> Path:
"""
@@ -325,25 +315,35 @@ class Configuration(configparser.RawConfigParser):
section, key = name.rsplit(":", maxsplit=1)
self.set_option(section, key, value)
def load_includes(self, path: Path | None = None) -> None:
def load_includes(self) -> None:
"""
load configuration includes from specified path
Args:
path(Path | None, optional): path to directory with include files. If none set, the default path will be
used (Default value = None)
"""
self.includes = [] # reset state
try:
path = path or self.include
# raw processing to make sure that options are applied correctly
include_directories = shlex.split(self.get("settings", "include", raw=True))
except (configparser.NoOptionError, configparser.NoSectionError):
return
for directory in include_directories:
value = self._interpolation.before_get( # type: ignore[attr-defined]
self,
"settings",
"include",
directory,
self._unify_values("settings", None), # type: ignore[attr-defined]
)
path = self._convert_path(value)
if not path.is_dir():
continue
for include in sorted(path.glob("*.ini")):
if include == self.logging_path:
continue # we don't want to load logging explicitly
self.read(include)
self.includes.append(include)
except (FileNotFoundError, configparser.NoOptionError, configparser.NoSectionError):
pass
def merge_sections(self, repository_id: RepositoryId) -> None:
"""
@@ -403,6 +403,7 @@ class Configuration(configparser.RawConfigParser):
# create another instance and copy values from there
instance = self.from_path(path, repository_id)
self.copy_from(instance)
self.includes = instance.includes
def set_option(self, section: str, option: str, value: str) -> None:
"""
@@ -40,10 +40,13 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
"required": True,
},
"include": {
"type": "path",
"coerce": "absolute_path",
"path_exists": True,
"path_type": "dir",
"type": "list",
"coerce": "list",
"schema": {
"type": "path",
"coerce": "absolute_path",
"path_type": "dir",
},
},
"logging": {
"type": "path",
@@ -190,8 +193,20 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
},
},
"build_command": {
"type": "string",
"required": True,
"type": "list",
"coerce": "list",
"schema": {
"type": "string",
"empty": False,
},
},
"devtools_wrapper": {
"type": "list",
"coerce": "list",
"schema": {
"type": "string",
"empty": False,
},
"empty": False,
},
"ignore_packages": {
@@ -206,6 +221,14 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
"type": "boolean",
"coerce": "boolean",
},
"make_flags": {
"type": "list",
"coerce": "list",
"schema": {
"type": "string",
"empty": False,
},
},
"makechrootpkg_flags": {
"type": "list",
"coerce": "list",
@@ -214,18 +237,22 @@ CONFIGURATION_SCHEMA: ConfigurationSchema = {
"empty": False,
},
},
"makepkg_flags": {
"type": "list",
"coerce": "list",
"schema": {
"type": "string",
"empty": False,
},
},
"min_age": {
"type": "integer",
"coerce": "integer",
"min": 0,
},
"makepkg_flags": {
"type": "list",
"coerce": "list",
"schema": {
"type": "string",
"empty": False,
},
"packager": {
"type": "string",
"empty": False,
},
"scan_paths": {
"type": "list",
@@ -190,5 +190,5 @@ class Validator(RootValidator):
{"type": "string"}
"""
fn = getattr(value, f"is_{constraint}")
if not fn():
if value.exists() and not fn():
self._error(field, f"Path {value} must be type of {constraint}")
@@ -21,6 +21,8 @@
from logging import NullHandler
from typing import Any
from ahriman.core.module_loader import optional_module
__all__ = ["JournalHandler"]
@@ -40,7 +42,5 @@ class _JournalHandler(NullHandler):
del args, kwargs
try:
from systemd.journal import JournalHandler # type: ignore[import-untyped]
except ImportError:
JournalHandler = _JournalHandler
systemd_journal = optional_module("systemd.journal")
JournalHandler = systemd_journal.JournalHandler if systemd_journal else _JournalHandler
@@ -26,6 +26,7 @@ from typing import ClassVar, Literal
from ahriman.core.configuration import Configuration
from ahriman.core.log.http_log_handler import HttpLogHandler
from ahriman.core.log.log_context import LogContext
from ahriman.core.module_loader import optional_module
from ahriman.models.log_handler import LogHandler
from ahriman.models.repository_id import RepositoryId
@@ -65,14 +66,11 @@ class LogLoader:
if selected is not None:
return selected
try:
from systemd.journal import JournalHandler # type: ignore[import-untyped]
del JournalHandler
if optional_module("systemd.journal"):
return LogHandler.Journald # journald import was found
except ImportError:
if LogLoader.DEFAULT_SYSLOG_DEVICE.exists():
return LogHandler.Syslog
return LogHandler.Console
if LogLoader.DEFAULT_SYSLOG_DEVICE.exists():
return LogHandler.Syslog
return LogHandler.Console
@staticmethod
def load(repository_id: RepositoryId, configuration: Configuration, handler: LogHandler, *,
+17 -2
View File
@@ -26,8 +26,7 @@ from pkgutil import ModuleInfo, walk_packages
from types import ModuleType
from typing import Any, TypeGuard, TypeVar
__all__ = ["implementations"]
__all__ = ["implementations", "optional_module"]
T = TypeVar("T")
@@ -74,3 +73,19 @@ def implementations(root_module: ModuleType, base_class: type[T]) -> Iterator[ty
for _, attribute in inspect.getmembers(module, is_base_class):
yield attribute
def optional_module(module_name: str) -> ModuleType | None:
"""
import an optional module
Args:
module_name(str): fully qualified module name
Returns:
ModuleType | None: imported module or ``None`` when it cannot be imported
"""
try:
return import_module(module_name)
except ImportError:
return None
@@ -73,7 +73,8 @@ class Executor(PackageInfo, Cleaner):
"""
self.reporter.set_building(package.base)
task = Task(package, self.configuration, self.repository_id.architecture, self.paths)
default_packager = self.configuration.get("build", "packager", fallback=None)
task = Task(package, self.configuration, self.repository_id, self.paths)
patches = self.reporter.package_patches_get(package.base, None)
commit_sha = task.init(path, patches, local_version)
@@ -86,7 +87,7 @@ class Executor(PackageInfo, Cleaner):
shutil.copy(artifact, path)
built.append(path / artifact.name)
else:
built = task.build(path, PACKAGER=packager)
built = task.build(path, PACKAGER=packager or default_packager)
package.with_packages(built)
for src in built:
@@ -1,4 +1,5 @@
import argparse
import multiprocessing
import pytest
from pathlib import Path
@@ -54,9 +55,6 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
ahriman_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_ahriman")
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_devtools")
makepkg_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
sudo_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
executable_mock = mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
init_mock = mocker.patch("ahriman.core.alpm.repo.Repo.init")
owner_guard_mock = mocker.patch("ahriman.models.repository_paths.RepositoryPaths.preserve_owner")
@@ -66,9 +64,6 @@ def test_run(args: argparse.Namespace, configuration: Configuration, repository:
ahriman_configuration_mock.assert_called_once_with(args, repository_id, configuration)
devtools_configuration_mock.assert_called_once_with(
repository_id, args.from_configuration, args.mirror, args.multilib, f"file://{repository_paths.repository}")
makepkg_configuration_mock.assert_called_once_with(args.packager, args.makeflags_jobs, repository_paths)
sudo_configuration_mock.assert_called_once_with(repository_paths, repository_id)
executable_mock.assert_called_once_with(repository_paths, repository_id)
init_mock.assert_called_once_with()
@@ -101,9 +96,6 @@ def test_run_with_server(args: argparse.Namespace, configuration: Configuration,
mocker.patch("ahriman.core.database.SQLite.load", return_value=database)
mocker.patch("ahriman.core.repository.Repository.load", return_value=repository)
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_ahriman")
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_makepkg")
mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_sudo")
mocker.patch("ahriman.application.handlers.setup.Setup.executable_create")
mocker.patch("ahriman.core.alpm.repo.Repo.init")
devtools_configuration_mock = mocker.patch("ahriman.application.handlers.setup.Setup.configuration_create_devtools")
@@ -113,17 +105,6 @@ def test_run_with_server(args: argparse.Namespace, configuration: Configuration,
repository_id, args.from_configuration, args.mirror, args.multilib, "server")
def test_build_command(repository_id: RepositoryId) -> None:
"""
must generate correct build command name
"""
path = Path("local")
build_command = Setup.build_command(path, repository_id)
assert build_command.name == f"{repository_id.name}-{repository_id.architecture}-build"
assert build_command.parent == path
def test_configuration_create_ahriman(args: argparse.Namespace, configuration: Configuration,
repository_paths: RepositoryPaths, mocker: MockerFixture) -> None:
"""
@@ -135,21 +116,22 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C
write_mock = mocker.patch("ahriman.core.configuration.Configuration.write")
remove_mock = mocker.patch("pathlib.Path.unlink", autospec=True)
_, repository_id = configuration.check_loaded()
command = Setup.build_command(repository_paths.root, repository_id)
Setup.configuration_create_ahriman(args, repository_id, configuration)
set_option_mock.assert_has_calls([
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture), "build_command",
str(command)),
MockCall("repository", "name", repository_id.name),
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture),
"packager", args.packager),
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture),
"make_flags", f"-j{multiprocessing.cpu_count()}"),
MockCall(Configuration.section_name("build", repository_id.name, repository_id.architecture),
"makechrootpkg_flags", f"-U {args.build_as_user}"),
MockCall(Configuration.section_name(
"alpm", repository_id.name, repository_id.architecture), "mirror", args.mirror),
MockCall(Configuration.section_name("sign", repository_id.name, repository_id.architecture), "target",
" ".join([target.name.lower() for target in args.sign_target])),
MockCall(Configuration.section_name("sign", repository_id.name, repository_id.architecture), "key",
args.sign_key),
MockCall(Configuration.section_name("alpm", repository_id.name, repository_id.architecture),
"mirror", args.mirror),
MockCall(Configuration.section_name("sign", repository_id.name, repository_id.architecture),
"target", " ".join([target.name.lower() for target in args.sign_target])),
MockCall(Configuration.section_name("sign", repository_id.name, repository_id.architecture),
"key", args.sign_key),
MockCall("web", "port", str(args.web_port)),
MockCall("status", "address", f"http://127.0.0.1:{str(args.web_port)}"),
MockCall("web", "unix_socket", str(args.web_unix_socket)),
@@ -157,7 +139,11 @@ def test_configuration_create_ahriman(args: argparse.Namespace, configuration: C
MockCall("auth", "salt", pytest.helpers.anyvar(str, strict=True)),
])
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
remove_mock.assert_called_once_with(configuration.include / "00-setup-overrides.ini", missing_ok=True)
remove_mock.assert_called_once_with(
next(
path for path in configuration.getpathlist("settings", "include")) /
"00-setup-overrides.ini",
missing_ok=True)
def test_configuration_create_ahriman_no_multilib(args: argparse.Namespace, configuration: Configuration,
@@ -237,48 +223,6 @@ def test_configuration_create_devtools_no_multilib(args: argparse.Namespace, con
write_mock.assert_called_once_with(pytest.helpers.anyvar(int))
def test_configuration_create_makepkg(args: argparse.Namespace, repository_paths: RepositoryPaths,
passwd: Any, mocker: MockerFixture) -> None:
"""
must create makepkg configuration
"""
args = _default_args(args)
mocker.patch("ahriman.application.handlers.setup.getpwuid", return_value=passwd)
write_text_mock = mocker.patch("pathlib.Path.write_text", autospec=True)
Setup.configuration_create_makepkg(args.packager, args.makeflags_jobs, repository_paths)
write_text_mock.assert_called_once_with(
Path("home") / ".makepkg.conf", pytest.helpers.anyvar(str, True), encoding="utf8")
def test_configuration_create_sudo(configuration: Configuration, repository_paths: RepositoryPaths,
mocker: MockerFixture) -> None:
"""
must create sudo configuration
"""
chmod_text_mock = mocker.patch("pathlib.Path.chmod")
write_text_mock = mocker.patch("pathlib.Path.write_text")
_, repository_id = configuration.check_loaded()
Setup.configuration_create_sudo(repository_paths, repository_id)
chmod_text_mock.assert_called_once_with(0o400)
write_text_mock.assert_called_once_with(pytest.helpers.anyvar(str, True), encoding="utf8")
def test_executable_create(configuration: Configuration, repository_paths: RepositoryPaths,
mocker: MockerFixture) -> None:
"""
must create executable
"""
symlink_mock = mocker.patch("pathlib.Path.symlink_to")
unlink_mock = mocker.patch("pathlib.Path.unlink")
_, repository_id = configuration.check_loaded()
Setup.executable_create(repository_paths, repository_id)
symlink_mock.assert_called_once_with(Setup.ARCHBUILD_COMMAND_PATH)
unlink_mock.assert_called_once_with(missing_ok=True)
def test_disallow_multi_architecture_run() -> None:
"""
must not allow multi architecture run
@@ -63,7 +63,7 @@ def test_run_default(args: argparse.Namespace, configuration: Configuration) ->
default = Configuration.from_path(Configuration.SYSTEM_CONFIGURATION_PATH, repository_id)
# copy autogenerated values
for section, key in (("build", "build_command"), ("repository", "root")):
for section, key in (("repository", "root"),):
value = configuration.get(section, key)
default.set_option(section, key, value)
@@ -53,8 +53,9 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None:
assert task_ahriman.build(local) == [task_ahriman.package.base]
check_output_mock.assert_called_once_with(
"extra-x86_64-build",
"-r", str(task_ahriman.paths.chroot),
"ahriman-archbuild",
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
"--", "-r", str(task_ahriman.paths.chroot),
"--", "-D", str(task_ahriman.paths.archive),
"--", "--skippgpcheck",
exception=pytest.helpers.anyvar(int),
@@ -79,8 +80,9 @@ def test_build_environment(task_ahriman: Task, mocker: MockerFixture) -> None:
task_ahriman.build(local, **environment, empty=None)
check_output_mock.assert_called_once_with(
"extra-x86_64-build",
"-r", str(task_ahriman.paths.chroot),
"ahriman-archbuild",
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
"--", "-r", str(task_ahriman.paths.chroot),
"--", "-D", str(task_ahriman.paths.archive),
"--", "--skippgpcheck",
exception=pytest.helpers.anyvar(int),
@@ -91,6 +93,31 @@ def test_build_environment(task_ahriman: Task, mocker: MockerFixture) -> None:
)
def test_build_makeflags(task_ahriman: Task, mocker: MockerFixture) -> None:
"""
must build package with MAKEFLAGS variable if set
"""
local = Path("local")
mocker.patch("pathlib.Path.iterdir", return_value=["file"])
mocker.patch("ahriman.core.build_tools.task.Task._package_archives", return_value=[task_ahriman.package.base])
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
task_ahriman.make_flags = "-j1"
task_ahriman.build(local)
check_output_mock.assert_called_once_with(
"ahriman-archbuild",
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
"--", "-r", str(task_ahriman.paths.chroot),
"--", "-D", str(task_ahriman.paths.archive),
"--", "--skippgpcheck",
exception=pytest.helpers.anyvar(int),
cwd=local,
logger=task_ahriman.logger,
user=task_ahriman.uid,
environment={"MAKEFLAGS": "-j1"},
)
def test_build_dry_run(task_ahriman: Task, mocker: MockerFixture) -> None:
"""
must run devtools in dry-run mode
@@ -100,13 +127,38 @@ def test_build_dry_run(task_ahriman: Task, mocker: MockerFixture) -> None:
mocker.patch("ahriman.core.build_tools.task.Task._package_archives", return_value=[task_ahriman.package.base])
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
assert task_ahriman.build(local, dry_run=True) == [task_ahriman.package.base]
task_ahriman.build(local, dry_run=True)
check_output_mock.assert_called_once_with(
"ahriman-archbuild",
"-r", task_ahriman.repository_id.name, "-a", task_ahriman.repository_id.architecture,
"--", "-r", str(task_ahriman.paths.chroot),
"--", "-D", str(task_ahriman.paths.archive),
"--", "--skippgpcheck",
"--nobuild",
exception=pytest.helpers.anyvar(int),
cwd=local,
logger=task_ahriman.logger,
user=task_ahriman.uid,
environment={},
)
def test_build_legacy_subcommand(task_ahriman: Task, mocker: MockerFixture) -> None:
"""
must build package by using legacy subcommand if set
"""
local = Path("local")
mocker.patch("pathlib.Path.iterdir", return_value=["file"])
mocker.patch("ahriman.core.build_tools.task.Task._package_archives", return_value=[task_ahriman.package.base])
check_output_mock = mocker.patch("ahriman.core.build_tools.task.check_output")
task_ahriman._legacy_build_command = ["extra-x86_64-build"]
task_ahriman.build(local)
check_output_mock.assert_called_once_with(
"extra-x86_64-build",
"-r", str(task_ahriman.paths.chroot),
"--", "-D", str(task_ahriman.paths.archive),
"--", "--skippgpcheck",
"--nobuild",
exception=pytest.helpers.anyvar(int),
cwd=local,
logger=task_ahriman.logger,
@@ -374,17 +374,16 @@ def test_load_environment(configuration: Configuration) -> None:
assert configuration.get("section:identifier", "key") == "value2"
def test_load_includes(mocker: MockerFixture) -> None:
def test_load_includes(configuration: Configuration, mocker: MockerFixture) -> None:
"""
must load includes
"""
mocker.patch.object(Configuration, "logging_path", Path("logging"))
read_mock = mocker.patch("ahriman.core.configuration.Configuration.read")
glob_mock = mocker.patch("pathlib.Path.glob", autospec=True, return_value=[Path("include"), Path("logging")])
configuration = Configuration()
configuration.load_includes(Path("path"))
glob_mock.assert_called_once_with(Path("path"), "*.ini")
configuration.load_includes()
glob_mock.assert_called_once_with(configuration.path.absolute().parent, "*.ini")
read_mock.assert_called_once_with(Path("include"))
assert configuration.includes == [Path("include")]
@@ -415,17 +414,6 @@ def test_load_includes_no_section() -> None:
configuration.load_includes()
def test_load_includes_default_path(mocker: MockerFixture) -> None:
"""
must load includes from default path
"""
mocker.patch.object(Configuration, "include", Path("path"))
glob_mock = mocker.patch("pathlib.Path.glob", autospec=True, return_value=[])
Configuration().load_includes()
glob_mock.assert_called_once_with(Path("path"), "*.ini")
def test_merge_sections_missing(configuration: Configuration) -> None:
"""
must merge create section if not exists
@@ -134,6 +134,10 @@ def test_validate_path_type(validator: Validator, mocker: MockerFixture) -> None
"""
error_mock = mocker.patch("ahriman.core.configuration.validator.Validator._error")
validator._validate_path_type("file", "field", Path("42"))
mocker.patch("pathlib.Path.exists", return_value=True)
mocker.patch("pathlib.Path.is_file", return_value=True)
validator._validate_path_type("file", "field", Path("1"))
+2 -1
View File
@@ -76,4 +76,5 @@ def task_ahriman(package_ahriman: Package, configuration: Configuration, reposit
Returns:
Task: built task test instance
"""
return Task(package_ahriman, configuration, "x86_64", repository_paths)
_, repository_id = configuration.check_loaded()
return Task(package_ahriman, configuration, repository_id, repository_paths)
@@ -2,7 +2,7 @@ import ahriman.web.views
from pathlib import Path
from ahriman.core.module_loader import _modules, implementations
from ahriman.core.module_loader import _modules, implementations, optional_module
from ahriman.web.views.base import BaseView
@@ -23,3 +23,17 @@ def test_implementations() -> None:
assert routes
assert all(isinstance(view, type) for view in routes)
assert all(issubclass(view, BaseView) for view in routes)
def test_optional_module() -> None:
"""
must import an available module
"""
assert optional_module("ahriman.web.views") is ahriman.web.views
def test_optional_module_fallback() -> None:
"""
must return none when the module cannot be imported
"""
assert optional_module("missing_ahriman_module") is None
+11 -15
View File
@@ -17,18 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
try:
import aiohttp_security
except ImportError:
aiohttp_security = None # type: ignore[assignment]
try:
import aiohttp_session
except ImportError:
aiohttp_session = None # type: ignore[assignment]
from typing import Any
from ahriman.core.module_loader import optional_module
__all__ = [
"authorized_userid",
@@ -39,6 +31,10 @@ __all__ = [
]
aiohttp_security = optional_module("aiohttp_security")
aiohttp_session = optional_module("aiohttp_session")
async def authorized_userid(*args: Any, **kwargs: Any) -> Any:
"""
handle aiohttp security methods
@@ -50,7 +46,7 @@ async def authorized_userid(*args: Any, **kwargs: Any) -> Any:
Returns:
Any: ``None`` in case if no aiohttp_security module found and function call otherwise
"""
if aiohttp_security is not None:
if aiohttp_security:
return await aiohttp_security.authorized_userid(*args, **kwargs) # pylint: disable=no-value-for-parameter
return None
@@ -66,7 +62,7 @@ async def check_authorized(*args: Any, **kwargs: Any) -> Any:
Returns:
Any: ``None`` in case if no aiohttp_security module found and function call otherwise
"""
if aiohttp_security is not None:
if aiohttp_security:
return await aiohttp_security.check_authorized(*args, **kwargs) # pylint: disable=no-value-for-parameter
return None
@@ -82,7 +78,7 @@ async def forget(*args: Any, **kwargs: Any) -> Any:
Returns:
Any: ``None`` in case if no aiohttp_security module found and function call otherwise
"""
if aiohttp_security is not None:
if aiohttp_security:
return await aiohttp_security.forget(*args, **kwargs) # pylint: disable=no-value-for-parameter
return None
@@ -98,7 +94,7 @@ async def get_session(*args: Any, **kwargs: Any) -> Any:
Returns:
Any: empty dictionary in case if no aiohttp_session module found and function call otherwise
"""
if aiohttp_session is not None:
if aiohttp_session:
return await aiohttp_session.get_session(*args, **kwargs)
return {}
@@ -114,6 +110,6 @@ async def remember(*args: Any, **kwargs: Any) -> Any:
Returns:
Any: ``None`` in case if no aiohttp_security module found and function call otherwise
"""
if aiohttp_security is not None:
if aiohttp_security:
return await aiohttp_security.remember(*args, **kwargs) # pylint: disable=no-value-for-parameter
return None
@@ -17,15 +17,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
try:
import aiohttp_apispec # type: ignore[import-untyped]
from ahriman.core.module_loader import optional_module
from marshmallow import Schema, fields
except ImportError:
aiohttp_apispec = optional_module("aiohttp_apispec")
marshmallow = optional_module("marshmallow")
if aiohttp_apispec and marshmallow:
Schema = marshmallow.Schema
fields = marshmallow.fields
else:
from unittest.mock import Mock
Schema = Mock # type: ignore[misc]
aiohttp_apispec = None
fields = Mock()
@@ -115,7 +115,7 @@ def apidocs(*,
authorization_required = permission != UserAccess.Unauthorized
def wrapper(handler: Callable[..., Any]) -> Callable[..., Any]:
if aiohttp_apispec is None:
if not aiohttp_apispec:
return handler # apispec is disabled
responses = _response_schema(
+3 -6
View File
@@ -100,20 +100,17 @@ def _servers(application: Application) -> list[dict[str, Any]]:
}]
def setup_apispec(application: Application) -> Any:
def setup_apispec(application: Application) -> None:
"""
setup swagger api specification
Args:
application(Application): web application instance
Returns:
Any: created specification instance if module is available
"""
if aiohttp_apispec is None:
return None
return
return aiohttp_apispec.setup_aiohttp_apispec(
aiohttp_apispec.setup_aiohttp_apispec(
application,
url="/api-docs/swagger.json",
openapi_version="3.0.2",
@@ -17,14 +17,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
try:
import aiohttp_openmetrics
except ImportError:
aiohttp_openmetrics = None # type: ignore[assignment]
from aiohttp.typedefs import Middleware
from aiohttp.web import HTTPNotFound, Request, Response, StreamResponse, middleware
from ahriman.core.module_loader import optional_module
from ahriman.web.middlewares import HandlerType
@@ -34,6 +30,9 @@ __all__ = [
]
aiohttp_openmetrics = optional_module("aiohttp_openmetrics")
async def metrics(request: Request) -> Response:
"""
handler for returning metrics
@@ -47,7 +46,7 @@ async def metrics(request: Request) -> Response:
Raises:
HTTPNotFound: endpoint is disabled
"""
if aiohttp_openmetrics is None:
if not aiohttp_openmetrics:
raise HTTPNotFound
return await aiohttp_openmetrics.metrics(request)
@@ -59,7 +58,7 @@ def metrics_handler() -> Middleware:
Returns:
Middleware: middleware function to handle server metrics
"""
if aiohttp_openmetrics is not None:
if aiohttp_openmetrics:
return aiohttp_openmetrics.metrics_middleware
@middleware
+1 -1
View File
@@ -60,7 +60,7 @@ async def server_info(view: BaseView) -> dict[str, Any]:
"username": await authorized_userid(view.request),
},
"autorefresh_intervals": sorted(autorefresh_intervals, key=comparator),
"docs_enabled": aiohttp_apispec is not None,
"docs_enabled": bool(aiohttp_apispec),
"index_url": view.configuration.get("web", "index_url", fallback=None),
"repositories": [
{
@@ -50,7 +50,7 @@ class DocsView(BaseView):
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
and returns empty list otherwise
"""
if aiohttp_apispec is None:
if not aiohttp_apispec:
return []
return cls.ROUTES
@@ -51,7 +51,7 @@ class SwaggerView(BaseView):
list[str]: list of routes defined for the view. By default, it tries to read :attr:`ROUTES` option if set
and returns empty list otherwise
"""
if aiohttp_apispec is None:
if not aiohttp_apispec:
return []
return cls.ROUTES
@@ -22,6 +22,7 @@ from secrets import token_urlsafe
from typing import ClassVar
from ahriman.core.auth.helpers import get_session, remember
from ahriman.core.module_loader import optional_module
from ahriman.models.user_access import UserAccess
from ahriman.web.apispec.decorators import apidocs
from ahriman.web.schemas import LoginSchema, OAuth2Schema
@@ -62,14 +63,12 @@ class LoginView(BaseView):
HTTPMethodNotAllowed: in case if method is used, but OAuth is disabled
HTTPUnauthorized: if case of authorization error
"""
try:
from ahriman.core.auth.oauth import OAuth
except ImportError:
# no aioauth library found
oauth = optional_module("ahriman.core.auth.oauth")
if not oauth:
raise HTTPMethodNotAllowed(self.request.method, ["POST"])
oauth_provider = self.validator
if not isinstance(oauth_provider, OAuth):
if not isinstance(oauth_provider, oauth.OAuth):
raise HTTPMethodNotAllowed(self.request.method, ["POST"])
session = await get_session(self.request)
@@ -48,7 +48,8 @@ def test_setup_apispec(application: Application, mocker: MockerFixture) -> None:
must set api specification
"""
apispec_mock = mocker.patch("aiohttp_apispec.setup_aiohttp_apispec")
assert setup_apispec(application)
setup_apispec(application)
apispec_mock.assert_called_once_with(
application,
url="/api-docs/swagger.json",
@@ -37,7 +37,7 @@ async def test_get_import_error(client_with_auth: TestClient, mocker: MockerFixt
"""
must return 405 on import error
"""
pytest.helpers.import_error("ahriman.core.auth.oauth", ["OAuth"], mocker)
mocker.patch("ahriman.web.views.v1.user.login.optional_module", return_value=None)
response = await client_with_auth.get("/api/v1/login")
assert response.status == 405
+5 -2
View File
@@ -2,7 +2,7 @@
pkgbase='ahriman'
pkgname=('ahriman' 'ahriman-core' 'ahriman-triggers' 'ahriman-web')
pkgver=2.21.0
pkgver=2.21.1
pkgrel=1
pkgdesc="ArcH linux ReposItory MANager"
arch=('any')
@@ -12,7 +12,8 @@ depends=('devtools>=1:1.0.0' 'git' 'pyalpm' 'python-bcrypt' 'python-filelock' 'p
makedepends=('npm' 'python-build' 'python-hatchling' 'python-installer' 'python-wheel')
source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgbase-$pkgver.tar.gz"
"$pkgbase.sysusers"
"$pkgbase.tmpfiles")
"$pkgbase.tmpfiles"
"sudoers.conf")
build() {
cd "$pkgbase-$pkgver"
@@ -59,6 +60,8 @@ package_ahriman-core() {
install -Dm644 "$srcdir/$pkgbase.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgbase.conf"
install -Dm644 "$srcdir/$pkgbase.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgbase.conf"
install -Dm440 "$srcdir/sudoers.conf" "$pkgdir/etc/sudoers.d/$pkgname"
}
package_ahriman-triggers() {
+1
View File
@@ -0,0 +1 @@
ahriman ALL= NOPASSWD:SETENV: /usr/bin/ahriman-archbuild *
+5 -3
View File
@@ -82,7 +82,7 @@ Base configuration settings.
* ``apply_migrations`` - perform database migrations on the application start, boolean, optional, default ``yes``. Useful if you are using git version. Note, however, that this option must be changed only if you know what to do and going to handle migrations manually.
* ``database`` - path to the application SQLite database, string, required.
* ``include`` - path to directory with configuration files overrides, string, optional. Files will be read in alphabetical order.
* ``include`` - path to directories with configuration files overrides, space separated list of strings, optional. Files will be read in alphabetical order.
* ``logging`` - path to logging configuration, string, required. Check ``logging.ini`` for reference.
``alpm:*`` groups
@@ -131,12 +131,14 @@ Authorized users are stored inside internal database, if any of external provide
Build related configuration. Group name can refer to architecture, e.g. ``build:x86_64`` can be used for x86_64 architecture specific settings.
* ``archbuild_flags`` - additional flags passed to ``archbuild`` command, space separated list of strings, optional.
* ``build_command`` - default build command, string, required.
* ``devtools_wrapper`` - path to devtools wrapper, space separated list of strings, required.
* ``ignore_packages`` - list packages to ignore during a regular update (manual update will still work), space separated list of strings, optional.
* ``include_debug_packages`` - distribute debug packages, boolean, optional, default ``yes``.
* ``makepkg_flags`` - additional flags passed to ``makepkg`` command, space separated list of strings, optional.
* ``make_flags`` - additional flags passed to ``make`` command via environment variable, space separated list of strings, optional.
* ``makechrootpkg_flags`` - additional flags passed to ``makechrootpkg`` command, space separated list of strings, optional.
* ``makepkg_flags`` - additional flags passed to ``makepkg`` command, space separated list of strings, optional.
* ``min_age`` - minimal age in seconds since the latest AUR package modification before automatic updates are allowed, integer, optional, default ``0``.
* ``packager`` - default packager identifier in form ``Name Surname <mail@example.com>``, string, optional.
* ``scan_paths`` - paths to be used for implicit dependencies scan, space separated list of strings, optional. If any of those paths is matched against the path, it will be added to the allowed list.
* ``triggers`` - list of ``ahriman.core.triggers.Trigger`` class implementation (e.g. ``ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger``) which will be loaded and run at the end of processing, space separated list of strings, optional. You can also specify triggers by their paths, e.g. ``/usr/lib/python3.10/site-packages/ahriman/core/report/report.py.ReportTrigger``. Triggers are run in the order of definition.
* ``triggers_known`` - optional list of ``ahriman.core.triggers.Trigger`` class implementations which are not run automatically and used only for trigger discovery and configuration validation.
+12 -36
View File
@@ -27,48 +27,24 @@ Initial setup
#.
Configure build tools (it is required for correct dependency management system):
#.
Create build command (you can choose any name for command, basically it should be ``{name}-{arch}-build``):
#.
Create configuration file ``{name}.conf`` or ``{name}-{arch}.conf``, where ``name`` is the repostory name and ``arch`` is the repository architecture, e.g.:
.. code-block:: shell
.. code-block:: shell
ln -s /usr/bin/archbuild /usr/local/bin/aur-x86_64-build
cp /usr/share/devtools/pacman.conf.d/{extra,aur-x86_64}.conf
#.
Create configuration file (same as previous ``{name}.conf``):
#.
Change configuration file, add your own repository, add multilib repository etc:
.. code-block:: shell
.. code-block:: shell
cp /usr/share/devtools/pacman.conf.d/{extra,aur}.conf
echo '[multilib]' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'Include = /etc/pacman.d/mirrorlist' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
#.
Change configuration file, add your own repository, add multilib repository etc:
.. code-block:: shell
echo '[multilib]' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'Include = /etc/pacman.d/mirrorlist' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo '[aur]' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'SigLevel = Optional TrustAll' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'Server = file:///var/lib/ahriman/repository/$repo/$arch' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
#.
Set ``build_command`` option to point to your command:
.. code-block:: shell
echo '[build]' | tee -a /etc/ahriman.ini.d/build.ini
echo 'build_command = aur-x86_64-build' | tee -a /etc/ahriman.ini.d/build.ini
#.
Configure ``/etc/sudoers.d/ahriman`` to allow running command without a password:
.. code-block:: shell
echo 'Cmnd_Alias CARCHBUILD_CMD = /usr/local/bin/aur-x86_64-build *' | tee -a /etc/sudoers.d/ahriman
echo 'ahriman ALL=(ALL) NOPASSWD:SETENV: CARCHBUILD_CMD' | tee -a /etc/sudoers.d/ahriman
chmod 400 /etc/sudoers.d/ahriman
echo '[aur]' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'SigLevel = Optional TrustAll' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
echo 'Server = file:///var/lib/ahriman/repository/$repo/$arch' | tee -a /usr/share/devtools/pacman.conf.d/aur-x86_64.conf
This command supports several arguments, kindly refer to its help message.
+1 -1
View File
@@ -39,5 +39,5 @@
"preview": "vite preview"
},
"type": "module",
"version": "2.21.0"
"version": "2.21.1"
}
@@ -58,11 +58,7 @@ export default function PackageInfoDialog({
const { showSuccess, showError } = useNotification();
const queryClient = useQueryClient();
const [localPackageBase, setLocalPackageBase] = useState(packageBase);
if (packageBase !== null && packageBase !== localPackageBase) {
setLocalPackageBase(packageBase);
}
const localPackageBase = packageBase;
const [activeTab, setActiveTab] = useState<TabKey>("logs");
const [refreshDatabase, setRefreshDatabase] = useState(true);
@@ -157,38 +153,42 @@ export default function PackageInfoDialog({
<DialogContent>
{pkg &&
<>
<PackageDetailsGrid dependencies={dependencies} pkg={pkg} />
<PackagePatchesList
editable={isAuthorized}
onDelete={key => void handleDeletePatch(key)}
patches={patches}
/>
<PackageDetailsGrid dependencies={dependencies} pkg={pkg} />
}
{localPackageBase &&
<PackagePatchesList
editable={isAuthorized}
onDelete={key => void handleDeletePatch(key)}
patches={patches}
/>
}
{localPackageBase && currentRepository &&
<>
<Box sx={{ borderBottom: 1, borderColor: "divider", mt: 2 }}>
<Tabs onChange={(_, tab: TabKey) => setActiveTab(tab)} value={activeTab}>
{tabs.map(({ key, label }) => <Tab key={key} label={label} value={key} />)}
</Tabs>
</Box>
{activeTab === "logs" && localPackageBase && currentRepository &&
{activeTab === "logs" &&
<BuildLogsTab
packageBase={localPackageBase}
repository={currentRepository}
/>
}
{activeTab === "changes" && localPackageBase && currentRepository &&
{activeTab === "changes" &&
<ChangesTab packageBase={localPackageBase} repository={currentRepository} />
}
{activeTab === "pkgbuild" && localPackageBase && currentRepository &&
{activeTab === "pkgbuild" &&
<PkgbuildTab packageBase={localPackageBase} repository={currentRepository} />
}
{activeTab === "events" && localPackageBase && currentRepository &&
{activeTab === "events" &&
<EventsTab packageBase={localPackageBase} repository={currentRepository} />
}
{activeTab === "artifacts" && localPackageBase && currentRepository &&
{activeTab === "artifacts" &&
<ArtifactsTab
currentVersion={pkg.version}
currentVersion={pkg?.version}
packageBase={localPackageBase}
repository={currentRepository}
/>
@@ -32,7 +32,7 @@ import { useCallback, useMemo } from "react";
import { DETAIL_TABLE_PROPS } from "utils";
interface ArtifactsTabProps {
currentVersion: string;
currentVersion?: string;
packageBase: string;
repository: RepositoryId;
}
@@ -78,6 +78,7 @@ export default function ArtifactsTab({
})).reverse();
},
queryKey: QueryKeys.artifacts(packageBase, repository),
refetchOnMount: "always",
});
const handleRollback = useCallback(async (version: string): Promise<void> => {
@@ -101,7 +102,7 @@ export default function ArtifactsTab({
<Tooltip title={params.row.version === currentVersion ? "Current version" : "Rollback to this version"}>
<span>
<IconButton
disabled={params.row.version === currentVersion}
disabled={currentVersion === params.row.version}
onClick={() => void handleRollback(params.row.version)}
size="small"
>
@@ -61,6 +61,7 @@ export default function BuildLogsTab({
enabled: !!packageBase,
queryFn: () => client.fetch.fetchPackageLogs(packageBase, repository),
queryKey: QueryKeys.logs(packageBase, repository),
refetchOnMount: "always",
});
// Build version selectors from all logs
@@ -116,6 +117,7 @@ export default function BuildLogsTab({
)
: skipToken,
queryKey: QueryKeys.logsVersion(packageBase, repository, activeVersion?.version ?? "", activeVersion?.processId ?? ""),
refetchOnMount: "always",
});
// Derive displayed logs: prefer fresh polled data when available
@@ -54,6 +54,7 @@ export default function EventsTab({ packageBase, repository }: EventsTabProps):
enabled: !!packageBase,
queryFn: () => client.fetch.fetchPackageEvents(repository, packageBase, 30),
queryKey: QueryKeys.events(repository, packageBase),
refetchOnMount: "always",
});
const rows = useMemo<EventRow[]>(() => events.map((event, index) => ({
+1
View File
@@ -30,6 +30,7 @@ export function usePackageChanges(packageBase: string, repository: RepositoryId)
enabled: !!packageBase,
queryFn: () => client.fetch.fetchPackageChanges(packageBase, repository),
queryKey: QueryKeys.changes(packageBase, repository),
refetchOnMount: "always",
});
return data;
+1 -1
View File
@@ -23,7 +23,7 @@ allow_read_only = no
[build]
archbuild_flags =
build_command = extra-x86_64-build
devtools_wrapper = ahriman-archbuild
ignore_packages =
makechrootpkg_flags =
makepkg_flags = --skippgpcheck
+21 -1
View File
@@ -93,6 +93,21 @@ class ImportOrder(BaseRawFileChecker):
)
)
@staticmethod
def import_context(statement: nodes.Import | nodes.ImportFrom) -> tuple[nodes.NodeNG, str]:
"""
extract the lexical block containing an import
Args:
statement(nodes.Import | nodes.ImportFrom): import node
Returns:
tuple[nodes.NodeNG, str]: parent node and its branch containing the import
"""
parent = statement.parent
field, _ = parent.locate_child(statement)
return parent, field
@staticmethod
def imports(source: Iterable[Any], start_lineno: int = 0) -> Iterable[nodes.Import | nodes.ImportFrom]:
"""
@@ -192,7 +207,12 @@ class ImportOrder(BaseRawFileChecker):
node(nodes.Module): module node to check
"""
root_module, *_ = node.qname().split(".")
self.check_imports(self.imports(node.values()), root_module)
contexts: dict[tuple[nodes.NodeNG, str], list[nodes.Import | nodes.ImportFrom]] = {}
for statement in self.imports(node.values()):
contexts.setdefault(self.import_context(statement), []).append(statement)
for imports in contexts.values():
self.check_imports(imports, root_module)
def register(linter: PyLinter) -> None:
@@ -117,36 +117,12 @@ def get_package_status_extended(package: Package) -> dict[str, Any]:
return {"status": BuildStatus().view(), "package": package.view()}
def import_error(package: str, components: list[str], mocker: MockerFixture) -> MagicMock:
"""
mock import error
Args:
package(str): package name to import
components(list[str]): component to import if any (e.g. from ... import ...)
mocker(MockerFixture): mocker object
Returns:
MagicMock: mocked object
"""
import builtins
_import = builtins.__import__
# pylint: disable=redefined-builtin
def test_import(name: str, globals: Any, locals: Any, from_list: list[str], level: Any):
if name == package and (not components or any(component in from_list for component in components)):
raise ImportError
return _import(name, globals, locals, from_list, level)
return mocker.patch.object(builtins, "__import__", test_import)
@pytest.hookimpl(trylast=True)
def pytest_configure() -> None:
"""
register helpers after pytest-helpers-namespace has initialized
"""
for helper in (anyvar, get_package_status, get_package_status_extended, import_error):
for helper in (anyvar, get_package_status, get_package_status_extended):
pytest.helpers.register(helper)
+14 -11
View File
@@ -2,7 +2,6 @@ env_list = [
"check",
"tests",
]
isolated_build = true
requires = [
"tox-uv",
]
@@ -33,6 +32,17 @@ bandit = [
"--configfile",
".bandit.toml",
]
coverage_report = [
"--show-missing",
"--skip-covered",
"--fail-under=100",
]
coverage_run = [
"--source",
"ahriman",
"-m",
"pytest",
]
manpage = [
"--author",
"{[project]name} team",
@@ -110,6 +120,7 @@ dependency_groups = [
]
deps = [
{ replace = "ref", of = ["project", "extras"], extend = true },
"pip",
]
pip_pre = true
set_env.CFLAGS = "-Wno-unterminated-string-initialization"
@@ -274,15 +285,12 @@ deps = [
{ replace = "ref", of = ["project", "extras"], extend = true },
]
pip_pre = true
recreate = true
commands = [
[
"sphinx-build",
"--builder",
"html",
"--fail-on-warning",
"--jobs",
"1",
"--write-all",
"docs",
"{envtmpdir}/html",
@@ -352,10 +360,7 @@ commands = [
[
"coverage",
"run",
"--source",
"ahriman",
"-m",
"pytest",
{ replace = "ref", of = ["flags", "coverage_run"], extend = true },
{ replace = "posargs", default = [
"tests/test_tests.py",
"ahriman-core/tests",
@@ -366,9 +371,7 @@ commands = [
[
"coverage",
"report",
"--show-missing",
"--skip-covered",
"--fail-under=100",
{ replace = "ref", of = ["flags", "coverage_report"], extend = true },
],
]