From 8f55cc600ea537a83b4cbd7f6b59c4d64bf879a8 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Tue, 17 Aug 2021 03:42:47 +0300 Subject: [PATCH] add manpage generator --- .github/workflows/run-tests.yml | 2 +- .gitignore | 2 ++ README.md | 1 + package/archlinux/PKGBUILD | 9 ++++---- setup.cfg | 3 +++ setup.py | 23 ++++++++++++++----- src/ahriman/application/ahriman.py | 3 +-- src/ahriman/core/status/client.py | 9 +++----- .../web/middlewares/exception_handler.py | 2 +- .../web/middlewares/test_exception_handler.py | 6 ++--- 10 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6dc89e5d..2afbb8e8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,7 +18,7 @@ jobs: docker run \ -v ${{ github.workspace }}:/build -w /build \ archlinux:latest \ - /bin/bash -c "pacman --noconfirm -Syu base-devel python python-pip && \ + /bin/bash -c "pacman --noconfirm -Syu base-devel python-argparse-manpage python-pip && \ pip install -e .[web] && \ pip install -e .[check] && \ pip install -e .[s3] && \ diff --git a/.gitignore b/.gitignore index a4d5b094..d9d60ce1 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,5 @@ ENV/ .venv/ *.tar.xz + +man/ diff --git a/README.md b/README.md index 6116a548..953e0b28 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # ArcHlinux ReposItory MANager [![build status](https://github.com/arcan1s/ahriman/actions/workflows/run-tests.yml/badge.svg)](https://github.com/arcan1s/ahriman/actions/workflows/run-tests.yml) +[![CodeFactor](https://www.codefactor.io/repository/github/arcan1s/ahriman/badge)](https://www.codefactor.io/repository/github/arcan1s/ahriman) Wrapper for managing custom repository inspired by [repo-scripts](https://github.com/arcan1s/repo-scripts). diff --git a/package/archlinux/PKGBUILD b/package/archlinux/PKGBUILD index 1617e889..5d2635d2 100644 --- a/package/archlinux/PKGBUILD +++ b/package/archlinux/PKGBUILD @@ -8,7 +8,7 @@ arch=('any') url="https://github.com/arcan1s/ahriman" license=('GPL3') depends=('devtools' 'git' 'pyalpm' 'python-aur' 'python-srcinfo') -makedepends=('python-pip') +makedepends=('python-argparse-manpage' 'python-pip') optdepends=('breezy: -bzr packages support' 'darcs: -darcs packages support' 'gnupg: package and repository sign' @@ -22,9 +22,6 @@ optdepends=('breezy: -bzr packages support' source=("https://github.com/arcan1s/ahriman/releases/download/$pkgver/$pkgname-$pkgver-src.tar.xz" 'ahriman.sysusers' 'ahriman.tmpfiles') -sha512sums=('6ab741bfb42f92ab00d1b6ecfc44426c00e5c433486e014efbdb585715d9a12dbbafc280e5a9f85b941c8681b13a9dad41327a3e3c44a9683ae30c1d6f017f50' - '13718afec2c6786a18f0b223ef8e58dccf0688bca4cdbe203f14071f5031ed20120eb0ce38b52c76cfd6e8b6581a9c9eaa2743eb11abbaca637451a84c33f075' - '55b20f6da3d66e7bbf2add5d95a3b60632df121717d25a993e56e737d14f51fe063eb6f1b38bd81cc32e05db01c0c1d80aaa720c45cde87f238d8b46cdb8cbc4') backup=('etc/ahriman.ini' 'etc/ahriman.ini.d/logging.ini') @@ -42,3 +39,7 @@ package() { install -Dm644 "$srcdir/$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf" install -Dm644 "$srcdir/$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf" } + +sha512sums=('6ab741bfb42f92ab00d1b6ecfc44426c00e5c433486e014efbdb585715d9a12dbbafc280e5a9f85b941c8681b13a9dad41327a3e3c44a9683ae30c1d6f017f50' + '13718afec2c6786a18f0b223ef8e58dccf0688bca4cdbe203f14071f5031ed20120eb0ce38b52c76cfd6e8b6581a9c9eaa2743eb11abbaca637451a84c33f075' + '55b20f6da3d66e7bbf2add5d95a3b60632df121717d25a993e56e737d14f51fe063eb6f1b38bd81cc32e05db01c0c1d80aaa720c45cde87f238d8b46cdb8cbc4') diff --git a/setup.cfg b/setup.cfg index 36bcbfff..c7f8fe20 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,6 @@ test = pytest [tool:pytest] addopts = --cov=ahriman --cov-report term-missing:skip-covered --pspec + +[build_manpages] +manpages = man/ahriman.1:module=ahriman.application.ahriman:function=_parser diff --git a/setup.py b/setup.py index 6d1e792e..3139b401 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,16 @@ -from distutils.util import convert_path +from build_manpages.build_manpages import build_manpages, get_build_py_cmd, get_install_cmd +from pathlib import Path from setuptools import setup, find_packages -from os import path +from setuptools.command.build_py import build_py +from setuptools.command.install import install +from typing import Any, Dict + + +metadata_path = Path(__file__).resolve().parent / "src/ahriman/version.py" +metadata: Dict[str, Any] = dict() +with metadata_path.open() as metadata_file: + exec(metadata_file.read(), metadata) # pylint: disable=exec-used -here = path.abspath(path.dirname(__file__)) -metadata = dict() -with open(convert_path("src/ahriman/version.py")) as metadata_file: - exec(metadata_file.read(), metadata) setup( name="ahriman", @@ -96,4 +101,10 @@ setup( "aiohttp_jinja2", ], }, + + cmdclass={ + "build_manpages": build_manpages, + "build_py": get_build_py_cmd(build_py), + "install": get_install_cmd(install), + } ) diff --git a/src/ahriman/application/ahriman.py b/src/ahriman/application/ahriman.py index 9d591ee7..2a9c5bdb 100644 --- a/src/ahriman/application/ahriman.py +++ b/src/ahriman/application/ahriman.py @@ -30,8 +30,7 @@ from ahriman.models.sign_settings import SignSettings # pylint thinks it is bad idea, but get the fuck off -# pylint: disable=protected-access -SubParserAction = argparse._SubParsersAction +SubParserAction = argparse._SubParsersAction # pylint: disable=protected-access def _parser() -> argparse.ArgumentParser: diff --git a/src/ahriman/core/status/client.py b/src/ahriman/core/status/client.py index ad1432f7..ea1b8087 100644 --- a/src/ahriman/core/status/client.py +++ b/src/ahriman/core/status/client.py @@ -53,8 +53,7 @@ class Client: :param status: current package build status """ - # pylint: disable=no-self-use - def get(self, base: Optional[str]) -> List[Tuple[Package, BuildStatus]]: + def get(self, base: Optional[str]) -> List[Tuple[Package, BuildStatus]]: # pylint: disable=no-self-use """ get package status :param base: package base to get @@ -63,16 +62,14 @@ class Client: del base return [] - # pylint: disable=no-self-use - def get_internal(self) -> InternalStatus: + def get_internal(self) -> InternalStatus: # pylint: disable=no-self-use """ get internal service status :return: current internal (web) service status """ return InternalStatus() - # pylint: disable=no-self-use - def get_self(self) -> BuildStatus: + def get_self(self) -> BuildStatus: # pylint: disable=no-self-use """ get ahriman status itself :return: current ahriman status diff --git a/src/ahriman/web/middlewares/exception_handler.py b/src/ahriman/web/middlewares/exception_handler.py index 3d20103e..ebbcabcc 100644 --- a/src/ahriman/web/middlewares/exception_handler.py +++ b/src/ahriman/web/middlewares/exception_handler.py @@ -40,7 +40,7 @@ def exception_handler(logger: Logger) -> Callable[[Request, HandlerType], Awaita except HTTPClientError: raise except Exception: - logger.exception(f"exception during performing request to {request.path}") + logger.exception("exception during performing request to %s", request.path) raise return handle diff --git a/tests/ahriman/web/middlewares/test_exception_handler.py b/tests/ahriman/web/middlewares/test_exception_handler.py index 11b9c6c9..20435273 100644 --- a/tests/ahriman/web/middlewares/test_exception_handler.py +++ b/tests/ahriman/web/middlewares/test_exception_handler.py @@ -25,8 +25,7 @@ async def test_exception_handler_client_error(aiohttp_request: Any, mocker: Mock """ must pass client exception """ - request_handler = AsyncMock() - request_handler.side_effect = HTTPBadRequest() + request_handler = AsyncMock(side_effect=HTTPBadRequest()) logging_mock = mocker.patch("logging.Logger.exception") handler = exception_handler(logging.getLogger()) @@ -39,8 +38,7 @@ async def test_exception_handler_server_error(aiohttp_request: Any, mocker: Mock """ must log server exception and re-raise it """ - request_handler = AsyncMock() - request_handler.side_effect = Exception() + request_handler = AsyncMock(side_effect=Exception()) logging_mock = mocker.patch("logging.Logger.exception") handler = exception_handler(logging.getLogger())