1414# Helpers
1515# ======================================================================================
1616load ("@bazel_skylib//lib:paths.bzl" , "paths" )
17+ load ("@bazel_skylib//rules:common_settings.bzl" , "BuildSettingInfo" )
1718load ("@rules_python//sphinxdocs:sphinx_docs_library.bzl" , "sphinx_docs_library" )
1819load ("@rules_python//sphinxdocs/private:sphinx_docs_library_info.bzl" , "SphinxDocsLibraryInfo" )
1920load ("//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)
0 commit comments