fix(settings): fix nested settings load via environment variables (#1551)
Signed-off-by: Alexander Sokolov <alsokoloff@gmail.com>
This commit is contained in:
parent
12dab0a1e8
commit
2efb7a7c06
@ -56,13 +56,15 @@ class DebugSettings(BaseModel):
|
||||
|
||||
|
||||
class AppSettings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_prefix="DOCLING_", env_nested_delimiter="_")
|
||||
model_config = SettingsConfigDict(
|
||||
env_prefix="DOCLING_", env_nested_delimiter="_", env_nested_max_split=1
|
||||
)
|
||||
|
||||
perf: BatchConcurrencySettings
|
||||
debug: DebugSettings
|
||||
perf: BatchConcurrencySettings = BatchConcurrencySettings()
|
||||
debug: DebugSettings = DebugSettings()
|
||||
|
||||
cache_dir: Path = Path.home() / ".cache" / "docling"
|
||||
artifacts_path: Optional[Path] = None
|
||||
|
||||
|
||||
settings = AppSettings(perf=BatchConcurrencySettings(), debug=DebugSettings())
|
||||
settings = AppSettings()
|
||||
|
29
tests/test_settings_load.py
Normal file
29
tests/test_settings_load.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
|
||||
|
||||
def _setup_env():
|
||||
os.environ["DOCLING_PERF_PAGE_BATCH_SIZE"] = "12"
|
||||
os.environ["DOCLING_DEBUG_VISUALIZE_RAW_LAYOUT"] = "True"
|
||||
os.environ["DOCLING_ARTIFACTS_PATH"] = "/path/to/artifacts"
|
||||
|
||||
|
||||
def test_settings():
|
||||
_setup_env()
|
||||
|
||||
import importlib
|
||||
|
||||
import docling.datamodel.settings as m
|
||||
|
||||
# Reinitialize settings module
|
||||
importlib.reload(m)
|
||||
|
||||
# Check top level setting
|
||||
assert str(m.settings.artifacts_path) == "/path/to/artifacts"
|
||||
|
||||
# Check nested set via environment variables
|
||||
assert m.settings.perf.page_batch_size == 12
|
||||
assert m.settings.debug.visualize_raw_layout is True
|
||||
|
||||
# Check nested defaults
|
||||
assert m.settings.perf.doc_batch_size == 2
|
||||
assert m.settings.debug.visualize_ocr is False
|
Loading…
Reference in New Issue
Block a user