From 4b6feb9ae6bbcc34c7b920a97622707984c91cac Mon Sep 17 00:00:00 2001 From: Evgenii Alekseev Date: Sun, 22 Oct 2023 22:18:23 +0300 Subject: [PATCH] refactor: add ability to pass anything as environment variable to build task --- src/ahriman/core/build_tools/task.py | 12 +++++++----- src/ahriman/core/repository/executor.py | 2 +- tests/ahriman/core/build_tools/test_task.py | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ahriman/core/build_tools/task.py b/src/ahriman/core/build_tools/task.py index bc06c50b..0e30e146 100644 --- a/src/ahriman/core/build_tools/task.py +++ b/src/ahriman/core/build_tools/task.py @@ -68,13 +68,13 @@ class Task(LazyLogging): self.makepkg_flags = configuration.getlist("build", "makepkg_flags", fallback=[]) self.makechrootpkg_flags = configuration.getlist("build", "makechrootpkg_flags", fallback=[]) - def build(self, sources_dir: Path, packager: str | None = None) -> list[Path]: + def build(self, sources_dir: Path, **kwargs: str | None) -> list[Path]: """ run package build Args: sources_dir(Path): path to where sources are - packager(str | None, optional): optional packager override (Default value = None) + **kwargs(str | None): environment variables to be passed to build processes Returns: list[Path]: paths of produced packages @@ -85,9 +85,11 @@ class Task(LazyLogging): command.extend(["--"] + self.makepkg_flags) self.logger.info("using %s for %s", command, self.package.base) - environment: dict[str, str] = {} - if packager is not None: - environment["PACKAGER"] = packager + environment: dict[str, str] = { + key: value + for key, value in kwargs.items() + if value is not None + } self.logger.info("using environment variables %s", environment) Task._check_output( diff --git a/src/ahriman/core/repository/executor.py b/src/ahriman/core/repository/executor.py index 1a46d64e..a5266468 100644 --- a/src/ahriman/core/repository/executor.py +++ b/src/ahriman/core/repository/executor.py @@ -83,7 +83,7 @@ class Executor(Cleaner): task = Task(package, self.configuration, self.architecture, self.paths) local_version = local_versions.get(package.base) if bump_pkgrel else None task.init(local_path, self.database, local_version) - built = task.build(local_path, packager_id) + built = task.build(local_path, PACKAGER=packager_id) for src in built: dst = self.paths.packages / src.name shutil.move(src, dst) diff --git a/tests/ahriman/core/build_tools/test_task.py b/tests/ahriman/core/build_tools/test_task.py index 8b14ce27..742df180 100644 --- a/tests/ahriman/core/build_tools/test_task.py +++ b/tests/ahriman/core/build_tools/test_task.py @@ -10,7 +10,7 @@ def test_build(task_ahriman: Task, mocker: MockerFixture) -> None: must build package """ check_output_mock = mocker.patch("ahriman.core.build_tools.task.Task._check_output") - task_ahriman.build(Path("ahriman"), "packager") + task_ahriman.build(Path("ahriman")) check_output_mock.assert_called()