Compare commits

..

5 Commits

Author SHA1 Message Date
153cf448af add list config options 2024-10-17 18:45:38 +03:00
eff5be9490 add package-splitt script 2024-10-16 14:11:22 +03:00
20a9134477 Revert "use hatchling instead of flit"
This reverts commit d18d146d79.
2024-10-13 23:04:00 +03:00
d18d146d79 use hatchling instead of flit 2024-10-10 14:50:04 +03:00
4e4029e6a1 move argument parsers to handlers themselves 2024-10-10 14:00:01 +03:00
8 changed files with 18 additions and 87 deletions

View File

@ -4,7 +4,7 @@ set -e
[ -n "$AHRIMAN_DEBUG" ] && set -x [ -n "$AHRIMAN_DEBUG" ] && set -x
# configuration tune # configuration tune
cat <<EOF > "/etc/ahriman.ini.d/01-docker.ini" cat <<EOF > "/etc/ahriman.ini.d/00-docker.ini"
[repository] [repository]
root = $AHRIMAN_REPOSITORY_ROOT root = $AHRIMAN_REPOSITORY_ROOT

View File

@ -12,14 +12,6 @@ ahriman.core.configuration.configuration module
:no-undoc-members: :no-undoc-members:
:show-inheritance: :show-inheritance:
ahriman.core.configuration.configuration\_multi\_dict module
------------------------------------------------------------
.. automodule:: ahriman.core.configuration.configuration_multi_dict
:members:
:no-undoc-members:
:show-inheritance:
ahriman.core.configuration.schema module ahriman.core.configuration.schema module
---------------------------------------- ----------------------------------------

View File

@ -13,27 +13,7 @@ There are two variable types which have been added to default ones, they are pat
* By default, it splits value by spaces excluding empty elements. * By default, it splits value by spaces excluding empty elements.
* In case if quotation mark (``"`` or ``'``) will be found, any spaces inside will be ignored. * In case if quotation mark (``"`` or ``'``) will be found, any spaces inside will be ignored.
* In order to use quotation mark inside value it is required to put it to another quotation mark, e.g. ``wor"'"d "with quote"`` will be parsed as ``["wor'd", "with quote"]`` and vice versa. * In order to use quotation mark inside value it is required to put it to another quotation mark, e.g. ``wor"'"d "with quote"`` will be parsed as ``["wor'd", "with quote"]`` and vice versa.
* Unclosed quotation mark is not allowed and will raise an exception. * Unclosed quotation mark is not allowed and will rise an exception.
It is also possible to split list option between multiple declarations. To do so, append key name with ``[]`` (like PHP, sorry!), e.g.:
.. code-block:: ini
[section]
list[] = value1
list[] = value2
will lead to ``${section:list}`` value to be set to ``value1 value2``. The values will be set in order of appearance, meaning that values which appear in different include files will be set in alphabetical order of file names. In order to reset list values, set option to empty string, e.g.:
.. code-block:: ini
[section]
list[] = value1
list[] =
list[] = value2
list[] = value3
will set option ``${section:list}`` to ``value2 value3``. Alternatively, setting the original option (e.g. ``list`` in the example above) will also reset value, though the subsequent options with leading ``[]`` will append the previous value.
Path values, except for casting to ``pathlib.Path`` type, will be also expanded to absolute paths relative to the configuration path. E.g. if path is set to ``ahriman.ini.d/logging.ini`` and root configuration path is ``/etc/ahriman.ini``, the value will be expanded to ``/etc/ahriman.ini.d/logging.ini``. In order to disable path expand, use the full path, e.g. ``/etc/ahriman.ini.d/logging.ini``. Path values, except for casting to ``pathlib.Path`` type, will be also expanded to absolute paths relative to the configuration path. E.g. if path is set to ``ahriman.ini.d/logging.ini`` and root configuration path is ``/etc/ahriman.ini``, the value will be expanded to ``/etc/ahriman.ini.d/logging.ini``. In order to disable path expand, use the full path, e.g. ``/etc/ahriman.ini.d/logging.ini``.
@ -42,7 +22,7 @@ Configuration allows string interpolation from the same configuration file, e.g.
.. code-block:: ini .. code-block:: ini
[section] [section]
key = ${another_key} key = ${anoher_key}
another_key = value another_key = value
will read value for the ``key`` option from ``another_key`` in the same section. In case if the cross-section reference is required, the ``${section:another_key}`` notation must be used. It also allows string interpolation from environment variables, e.g.: will read value for the ``key`` option from ``another_key`` in the same section. In case if the cross-section reference is required, the ``${section:another_key}`` notation must be used. It also allows string interpolation from environment variables, e.g.:

View File

@ -65,19 +65,9 @@ makepkg_flags = --nocolor --ignorearch
; List of paths to be used for implicit dependency scan. Regular expressions are supported. ; List of paths to be used for implicit dependency scan. Regular expressions are supported.
scan_paths = ^usr/lib(?!/cmake).*$ scan_paths = ^usr/lib(?!/cmake).*$
; List of enabled triggers in the order of calls. ; List of enabled triggers in the order of calls.
triggers[] = ahriman.core.gitremote.RemotePullTrigger triggers = ahriman.core.gitremote.RemotePullTrigger ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger ahriman.core.gitremote.RemotePushTrigger
triggers[] = ahriman.core.report.ReportTrigger
triggers[] = ahriman.core.upload.UploadTrigger
triggers[] = ahriman.core.gitremote.RemotePushTrigger
; List of well-known triggers. Used only for configuration purposes. ; List of well-known triggers. Used only for configuration purposes.
triggers_known[] = ahriman.core.distributed.WorkerLoaderTrigger triggers_known = ahriman.core.distributed.WorkerLoaderTrigger ahriman.core.distributed.WorkerRegisterTrigger ahriman.core.distributed.WorkerTrigger ahriman.core.distributed.WorkerUnregisterTrigger ahriman.core.gitremote.RemotePullTrigger ahriman.core.gitremote.RemotePushTrigger ahriman.core.report.ReportTrigger ahriman.core.upload.UploadTrigger ahriman.core.support.KeyringTrigger ahriman.core.support.MirrorlistTrigger
triggers_known[] = ahriman.core.distributed.WorkerTrigger
triggers_known[] = ahriman.core.gitremote.RemotePullTrigger
triggers_known[] = ahriman.core.gitremote.RemotePushTrigger
triggers_known[] = ahriman.core.report.ReportTrigger
triggers_known[] = ahriman.core.support.KeyringTrigger
triggers_known[] = ahriman.core.support.MirrorlistTrigger
triggers_known[] = ahriman.core.upload.UploadTrigger
; Maximal age in seconds of the VCS packages before their version will be updated with its remote source. ; Maximal age in seconds of the VCS packages before their version will be updated with its remote source.
;vcs_allowed_age = 604800 ;vcs_allowed_age = 604800
; List of worker nodes addresses used for build process, e.g.: ; List of worker nodes addresses used for build process, e.g.:
@ -131,7 +121,7 @@ host = 127.0.0.1
; Path to directory with static files. ; Path to directory with static files.
static_path = ${templates}/static static_path = ${templates}/static
; List of directories with templates. ; List of directories with templates.
templates[] = ${prefix}/share/ahriman/templates templates = ${prefix}/share/ahriman/templates
; Path to unix socket. If none set, unix socket will be disabled. ; Path to unix socket. If none set, unix socket will be disabled.
;unix_socket = ;unix_socket =
; Allow unix socket to be world readable. ; Allow unix socket to be world readable.
@ -256,7 +246,7 @@ template = email-index.jinja2
; Template name to be used for full packages list generation (same as HTML report). ; Template name to be used for full packages list generation (same as HTML report).
;template_full = ;template_full =
; List of directories with templates. ; List of directories with templates.
templates[] = ${prefix}/share/ahriman/templates templates = ${prefix}/share/ahriman/templates
; SMTP user. ; SMTP user.
;user = ;user =
@ -275,7 +265,7 @@ templates[] = ${prefix}/share/ahriman/templates
; Template name to be used. ; Template name to be used.
template = repo-index.jinja2 template = repo-index.jinja2
; List of directories with templates. ; List of directories with templates.
templates[] = ${prefix}/share/ahriman/templates templates = ${prefix}/share/ahriman/templates
; Remote service callback trigger configuration sample. ; Remote service callback trigger configuration sample.
[remote-call] [remote-call]
@ -305,7 +295,7 @@ templates[] = ${prefix}/share/ahriman/templates
; Template name to be used. ; Template name to be used.
template = rss.jinja2 template = rss.jinja2
; List of directories with templates. ; List of directories with templates.
templates[] = ${prefix}/share/ahriman/templates templates = ${prefix}/share/ahriman/templates
; Telegram reporting trigger configuration sample. ; Telegram reporting trigger configuration sample.
[telegram] [telegram]
@ -326,7 +316,7 @@ template = telegram-index.jinja2
; Telegram specific template mode, one of MarkdownV2, HTML or Markdown. ; Telegram specific template mode, one of MarkdownV2, HTML or Markdown.
;template_type = HTML ;template_type = HTML
; List of directories with templates. ; List of directories with templates.
templates[] = ${prefix}/share/ahriman/templates templates = ${prefix}/share/ahriman/templates
; HTTP request timeout in seconds. ; HTTP request timeout in seconds.
;timeout = 30 ;timeout = 30

View File

@ -200,9 +200,9 @@ class Setup(Handler):
multilib(bool): add or do not multilib repository to the configuration multilib(bool): add or do not multilib repository to the configuration
repository_server(str): url of the repository repository_server(str): url of the repository
""" """
# allow_no_value=True is required because pacman uses boolean configuration in which just keys present # allow_multi_key=False is required because pacman uses boolean configuration in which just keys present
# (e.g. NoProgressBar) which will lead to exception. allow_multi_key=False is set just for fun # (e.g. NoProgressBar) which will lead to exception
configuration = Configuration(allow_no_value=True, allow_multi_key=False) configuration = Configuration(allow_multi_key=False)
# preserve case # preserve case
# stupid mypy thinks that it is impossible # stupid mypy thinks that it is impossible
configuration.optionxform = lambda optionstr: optionstr # type: ignore[method-assign] configuration.optionxform = lambda optionstr: optionstr # type: ignore[method-assign]

View File

@ -70,28 +70,25 @@ class Configuration(configparser.RawConfigParser):
SYSTEM_CONFIGURATION_PATH = Path(sys.prefix) / "share" / "ahriman" / "settings" / "ahriman.ini" SYSTEM_CONFIGURATION_PATH = Path(sys.prefix) / "share" / "ahriman" / "settings" / "ahriman.ini"
converters: dict[str, Callable[[str], Any]] # typing guard converters: dict[str, Callable[[str], Any]] # typing guard
def __init__(self, allow_no_value: bool = False, allow_multi_key: bool = True) -> None: def __init__(self, allow_multi_key: bool = True) -> None:
""" """
Args: Args:
allow_no_value(bool, optional): copies :class:`configparser.RawConfigParser` behaviour. In case if it is set
to ``True``, the keys without values will be allowed (Default value = False)
allow_multi_key(bool, optional): if set to ``False``, then the default dictionary class will be used to allow_multi_key(bool, optional): if set to ``False``, then the default dictionary class will be used to
store keys internally. Otherwise, the special implementation will be used, which supports arrays store keys internally. Otherwise, the special implementation will be used, which supports arrays
(Default value = True) (Default value = True)
""" """
configparser.RawConfigParser.__init__( configparser.RawConfigParser.__init__(
self, self,
dict_type=ConfigurationMultiDict if allow_multi_key else dict, # type: ignore[arg-type] dict_type=ConfigurationMultiDict if allow_multi_key else dict,
allow_no_value=allow_no_value,
strict=False, strict=False,
empty_lines_in_values=not allow_multi_key, empty_lines_in_values=False,
interpolation=ShellInterpolator(), interpolation=ShellInterpolator(),
converters={ converters={
"list": shlex.split, "list": shlex.split,
"path": self._convert_path, "path": self._convert_path,
"pathlist": lambda value: [self._convert_path(element) for element in shlex.split(value)], "pathlist": lambda value: [self._convert_path(element) for element in shlex.split(value)],
}, },
) ) # type: ignore[call-overload]
self.repository_id: RepositoryId | None = None self.repository_id: RepositoryId | None = None
self.path: Path | None = None self.path: Path | None = None

View File

@ -1,6 +1,4 @@
import configparser import configparser
from io import StringIO
import pytest import pytest
from pathlib import Path from pathlib import Path
@ -182,32 +180,6 @@ def test_getlist_unmatched_quote(configuration: Configuration) -> None:
configuration.getlist("build", "test_list") configuration.getlist("build", "test_list")
def test_getlist_append() -> None:
"""
must correctly append list values
"""
configuration = Configuration()
configuration._read(
StringIO("""
[section]
list1[] = value1
list1[] = value2
list2[] = value3
list2[] =
list2[] = value4
list2[] = value5
list3[] = value6
list3 = value7
list3[] = value8
"""), "io")
assert configuration.getlist("section", "list1") == ["value1", "value2"]
assert configuration.getlist("section", "list2") == ["value4", "value5"]
assert configuration.getlist("section", "list3") == ["value7", "value8"]
def test_getpath_absolute_to_absolute(configuration: Configuration) -> None: def test_getpath_absolute_to_absolute(configuration: Configuration) -> None:
""" """
must not change path for absolute path in settings must not change path for absolute path in settings