fix: disable colors for importing parser calls

In case if parser is used to generate docs, it remains w\o colors, but
help messages are still formatted with it
This commit is contained in:
2026-07-18 14:06:58 +03:00
parent fd6add46f9
commit a4a7c13344
6 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-lts-latest
tools:
python: "3.13"
python: "3.14"
apt_packages:
- graphviz
+1 -1
View File
@@ -17,7 +17,7 @@ description = "ArcH linux ReposItory MANager, core package"
dynamic = [
"version",
]
requires-python = ">=3.13"
requires-python = ">=3.14"
[project.optional-dependencies]
journald = [
@@ -19,6 +19,7 @@
#
import argparse
from functools import partial
from pathlib import Path
import ahriman.application.handlers
@@ -34,10 +35,13 @@ from ahriman.models.log_handler import LogHandler
__all__: list[str] = []
def _parser() -> argparse.ArgumentParser:
def _parser(*, color: bool = False) -> argparse.ArgumentParser:
"""
command line parser generator
Args:
color(bool, optional): enable colors in help messages (Default value = False)
Returns:
argparse.ArgumentParser: command line parser for the application
"""
@@ -63,7 +67,7 @@ Start web service (requires additional configuration):
>>> ahriman web
""",
fromfile_prefix_chars="@", formatter_class=_HelpFormatter)
fromfile_prefix_chars="@", formatter_class=_HelpFormatter, color=color)
parser.add_argument("-a", "--architecture", help="filter by target architecture")
parser.add_argument("-c", "--configuration", help="configuration path", type=Path,
default=Path("/") / "etc" / "ahriman.ini")
@@ -92,8 +96,9 @@ Start web service (requires additional configuration):
for handler in implementations(ahriman.application.handlers, Handler):
for subparser_parser in handler.arguments:
subparser = subparser_parser(subparsers)
subparser.color = color
subparser.formatter_class = _HelpFormatter
subparser.set_defaults(handler=handler, parser=_parser)
subparser.set_defaults(handler=handler, parser=partial(_parser, color=color))
# sort actions alphabetically in both choices and help message
# pylint: disable=protected-access
@@ -110,7 +115,7 @@ def run() -> int:
Returns:
int: application status code
"""
parser = _parser()
parser = _parser(color=True)
args = parser.parse_args()
if args.command is None: # in case of empty command we would like to print help message
+1 -1
View File
@@ -13,7 +13,7 @@ description = "ArcH linux ReposItory MANager, additional extensions"
dynamic = [
"version",
]
requires-python = ">=3.13"
requires-python = ">=3.14"
[tool.hatch.build.targets.wheel]
packages = [
+1 -1
View File
@@ -17,7 +17,7 @@ description = "ArcH linux ReposItory MANager, web server"
dynamic = [
"version",
]
requires-python = ">=3.13"
requires-python = ">=3.14"
[project.optional-dependencies]
auth = [
+1 -1
View File
@@ -20,7 +20,7 @@ dynamic = [
]
license = { file = "COPYING" }
readme = "README.md"
requires-python = ">=3.13"
requires-python = ">=3.14"
[project.urls]
Changelog = "https://github.com/arcan1s/ahriman/releases"