core: Replace legacy INI config system with Pydantic-based TOML configuration.

This is a huge configuration refactoring.

The configuration system now uses Pydantic settings, with better validation, better
support for environment variables and other goodies.

The main config files now use TOML instead of INI, this allow for better handling of
complex types, notably dict.

Plugins, components and frontends can declare their config settings in a class which will
be imported dynamically.
This commit is contained in:
Goffi 2025-11-30 12:27:35 +01:00
commit 6a7b7bc36a

View file

@ -114,8 +114,24 @@ class OrderedSet(collections.abc.MutableSet):
self._dict.update({i: None for i in items})
def parse_size(size):
"""Parse a file size with optional multiple symbole"""
def parse_size(size: str) -> int:
"""Parse a file size with optional unit.
The size string can contain an optional unit suffix. Units are case-insensitive.
Spaces within the size string are ignored.
Examples::
"1024" -> 1024
"1 kb" -> 1000
"1 ko" -> 1000
"2 Mb" -> 2000000
"1 MiB" -> 1048576
@param size: Size string with optional unit (e.g. "1024", "1 kb", "2 Mb", "1 MiB")
@return: Size in bytes
@raise ValueError: If the size string is invalid or contains unknown units
"""
try:
return int(size)
except ValueError:
@ -138,13 +154,13 @@ def parse_size(size):
multiplier = size_units[symbol.lower()]
except KeyError:
raise ValueError(
"unknown size multiplier symbole: {symbol!r} (size: {size!r})"
"unknown size multiplier symbol: {symbol!r} (size: {size!r})"
)
else:
return number * multiplier
return number
except Exception as e:
raise ValueError(f"invalid size: {e}")
raise ValueError(f"invalid size ({size!r}): {e}")
def get_size_multiplier(size: int | str, suffix="o"):