Skip to content

Commit 2efb7a7

Browse files
authored
fix(settings): fix nested settings load via environment variables (#1551)
Signed-off-by: Alexander Sokolov <[email protected]>
1 parent 12dab0a commit 2efb7a7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

docling/datamodel/settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ class DebugSettings(BaseModel):
5656

5757

5858
class AppSettings(BaseSettings):
59-
model_config = SettingsConfigDict(env_prefix="DOCLING_", env_nested_delimiter="_")
59+
model_config = SettingsConfigDict(
60+
env_prefix="DOCLING_", env_nested_delimiter="_", env_nested_max_split=1
61+
)
6062

61-
perf: BatchConcurrencySettings
62-
debug: DebugSettings
63+
perf: BatchConcurrencySettings = BatchConcurrencySettings()
64+
debug: DebugSettings = DebugSettings()
6365

6466
cache_dir: Path = Path.home() / ".cache" / "docling"
6567
artifacts_path: Optional[Path] = None
6668

6769

68-
settings = AppSettings(perf=BatchConcurrencySettings(), debug=DebugSettings())
70+
settings = AppSettings()

tests/test_settings_load.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
3+
4+
def _setup_env():
5+
os.environ["DOCLING_PERF_PAGE_BATCH_SIZE"] = "12"
6+
os.environ["DOCLING_DEBUG_VISUALIZE_RAW_LAYOUT"] = "True"
7+
os.environ["DOCLING_ARTIFACTS_PATH"] = "/path/to/artifacts"
8+
9+
10+
def test_settings():
11+
_setup_env()
12+
13+
import importlib
14+
15+
import docling.datamodel.settings as m
16+
17+
# Reinitialize settings module
18+
importlib.reload(m)
19+
20+
# Check top level setting
21+
assert str(m.settings.artifacts_path) == "/path/to/artifacts"
22+
23+
# Check nested set via environment variables
24+
assert m.settings.perf.page_batch_size == 12
25+
assert m.settings.debug.visualize_raw_layout is True
26+
27+
# Check nested defaults
28+
assert m.settings.perf.doc_batch_size == 2
29+
assert m.settings.debug.visualize_ocr is False

0 commit comments

Comments
 (0)