@@ -291,6 +291,26 @@ def postprocess_need_links(needs_types_list: list[ScoreNeedType]):
291291 )
292292
293293
294+ def _clear_needs_defaults (app : Sphinx ):
295+ """Clear default need types, links and fields provided by sphinx-needs.
296+
297+ This ensures that only the need types defined in our metamodel are used,
298+ and prevents issues where the defaults get merged with our types and cause
299+ unexpected behavior.
300+ """
301+ default_directives = {"need" , "req" , "spec" , "impl" , "test" }
302+ existing_directives = {nt ["directive" ] for nt in app .config .needs_types }
303+ if existing_directives == default_directives :
304+ app .config .needs_types .clear ()
305+ logger .info ("Cleared default Sphinx-Needs types: %s" , default_directives )
306+ else :
307+ logger .info (
308+ f"Expected default need types { default_directives } not found. "
309+ "Not clearing needs_types to avoid accidentally removing custom types. "
310+ f"Existing directives: { existing_directives } "
311+ )
312+
313+
294314def setup (app : Sphinx ) -> dict [str , str | bool ]:
295315 app .add_config_value ("external_needs_source" , "" , rebuild = "env" )
296316 app .add_config_value ("score_metamodel_yaml" , "" , rebuild = "env" )
@@ -303,6 +323,7 @@ def setup(app: Sphinx) -> dict[str, str | bool]:
303323 metamodel = load_metamodel_data (override_path )
304324
305325 # Extend sphinx-needs config rather than overwriting
326+ _clear_needs_defaults (app )
306327 app .config .needs_types += metamodel .needs_types
307328 app .config .needs_links .update (metamodel .needs_links )
308329 app .config .needs_fields .update (metamodel .needs_fields )
0 commit comments