@@ -263,7 +263,8 @@ def setup(app: Sphinx) -> dict[str, Any]:
263263 # Make connections to events
264264 app .connect ("config-inited" , load_config_from_toml , priority = 10 ) # runs early
265265 app .connect ("config-inited" , load_config )
266- app .connect ("config-inited" , check_configuration )
266+ app .connect ("config-inited" , merge_default_configs )
267+ app .connect ("config-inited" , check_configuration , priority = 600 ) # runs late
267268
268269 app .connect ("env-before-read-docs" , prepare_env )
269270 app .connect ("env-before-read-docs" , load_external_needs )
@@ -589,6 +590,31 @@ def prepare_env(app: Sphinx, env: BuildEnvironment, _docnames: list[str]) -> Non
589590 # Otherwise, the service may get registered later by an external sphinx-needs extension
590591 services .register (name , service ["class" ], ** service ["class_init" ])
591592
593+ # Set time measurement flag
594+ if needs_config .debug_measurement :
595+ debug .START_TIME = timer () # Store the rough start time of Sphinx build
596+ debug .EXECUTE_TIME_MEASUREMENTS = True
597+
598+ if needs_config .debug_filters :
599+ with contextlib .suppress (FileNotFoundError ):
600+ Path (str (app .outdir ), "debug_filters.jsonl" ).unlink ()
601+
602+
603+ def merge_default_configs (_app : Sphinx , config : Config ) -> None :
604+ """Merge built-in defaults with user configuration."""
605+ needs_config = NeedsSphinxConfig (config )
606+
607+ needs_config .layouts = {** LAYOUTS , ** needs_config .layouts }
608+
609+ needs_config .flow_configs = {
610+ ** NEEDFLOW_CONFIG_DEFAULTS ,
611+ ** needs_config .flow_configs ,
612+ }
613+ needs_config .graphviz_styles = {
614+ ** GRAPHVIZ_STYLE_DEFAULTS ,
615+ ** needs_config .graphviz_styles ,
616+ }
617+
592618 # Register built-in functions
593619 for need_common_func in NEEDS_COMMON_FUNCTIONS :
594620 _NEEDS_CONFIG .add_function (need_common_func )
@@ -632,28 +658,9 @@ def prepare_env(app: Sphinx, env: BuildEnvironment, _docnames: list[str]) -> Non
632658 )
633659
634660 needs_config .extra_links = common_links + needs_config .extra_links
635- needs_config .layouts = {** LAYOUTS , ** needs_config .layouts }
636-
637- needs_config .flow_configs = {
638- ** NEEDFLOW_CONFIG_DEFAULTS ,
639- ** needs_config .flow_configs ,
640- }
641- needs_config .graphviz_styles = {
642- ** GRAPHVIZ_STYLE_DEFAULTS ,
643- ** needs_config .graphviz_styles ,
644- }
645-
646- # Set time measurement flag
647- if needs_config .debug_measurement :
648- debug .START_TIME = timer () # Store the rough start time of Sphinx build
649- debug .EXECUTE_TIME_MEASUREMENTS = True
650-
651- if needs_config .debug_filters :
652- with contextlib .suppress (FileNotFoundError ):
653- Path (str (app .outdir ), "debug_filters.jsonl" ).unlink ()
654661
655662
656- def check_configuration (_app : Sphinx , config : Config ) -> None :
663+ def check_configuration (app : Sphinx , config : Config ) -> None :
657664 """Checks the configuration for invalid options.
658665
659666 E.g. defined need-option, which is already defined internally
0 commit comments