Skip to content

Commit 9a5e2c9

Browse files
authored
docs: add user and repo as parameters to incremental (#70)
1 parent de362c1 commit 9a5e2c9

4 files changed

Lines changed: 55 additions & 19 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ jobs:
3838
id-token: write
3939

4040
with:
41-
bazel-target: "//docs:github_pages__release"
41+
bazel-target: "//docs:incremental_release -- --github_user=${{ github.repository_owner }} --github_repo=${{ github.event.repository.name }}"
4242
retention-days: 3

src/extensions/score_layout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def update_config(app: Sphinx, _config: Any):
3232
app.config.needs_layouts = sphinx_options.needs_layouts
3333
app.config.needs_global_options = sphinx_options.needs_global_options
3434
app.config.html_theme = html_options.html_theme
35-
app.config.html_context = html_options.html_context
35+
app.config.html_context = html_options.return_html_context(app)
3636
app.config.html_theme_options = html_options.return_html_theme_options(app)
3737

3838
# Setting HTML static path

src/extensions/score_layout/html_options.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def return_html_theme_options(app: Sphinx) -> dict[str, object]:
17-
return {
17+
theme_options = {
1818
"navbar_align": "content",
1919
"header_links_before_dropdown": 5,
2020
"icon_links": [
@@ -28,20 +28,33 @@ def return_html_theme_options(app: Sphinx) -> dict[str, object]:
2828
# https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/source-buttons.html#add-an-edit-button
2929
"use_edit_page_button": True,
3030
"collapse_navigation": True,
31-
# Enable version switcher
32-
"switcher": {
33-
"json_url": (
34-
f"https://{html_context['github_user']}.github.io/"
35-
f"{html_context['github_repo']}/versions.json"
36-
), # URL to JSON file, hardcoded for now
37-
"version_match": app.config.release,
38-
},
39-
"navbar_end": ["theme-switcher", "navbar-icon-links", "version-switcher"],
4031
"logo": {
4132
"text": "Eclipse S-CORE",
4233
},
4334
}
4435

36+
# Enable version switcher if github_user and github_repo are provided via CLI
37+
if (
38+
app.config.html_context.get("github_user") != "dummy"
39+
and app.config.html_context.get("github_repo") != "dummy"
40+
):
41+
theme_options["switcher"] = {
42+
"json_url": (
43+
f"https://{app.config.html_context['github_user']}.github.io/"
44+
f"{app.config.html_context['github_repo']}/versions.json"
45+
), # URL to JSON file, hardcoded for now
46+
"version_match": app.config.release,
47+
}
48+
theme_options["navbar_end"] = [
49+
"theme-switcher",
50+
"navbar-icon-links",
51+
"version-switcher",
52+
]
53+
else:
54+
theme_options["navbar_end"] = ["theme-switcher", "navbar-icon-links"]
55+
56+
return theme_options
57+
4558

4659
html_theme = "pydata_sphinx_theme" # "alabaster"
4760
html_static_path = ["src/assets", "_assets"]
@@ -54,10 +67,16 @@ def return_html_theme_options(app: Sphinx) -> dict[str, object]:
5467
# html_logo = "_assets/S-CORE_Logo_white.svg"
5568

5669

57-
html_context = {
58-
# "github_url": "https://github.com", # or your GitHub Enterprise site
59-
"github_user": "eclipse-score",
60-
"github_repo": "score",
61-
"github_version": "main",
62-
"doc_path": "docs",
63-
}
70+
def return_html_context(app: Sphinx) -> dict[str, str]:
71+
if not hasattr(app.config, "html_context") or (
72+
not app.config.html_context.get("github_user")
73+
and not app.config.html_context.get("github_repo")
74+
):
75+
return {
76+
# still required for use_edit_page_button and other elements except version switcher
77+
"github_user": "dummy",
78+
"github_repo": "dummy",
79+
"github_version": "main",
80+
"doc_path": "docs",
81+
}
82+
return app.config.html_context

src/incremental.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def transform_env_str_to_dict(external_needs_source: str) -> list[dict[str, str]
6565
parser.add_argument(
6666
"--debug", help="Enable Debugging via debugpy", action="store_true"
6767
)
68+
# optional GitHub user forwarded from the Bazel CLI
69+
parser.add_argument(
70+
"--github_user",
71+
help="GitHub username to embed in the Sphinx build",
72+
)
73+
parser.add_argument(
74+
"--github_repo",
75+
help="GitHub repository to embed in the Sphinx build",
76+
)
6877
args = parser.parse_args()
6978
if args.debug:
7079
debugpy.listen(("0.0.0.0", args.debug_port))
@@ -87,6 +96,14 @@ def transform_env_str_to_dict(external_needs_source: str) -> list[dict[str, str]
8796
get_env("CONF_DIRECTORY"),
8897
f"--define=external_needs_source={json.dumps(transform_env_str_to_dict(get_env('EXTERNAL_NEEDS_INFO')))}",
8998
]
99+
100+
# configure sphinx build with GitHub user and repo from CLI
101+
if args.github_user and args.github_repo:
102+
base_arguments.append(f"-A=github_user={args.github_user}")
103+
base_arguments.append(f"-A=github_repo={args.github_repo}")
104+
base_arguments.append(f"-A=github_version=main")
105+
base_arguments.append(f"-A=doc_path=docs")
106+
90107
action = get_env("ACTION")
91108
if action == "live_preview":
92109
sphinx_autobuild_main(

0 commit comments

Comments
 (0)