Skip to content

Commit 5293d13

Browse files
feat: make Mermaid support configurable and default disabled
1 parent 89fbbad commit 5293d13

5 files changed

Lines changed: 35 additions & 4 deletions

File tree

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ build:info --//bazel/rules/rules_score:verbosity=info
2323
# debug build: complete output including debug/trace from all tools
2424
build:debug --//bazel/rules/rules_score:verbosity=debug
2525

26+
# Enable Mermaid diagrams in Sphinx documentation builds
27+
build:mermaid --//bazel/rules/rules_score:enable_mermaid
2628
# Standard combined coverage (Rust + Python, no Ferrocene required)
2729
# Usage: bazel coverage --config=coverage <targets>
2830
# Then run: bazel run //coverage:combined_report

bazel/rules/rules_score/BUILD

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313

14-
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
14+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
1515
load("@pip_rules_score//:requirements.bzl", "requirement")
1616
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
1717
load(
@@ -200,3 +200,13 @@ string_flag(
200200
],
201201
visibility = ["//visibility:public"],
202202
)
203+
204+
# ---------------------------------------------------------------------------
205+
# Build setting: enable Mermaid diagrams in Sphinx documentation
206+
# ---------------------------------------------------------------------------
207+
208+
bool_flag(
209+
name = "enable_mermaid",
210+
build_setting_default = False,
211+
visibility = ["//visibility:public"],
212+
)

bazel/rules/rules_score/private/sphinx_module.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# Helpers
1515
# ======================================================================================
1616
load("@bazel_skylib//lib:paths.bzl", "paths")
17+
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1718
load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
1819
load("@rules_python//sphinxdocs/private:sphinx_docs_library_info.bzl", "SphinxDocsLibraryInfo")
1920
load("//bazel/rules/rules_score:providers.bzl", "FilteredExecpathInfo", "SphinxIndexFileInfo", "SphinxModuleInfo", "SphinxNeedsInfo")
@@ -42,12 +43,18 @@ def _create_config_py(ctx):
4243
config_file = ctx.actions.declare_file(ctx.label.name + "/conf.py")
4344
template = sphinx_toolchain.conf_template.files.to_list()[0]
4445

45-
# Read template and substitute PROJECT_NAME
46+
# Get the enable_mermaid flag value
47+
enable_mermaid = ctx.attr._enable_mermaid[BuildSettingInfo].value
48+
# Convert boolean to string representation for template
49+
enable_mermaid_str = "True" if enable_mermaid else "False"
50+
51+
# Read template and substitute PROJECT_NAME and ENABLE_MERMAID
4652
ctx.actions.expand_template(
4753
template = template,
4854
output = config_file,
4955
substitutions = {
5056
"{PROJECT_NAME}": ctx.label.name.replace("_", " ").title(),
57+
"{ENABLE_MERMAID}": enable_mermaid_str,
5158
},
5259
)
5360
return config_file
@@ -69,6 +76,10 @@ sphinx_rule_attrs = dict(
6976
"deps": attr.label_list(
7077
doc = "List of other sphinx_module targets this module depends on for intersphinx.",
7178
),
79+
"_enable_mermaid": attr.label(
80+
default = Label("//bazel/rules/rules_score:enable_mermaid"),
81+
doc = "Enable Mermaid diagrams in Sphinx documentation.",
82+
),
7283
},
7384
**VERBOSITY_ATTR
7485
)

bazel/rules/rules_score/templates/conf.template.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@
4747
)
4848

4949
# Sphinx extensions - comprehensive list for SCORE modules
50+
# Note: sphinxcontrib.mermaid is conditionally included based on {ENABLE_MERMAID} setting
5051
extensions = [
5152
"sphinx_module_ext",
5253
"sphinx_needs",
5354
"sphinx_design",
5455
"myst_parser",
55-
"sphinxcontrib.mermaid",
5656
"sphinxcontrib.plantuml",
5757
"trlc",
5858
"clickable_plantuml",
5959
]
6060

61+
# Conditionally add mermaid extension if enabled
62+
if {ENABLE_MERMAID}:
63+
extensions.append("sphinxcontrib.mermaid")
64+
print("Extensions: " + str(extensions))
6165
# MyST parser extensions
6266
myst_enable_extensions = ["colon_fence"]
6367

bazel/rules/rules_score/test/template/conf.template.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
)
3131

3232
# Sphinx extensions - comprehensive list for SCORE modules
33+
# Note: sphinxcontrib.mermaid is conditionally included based on {ENABLE_MERMAID} setting
3334
extensions = [
3435
"sphinx_needs",
3536
"sphinx_design",
3637
"myst_parser",
37-
"sphinxcontrib.mermaid",
3838
"sphinxcontrib.plantuml",
3939
"score_plantuml",
4040
"score_metamodel",
@@ -43,6 +43,10 @@
4343
"score_layout",
4444
]
4545

46+
# Conditionally add mermaid extension if enabled
47+
if {ENABLE_MERMAID}:
48+
extensions.append("sphinxcontrib.mermaid")
49+
4650
# MyST parser extensions
4751
myst_enable_extensions = ["colon_fence"]
4852

0 commit comments

Comments
 (0)