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
+27 -10
View File
@@ -509,6 +509,8 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
def lazy_config_file_settings() -> dict:
"""Config file settings.
Resolves/ creates config file path.
This function runs at **instance creation**, not class definition. Ensures if ConfigEOS
is recreated this function is run.
"""
@@ -552,13 +554,13 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
is recreated this function is run.
"""
# Updates path to the data directory.
data_folder_settings = {
settings = {
"general": {
"data_folder_path": default_data_folder_path(),
},
}
return data_folder_settings
return settings
def lazy_init_settings() -> dict:
"""Init settings.
@@ -584,7 +586,9 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
logger.debug("Config initialisation with env settings is disabled.")
return {}
return env_settings()
settings = env_settings()
return settings
def lazy_dotenv_settings() -> dict:
"""Dotenv settings.
@@ -596,7 +600,9 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
logger.debug("Config initialisation with dotenv settings is disabled.")
return {}
return dotenv_settings()
settings = dotenv_settings()
return settings
def lazy_file_settings() -> dict:
"""File settings.
@@ -640,18 +646,20 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
logger.debug("Config initialisation with file secret settings is disabled.")
return {}
return file_secret_settings()
settings = file_secret_settings()
return settings
# All the settings sources in priority sequence
# The settings are all lazyly evaluated at instance creation time to allow for
# runtime configuration.
setting_sources = [
lazy_config_cli_settings, # Prio high
lazy_config_file_settings,
lazy_init_settings,
lazy_env_settings,
lazy_dotenv_settings,
lazy_file_settings,
lazy_config_file_settings, # resolves/creates config file path
lazy_file_settings, # actually loads JSON config values
lazy_init_settings,
lazy_data_folder_path_settings,
lazy_file_secret_settings, # Prio low
]
@@ -713,7 +721,11 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
logger.error(error_msg)
raise ValueError(error_msg)
self.merge_settings_from_dict(settings.model_dump(exclude_none=True, exclude_unset=True))
# Exclude None, unset and computed fields from generating settings.
# Pydantic may use even provided computed field values instead of recalculating.
self.merge_settings_from_dict(
settings.model_dump(exclude_none=True, exclude_unset=True, exclude_computed_fields=True)
)
def merge_settings_from_dict(self, data: dict) -> None:
"""Merges the provided dictionary data into the current instance.
@@ -737,7 +749,12 @@ class ConfigEOS(SingletonMixin, SettingsEOSDefaults):
config.merge_settings_from_dict(new_data)
"""
self._setup(**merge_models(self, data))
merged = merge_models(
self,
data,
)
self._setup(**merged)
def reset_settings(self) -> None:
"""Reset all changed settings to environment/config file defaults.