refactor: fix warnings and typos, cleanup code

This commit is contained in:
Evgenii Alekseev 2023-12-28 16:53:45 +02:00
parent c3dacd6883
commit f3e9fbf9d0
20 changed files with 35 additions and 37 deletions

View File

@ -96,7 +96,7 @@ All subcommands are divided into several groups depending on the role they are d
* ``aur`` (``aur-search``) group is for AUR operations. * ``aur`` (``aur-search``) group is for AUR operations.
* ``help`` (e.g. ``help``) are system commands. * ``help`` (e.g. ``help``) are system commands.
* ``package`` subcommands (e.g. ``package-add``) allow to perform single package actions. * ``package`` subcommands (e.g. ``package-add``) allow to perform single package actions.
* ``patch`` subcommands (e.g. ``pacth-list``) are the special case of ``package`` subcommands introduced in order to control patches for packages. * ``patch`` subcommands (e.g. ``patch-list``) are the special case of ``package`` subcommands introduced in order to control patches for packages.
* ``repo`` subcommands (e.g. ``repo-check``) usually perform actions on whole repository. * ``repo`` subcommands (e.g. ``repo-check``) usually perform actions on whole repository.
* ``service`` subcommands (e.g. ``service-setup``) perform actions which are related to whole service managing: create repository, show configuration. * ``service`` subcommands (e.g. ``service-setup``) perform actions which are related to whole service managing: create repository, show configuration.
* ``user`` subcommands (``user-add``) are intended for user management. * ``user`` subcommands (``user-add``) are intended for user management.

View File

@ -545,7 +545,7 @@ In this example we are going to use files and packages which are provided by off
.. code-block:: shell .. code-block:: shell
wget http://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst wget https://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst
pacman -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst pacman -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst
#. #.
@ -553,7 +553,7 @@ In this example we are going to use files and packages which are provided by off
.. code-block:: shell .. code-block:: shell
wget http://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst wget https://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst
pacman -U devtools-20221208-1.2-any.pkg.tar.zst pacman -U devtools-20221208-1.2-any.pkg.tar.zst
Alternatively, you can create your own ``makepkg`` configuration and save it as ``/usr/share/devtools/makepkg.conf.d/i686.conf``. Alternatively, you can create your own ``makepkg`` configuration and save it as ``/usr/share/devtools/makepkg.conf.d/i686.conf``.
@ -563,7 +563,7 @@ In this example we are going to use files and packages which are provided by off
.. code-block:: shell .. code-block:: shell
ahriman -a i686 service-setup --mirror 'http://de.mirror.archlinux32.org/$arch/$repo'--no-multilib ... ahriman -a i686 service-setup --mirror 'https://de.mirror.archlinux32.org/$arch/$repo'--no-multilib ...
In addition to usual options, you need to specify the following options: In addition to usual options, you need to specify the following options:
@ -598,8 +598,8 @@ There are two possible ways to achieve same setup, by using docker container. Th
.. code-block:: dockerfile .. code-block:: dockerfile
RUN pacman --noconfirm -Sy wget RUN pacman --noconfirm -Sy wget
RUN wget http://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst && pacman --noconfirm -U devtools-20221208-1.2-any.pkg.tar.zst RUN wget https://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst && pacman --noconfirm -U devtools-20221208-1.2-any.pkg.tar.zst
RUN wget http://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst && pacman --noconfirm -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst RUN wget https://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst && pacman --noconfirm -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst
#. #.
At that point you should have full ``Dockerfile`` like: At that point you should have full ``Dockerfile`` like:
@ -611,8 +611,8 @@ There are two possible ways to achieve same setup, by using docker container. Th
RUN pacman-key --init RUN pacman-key --init
RUN pacman --noconfirm -Sy wget RUN pacman --noconfirm -Sy wget
RUN wget http://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst && pacman --noconfirm -U devtools-20221208-1.2-any.pkg.tar.zst RUN wget https://pool.mirror.archlinux32.org/i686/extra/devtools-20221208-1.2-any.pkg.tar.zst && pacman --noconfirm -U devtools-20221208-1.2-any.pkg.tar.zst
RUN wget http://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst && pacman --noconfirm -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst RUN wget https://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-20230705-1.0-any.pkg.tar.zst && pacman --noconfirm -U archlinux32-keyring-20230705-1.0-any.pkg.tar.zst
#. #.
After that you can build you own container, e.g.: After that you can build you own container, e.g.:
@ -626,7 +626,7 @@ There are two possible ways to achieve same setup, by using docker container. Th
.. code-block:: shell .. code-block:: shell
docker run --privileged -p 8080:8080 -e AHRIMAN_ARCHITECTURE=i686 -e AHRIMAN_PACMAN_MIRROR='http://de.mirror.archlinux32.org/$arch/$repo' -e AHRIMAN_MULTILIB= ahriman-i686:latest docker run --privileged -p 8080:8080 -e AHRIMAN_ARCHITECTURE=i686 -e AHRIMAN_PACMAN_MIRROR='https://de.mirror.archlinux32.org/$arch/$repo' -e AHRIMAN_MULTILIB= ahriman-i686:latest
Remote synchronization Remote synchronization
---------------------- ----------------------

View File

@ -7,7 +7,7 @@ Collection of the examples of docker compose configuration files, which covers s
* [Check](check): double process service; one with periodic checks (automatic build disabled) and other one is with the web service. * [Check](check): double process service; one with periodic checks (automatic build disabled) and other one is with the web service.
* [Daemon](daemon): service with periodic repository checks. * [Daemon](daemon): service with periodic repository checks.
* [Distributed](distributed): cluster of three nodes, one with web interface and two workers which are responsible for build process. * [Distributed](distributed): cluster of three nodes, one with web interface and two workers which are responsible for build process.
* [Distrubuted manual](distributed-manual): same as [distributed](distributed), but two nodes and update process must be run on worker node manually. * [Distributed manual](distributed-manual): same as [distributed](distributed), but two nodes and update process must be run on worker node manually.
* [i686](i686): non-x86_64 architecture setup. * [i686](i686): non-x86_64 architecture setup.
* [Multi repo](multirepo): run web service with two separated repositories. * [Multi repo](multirepo): run web service with two separated repositories.
* [Pull](pull): normal service, but in addition with pulling packages from another source (e.g. GitHub repository). * [Pull](pull): normal service, but in addition with pulling packages from another source (e.g. GitHub repository).

View File

@ -5,5 +5,5 @@ ENV ARCH32_KEYRING_VERSION="20231126-1.0"
RUN pacman-key --init RUN pacman-key --init
RUN pacman -Sy --noconfirm wget && \ RUN pacman -Sy --noconfirm wget && \
wget -nv http://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-${ARCH32_KEYRING_VERSION}-any.pkg.tar.zst && \ wget -nv https://pool.mirror.archlinux32.org/i686/core/archlinux32-keyring-${ARCH32_KEYRING_VERSION}-any.pkg.tar.zst && \
pacman -U --noconfirm archlinux32-keyring-${ARCH32_KEYRING_VERSION}-any.pkg.tar.zst pacman -U --noconfirm archlinux32-keyring-${ARCH32_KEYRING_VERSION}-any.pkg.tar.zst

View File

@ -34,9 +34,6 @@ from ahriman.models.worker import Worker
class Updater(LazyLogging): class Updater(LazyLogging):
""" """
updater handler interface updater handler interface
Attributes:
split_method(Callable[[Iterable[Package]], list[list[Package]]]): method to split packages into chunks
""" """
@staticmethod @staticmethod

View File

@ -170,7 +170,7 @@ class Handler:
# extract repository names first # extract repository names first
if (from_args := args.repository) is not None: if (from_args := args.repository) is not None:
repositories: Iterable[str] = [from_args] repositories: Iterable[str] = [from_args]
elif (from_filesystem := RepositoryPaths.known_repositories(root)): elif from_filesystem := RepositoryPaths.known_repositories(root):
repositories = from_filesystem repositories = from_filesystem
else: # try to read configuration now else: # try to read configuration now
repositories = [configuration.get("repository", "name")] repositories = [configuration.get("repository", "name")]

View File

@ -344,7 +344,7 @@ class Sources(LazyLogging):
str: HEAD commit hash str: HEAD commit hash
""" """
# we might want to parse git files instead though # we might want to parse git files instead though
return check_output("git", "rev-parse", ref_name, cwd=sources_dir) return check_output("git", "rev-parse", ref_name, cwd=sources_dir, logger=self.logger)
def move(self, pkgbuild_dir: Path, sources_dir: Path) -> None: def move(self, pkgbuild_dir: Path, sources_dir: Path) -> None:
""" """

View File

@ -38,7 +38,7 @@ class Task(LazyLogging):
archbuild_flags(list[str]): command flags for archbuild command archbuild_flags(list[str]): command flags for archbuild command
architecture(str): repository architecture architecture(str): repository architecture
build_command(str): build command build_command(str): build command
makechroootpkg_flags(list[str]): command flags for makechrootpkg command makechrootpkg_flags(list[str]): command flags for makechrootpkg command
makepkg_flags(list[str]): command flags for makepkg command makepkg_flags(list[str]): command flags for makepkg command
package(Package): package definitions package(Package): package definitions
paths(RepositoryPaths): repository paths instance paths(RepositoryPaths): repository paths instance

View File

@ -41,7 +41,7 @@ class Client:
load client from settings load client from settings
Args: Args:
repository_id(RepositoryId): repository unqiue 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

View File

@ -276,8 +276,8 @@ class Tree:
unprocessed = sorted(self.leaves, key=lambda leaf: leaf.package.base) unprocessed = sorted(self.leaves, key=lambda leaf: leaf.package.base)
while unprocessed: while unprocessed:
# pick one and append it to the most free partition and build chunk # pick one and append it to the most free partition and build chunk
leaf = unprocessed.pop() first_leaf = unprocessed.pop()
chunk = [leaf] chunk = [first_leaf]
while True: # python doesn't allow to use walrus operator to unpack tuples while True: # python doesn't allow to use walrus operator to unpack tuples
# get packages which depend on packages in chunk # get packages which depend on packages in chunk

View File

@ -46,7 +46,7 @@ class Result:
default constructor default constructor
Args: Args:
addded(Iterable[Package] | None, optional): initial list of successfully added packages added(Iterable[Package] | None, optional): initial list of successfully added packages
(Default value = None) (Default value = None)
updated(Iterable[Package] | None, optional): initial list of successfully updated packages updated(Iterable[Package] | None, optional): initial list of successfully updated packages
(Default value = None) (Default value = None)

View File

@ -1,6 +1,4 @@
import argparse import argparse
import configparser
import pytest import pytest
from pytest_mock import MockerFixture from pytest_mock import MockerFixture

View File

@ -565,6 +565,7 @@ def watcher(repository_id: RepositoryId, database: SQLite, repository: Repositor
Args: Args:
repository_id(RepositoryId): repository identifier fixture repository_id(RepositoryId): repository identifier fixture
database(SQLite): database fixture database(SQLite): database fixture
repository(Repository): repository fixture
Returns: Returns:
Watcher: package status watcher test instance Watcher: package status watcher test instance

View File

@ -510,7 +510,7 @@ def test_head(sources: Sources, mocker: MockerFixture) -> None:
local = Path("local") local = Path("local")
assert sources.head(local) == "sha" assert sources.head(local) == "sha"
check_output_mock.assert_called_once_with("git", "rev-parse", "HEAD", cwd=local) check_output_mock.assert_called_once_with("git", "rev-parse", "HEAD", cwd=local, logger=sources.logger)
def test_head_specific(sources: Sources, mocker: MockerFixture) -> None: def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
@ -521,7 +521,7 @@ def test_head_specific(sources: Sources, mocker: MockerFixture) -> None:
local = Path("local") local = Path("local")
assert sources.head(local, "master") == "sha" assert sources.head(local, "master") == "sha"
check_output_mock.assert_called_once_with("git", "rev-parse", "master", cwd=local) check_output_mock.assert_called_once_with("git", "rev-parse", "master", cwd=local, logger=sources.logger)
def test_move(sources: Sources, mocker: MockerFixture) -> None: def test_move(sources: Sources, mocker: MockerFixture) -> None:

View File

@ -145,7 +145,7 @@ def update_printer(package_ahriman: Package) -> UpdatePrinter:
package_ahriman(Package): package fixture package_ahriman(Package): package fixture
Returns: Returns:
UpdatePrinter: udpate printer test instance UpdatePrinter: update printer test instance
""" """
return UpdatePrinter(package_ahriman, None) return UpdatePrinter(package_ahriman, None)

View File

@ -15,6 +15,7 @@ from ahriman.core.util import check_output, check_user, dataclass_view, enum_val
srcinfo_property, srcinfo_property_list, trim_package, unquote, utcnow, walk srcinfo_property, srcinfo_property_list, trim_package, unquote, utcnow, walk
from ahriman.models.package import Package from ahriman.models.package import Package
from ahriman.models.package_source import PackageSource from ahriman.models.package_source import PackageSource
from ahriman.models.repository_id import RepositoryId
from ahriman.models.repository_paths import RepositoryPaths from ahriman.models.repository_paths import RepositoryPaths
@ -150,11 +151,11 @@ def test_check_output_empty_line(mocker: MockerFixture) -> None:
logger_mock.assert_has_calls([MockCall(""), MockCall("hello")]) logger_mock.assert_has_calls([MockCall(""), MockCall("hello")])
def test_check_user(mocker: MockerFixture) -> None: def test_check_user(repository_id: RepositoryId, mocker: MockerFixture) -> None:
""" """
must check user correctly must check user correctly
""" """
paths = RepositoryPaths(Path.cwd(), "x86_64") paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0]) mocker.patch("os.getuid", return_value=paths.root_owner[0])
check_user(paths, unsafe=False) check_user(paths, unsafe=False)
@ -167,22 +168,22 @@ def test_check_user_no_directory(repository_paths: RepositoryPaths, mocker: Mock
check_user(repository_paths, unsafe=False) check_user(repository_paths, unsafe=False)
def test_check_user_exception(mocker: MockerFixture) -> None: def test_check_user_exception(repository_id: RepositoryId, mocker: MockerFixture) -> None:
""" """
must raise exception if user differs must raise exception if user differs
""" """
paths = RepositoryPaths(Path.cwd(), "x86_64") paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1) mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
with pytest.raises(UnsafeRunError): with pytest.raises(UnsafeRunError):
check_user(paths, unsafe=False) check_user(paths, unsafe=False)
def test_check_user_unsafe(mocker: MockerFixture) -> None: def test_check_user_unsafe(repository_id: RepositoryId, mocker: MockerFixture) -> None:
""" """
must skip check if unsafe flag is set must skip check if unsafe flag is set
""" """
paths = RepositoryPaths(Path.cwd(), "x86_64") paths = RepositoryPaths(Path.cwd(), repository_id)
mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1) mocker.patch("os.getuid", return_value=paths.root_owner[0] + 1)
check_user(paths, unsafe=True) check_user(paths, unsafe=True)

View File

@ -37,7 +37,9 @@ def test_load_trigger(trigger_loader: TriggerLoader, configuration: Configuratio
""" """
must load trigger must load trigger
""" """
loaded = trigger_loader.load_trigger("ahriman.core.report.ReportTrigger", "x86_64", configuration) _, repository_id = configuration.check_loaded()
loaded = trigger_loader.load_trigger("ahriman.core.report.ReportTrigger", repository_id, configuration)
assert loaded assert loaded
assert isinstance(loaded, ReportTrigger) assert isinstance(loaded, ReportTrigger)

View File

@ -54,8 +54,7 @@ def test_from_json_2(aur_package_ahriman: AURPackage, mocker: MockerFixture) ->
assert AURPackage.from_json(asdict(aur_package_ahriman)) == aur_package_ahriman assert AURPackage.from_json(asdict(aur_package_ahriman)) == aur_package_ahriman
def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman: AURPackage, def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman: AURPackage) -> None:
resource_path_root: Path) -> None:
""" """
must load package from repository database must load package from repository database
""" """

View File

@ -320,7 +320,7 @@ def test_local_files_empty(mocker: MockerFixture, resource_path_root: Path) -> N
assert list(Package.local_files(Path("path"))) == [] assert list(Package.local_files(Path("path"))) == []
def test_local_files_error(mocker: MockerFixture, resource_path_root: Path) -> None: def test_local_files_error(mocker: MockerFixture) -> None:
""" """
must raise exception on package parsing for local sources must raise exception on package parsing for local sources
""" """

View File

@ -139,7 +139,7 @@ async def test_exception_handler_head() -> None:
async def test_exception_handler_method_not_allowed() -> None: async def test_exception_handler_method_not_allowed() -> None:
""" """
must handle not allowed methodss must handle not allowed methods
""" """
request = pytest.helpers.request("", "", "POST") request = pytest.helpers.request("", "", "POST")
request_handler = AsyncMock(side_effect=HTTPMethodNotAllowed("POST", ["GET"])) request_handler = AsyncMock(side_effect=HTTPMethodNotAllowed("POST", ["GET"]))