fix(settings): fix nested settings load via environment variables (#1551)

Signed-off-by: Alexander Sokolov <alsokoloff@gmail.com>
This commit is contained in:
Alex Sokolov 2025-05-14 14:42:10 +03:00 committed by GitHub
parent 12dab0a1e8
commit 2efb7a7c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 4 deletions

View File

@ -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()

View 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