Skip to content

Commit c6e9f81

Browse files
authored
Fix metamodel path and Needs defaults (eclipse-score#548)
* fix: external metamodel.yaml path Sphinx-build changes working dir to where conf.py is. Bazel provides a path relative to the workspace. By making the path absolute it works out. * fix: clear Sphinx-Needs defaults
1 parent 35caeac commit c6e9f81

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/extensions/score_metamodel/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
294314
def 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)

src/incremental.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def get_env(name: str) -> str:
8686

8787
metamodel_yaml = os.environ.get("SCORE_METAMODEL_YAML", "")
8888
if metamodel_yaml:
89+
# Normalize to absolute path so it resolves correctly after Sphinx changes cwd
90+
if not os.path.isabs(metamodel_yaml):
91+
metamodel_yaml = workspace + metamodel_yaml
92+
metamodel_yaml = os.path.abspath(metamodel_yaml)
8993
base_arguments.append(f"--define=score_metamodel_yaml={metamodel_yaml}")
9094

9195
# configure sphinx build with GitHub user and repo from CLI

0 commit comments

Comments
 (0)