Skip to content

Commit 0dd5e75

Browse files
authored
Merge pull request #1442 from ROCm/alexxu12/rocm-ds-version-list
feat: add version list to rocm-ds flavor & improve header version & fix header banner display error
2 parents 3f22cfe + 78213e8 commit 0dd5e75

7 files changed

Lines changed: 56 additions & 25 deletions

File tree

src/rocm_docs/projects.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from sphinx.config import Config
3131
from sphinx.errors import ExtensionError
3232

33-
from rocm_docs import formatting, util
33+
from rocm_docs import formatting, theme, util
3434

3535
if sys.version_info < (3, 11):
3636
import importlib.abc as importlib_abc
@@ -405,15 +405,24 @@ def _get_context(
405405

406406

407407
def _update_theme_configs(
408-
app: Sphinx, current_project: _Project | None, current_branch: str
408+
app: Sphinx,
409+
current_project: _Project | None,
410+
current_branch: str,
411+
flavor: str,
409412
) -> None:
410413
"""Update configurations for use in theme.py"""
411-
latest_version = requests.get(
412-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/latest_version.txt"
413-
).text.strip("\r\n")
414-
latest_version_string = f"docs-{latest_version}"
414+
latest_version_list = requests.get(
415+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/latest_version.txt"
416+
).text.strip()
417+
latest_version_dict = theme._parse_version(latest_version_list)
418+
latest_version = latest_version_dict.get(flavor, "latest")
419+
latest_version_string_list = ["latest"]
420+
if latest_version != "latest":
421+
# Some component's docs branch has "docs-" prefix, others do not
422+
latest_version_string_list += [f"docs-{latest_version}", latest_version]
423+
415424
release_candidate = requests.get(
416-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/release_candidate.txt"
425+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/release_candidate.txt"
417426
).text.strip("\r\n")
418427
release_candidate_string = f"docs-{release_candidate}"
419428

@@ -423,7 +432,7 @@ def _update_theme_configs(
423432

424433
doc_branch_pattern = r"^docs-\d+\.\d+\.\d+$"
425434

426-
if current_branch in [latest_version_string, "latest"]:
435+
if current_branch in latest_version_string_list:
427436
app.config.projects_version_type = util.VersionType.LATEST_RELEASE
428437
elif current_branch.startswith(release_candidate_string):
429438
app.config.projects_version_type = util.VersionType.RELEASE_CANDIDATE
@@ -509,11 +518,20 @@ def _update_config(app: Sphinx, _: Config) -> None:
509518
Path(app.srcdir, app.config.external_toc_path),
510519
context,
511520
)
521+
522+
if not config_provided_by_user(app, "html_theme_options"):
523+
app.config.html_theme_options = {"flavor": "rocm"}
524+
512525
# Store the context to be referenced later
513526
app.config.projects_context = context
514527

515528
_set_doxygen_html(app, current_project)
516-
_update_theme_configs(app, current_project, branch)
529+
_update_theme_configs(
530+
app,
531+
current_project,
532+
branch,
533+
app.config.html_theme_options.get("flavor", "rocm"),
534+
)
517535

518536

519537
def _setup_projects_context(

src/rocm_docs/rocm_docs_theme/flavors/ai-developer-hub/header.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
55
{% set version_name = "Future Release" %}
66
{% elif branch == "latest" %}
7-
{% set version_name = "" %}
7+
{% set version_name = latest_version["ai-developer-hub"] %}
88
{% else %}
99
{% set version_name = branch %}
1010
{% endif %}

src/rocm_docs/rocm_docs_theme/flavors/instinct/header.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
55
{% set version_name = "Future Release" %}
66
{% elif branch == "latest" %}
7-
{% set version_name = latest_version %}
7+
{% set version_name = latest_version["rocm"] %}
88
{% else %}
99
{% set version_name = branch %}
1010
{% endif %}

src/rocm_docs/rocm_docs_theme/flavors/rocm-ds/header.jinja

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
55
{% set version_name = "Future Release" %}
66
{% elif branch == "latest" %}
7-
{% set version_name = "25.05" %}
7+
{% set version_name = latest_version["rocm-ds"] %}
88
{% else %}
99
{% set version_name = branch %}
1010
{% endif %}
@@ -20,9 +20,7 @@
2020
{% set repo_url = repo_url|replace("http://", "https://") %}
2121

2222
{% macro version_list() -%}
23-
{% if theme_version_list_link %}
24-
<a class="header-all-versions" href="{{ theme_version_list_link }}">Version List</a>
25-
{% endif %}
23+
<a class="header-all-versions" href="https://rocm.docs.amd.com/projects/rocm-ds/en/latest/release/versions.html">Version List</a>
2624
{%- endmacro -%}
2725

2826
{%

src/rocm_docs/rocm_docs_theme/flavors/rocm-ls/header.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
55
{% set version_name = "Future Release" %}
66
{% elif branch == "latest" %}
7-
{% set version_name = "25.09" %}
7+
{% set version_name = latest_version["rocm-ls"] %}
88
{% else %}
99
{% set version_name = branch %}
1010
{% endif %}

src/rocm_docs/rocm_docs_theme/flavors/rocm/header.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
55
{% set version_name = "Future Release" %}
66
{% elif branch == "latest" %}
7-
{% set version_name = latest_version %}
7+
{% set version_name = latest_version["rocm"] %}
88
{% else %}
99
{% set version_name = branch.replace('-', ' ').title() %}
1010
{% endif %}

src/rocm_docs/theme.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,35 @@ def _get_version_from_url(url: str) -> str:
4141
return ""
4242

4343

44+
def _parse_version(version_string: str) -> dict[str, str]:
45+
"""Parse latest_version.txt and output a dictionary of site_name : latest_version.
46+
47+
Example:
48+
{"ROCm": "7.0.2", "AI-Developer-Hub": "v7.0", "ROCm-DS": "25.05"}
49+
"""
50+
header_latest_version_list = [
51+
site_version.split(":") for site_version in version_string.split("\n")
52+
]
53+
return {
54+
site_version_pair[0].strip(): site_version_pair[1].strip()
55+
for site_version_pair in header_latest_version_list
56+
}
57+
58+
4459
def _add_custom_context(
4560
app: Sphinx, # noqa: ARG001
4661
pagename: str, # noqa: ARG001
4762
templatename: str, # noqa: ARG001
48-
context: dict[str, str],
63+
context: dict[str, str | dict[str, str]],
4964
doctree: object, # noqa: ARG001
5065
) -> None:
51-
header_latest_version = _get_version_from_url(
52-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/latest_version.txt"
66+
latest_version_list = _get_version_from_url(
67+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/latest_version.txt"
5368
)
54-
context["header_latest_version"] = header_latest_version
69+
context["header_latest_version"] = _parse_version(latest_version_list)
5570

5671
header_release_candidate_version = _get_version_from_url(
57-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/release_candidate.txt"
72+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/release_candidate.txt"
5873
)
5974
context["header_release_candidate_version"] = (
6075
header_release_candidate_version
@@ -161,11 +176,11 @@ def _update_theme_options(app: Sphinx) -> None:
161176
)
162177

163178
header_latest_version = _get_version_from_url(
164-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/latest_version.txt"
179+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/latest_version.txt"
165180
)
166181

167182
header_release_candidate_version = _get_version_from_url(
168-
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/data/release_candidate.txt"
183+
"https://raw.githubusercontent.com/ROCm/rocm-docs-core/new_data/release_candidate.txt"
169184
)
170185

171186
default_config_opts = {
@@ -174,7 +189,7 @@ def _update_theme_options(app: Sphinx) -> None:
174189
"notfound_context": {"title": "404 - Page Not Found"},
175190
"notfound_template": "404.html",
176191
"html_context": {
177-
"header_latest_version": header_latest_version,
192+
"header_latest_version": _parse_version(header_latest_version),
178193
"header_release_candidate_version": header_release_candidate_version,
179194
},
180195
}

0 commit comments

Comments
 (0)