fix: default server settings prevent env var config (#1234)

Change configuration source priorities to:

- cli
- environment vars
- dotenv settings
- config file settings
- init settings

By this the environment vars supersede any configuration var
provided by the configuration file or by the initialisation
with pydantic.

The test_config.py::test_computed_path was fixed to to not
use the defaul env var overwrite defined by conftest.py.
This seemed to indicate non working env vars, but in fact
was a test setupt fault.

Besides this fix there are other fixes and changes added:

* fix: exclude computed fields when merging settings

  Pydantic may overwrite settings by values given for computed
  fields and use these values instead of re-computing the field.
  Avoid computed fields in merging settings.

* chore: improve Windows compatability of development setup

  Improve scripts to better run also on Windows. When doing path
  checks keep compatibility also to Windows pathes. A lot of
  changes to avoid the famous Windows CRLF handling and keep
  line endings to LF.

* chore: add development hint for Windows

  Windows developers should set core.autocrlf to false.

* chore: update version

Signed-off-by: b0661 <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2026-08-16 13:56:25 +02:00
committed by GitHub
parent 269d2162a9
commit 886c93c92b
18 changed files with 525 additions and 345 deletions
+7 -1
View File
@@ -66,6 +66,9 @@ def merge_models(source: BaseModel, update_dict: dict[str, Any]) -> dict[str, An
Nested dictionaries are merged recursively.
Lists in update_dict replace source lists entirely.
Computed fields are excluded from the source model because they represent
derived state rather than configuration input.
Args:
source (BaseModel): Pydantic model instance serving as the source.
update_dict (dict[str, Any]): Dictionary with updates to apply.
@@ -91,7 +94,10 @@ def merge_models(source: BaseModel, update_dict: dict[str, Any]) -> dict[str, An
# For other types or if update_data is None, override source_data
return update_data
source_dict = source.model_dump(exclude_unset=True)
source_dict = source.model_dump(
exclude_unset=True,
exclude_computed_fields=True,
)
merged_result = deep_merge(source_dict, deepcopy(update_dict))
return merged_result
+1 -1
View File
@@ -276,7 +276,7 @@ def _version_date_hash() -> tuple[datetime, str]:
Returns:
lattest commit date and SHA256 hash of the project files
"""
if not str(DIR_PACKAGE_ROOT).endswith("src/akkudoktoreos"):
if DIR_PACKAGE_ROOT.parts[-2:] != ("src", "akkudoktoreos"): # check path Windows friendly
error_msg = f"DIR_PACKAGE_ROOT does not end with src/akkudoktoreos: {DIR_PACKAGE_ROOT}"
raise ValueError(error_msg)