[mod] brand - partial migration of settings to msgspec.Struct (#5280)

The settings are currently an untyped key/value structure, whose types are
dynamically built at runtime.  The construction process of this structure
is *hand-crafted*.

In the long term, we want a static typing of this structure, based on a standard
tool.  The ``msgspec.Struct`` structures are suitable as a standard tool.

This patch makes a first step towards static typing and implements the "brand"
section using ``msgspec.Struct`` structures.

BTW: searx/settings_defaults.py - ``git_url`` and ``git_branch`` had been
removed in aee613d256, this is a leftover.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser
2025-10-10 16:14:29 +02:00
committed by GitHub
parent f0dfe3cc0e
commit 21d0428cf2
6 changed files with 105 additions and 39 deletions

View File

@@ -9,6 +9,7 @@ from os.path import dirname, abspath
import logging
import msgspec
import searx.unixthreadname # pylint: disable=unused-import
# Debug
@@ -76,20 +77,22 @@ def get_setting(name: str, default: t.Any = _unset) -> t.Any:
settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
"""
value: dict[str, t.Any] = settings
value = settings
for a in name.split('.'):
if isinstance(value, dict):
value = value.get(a, _unset)
if isinstance(value, msgspec.Struct):
value = getattr(value, a, _unset)
elif isinstance(value, dict):
value = value.get(a, _unset) # pyright: ignore
else:
value = _unset # type: ignore
value = _unset
if value is _unset:
if default is _unset:
raise KeyError(name)
value = default # type: ignore
value = default
break
return value
return value # pyright: ignore
def _is_color_terminal():