Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 58 additions & 25 deletions .github/workflows/yaml_merger.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,90 @@
import yaml
from typing import List, Dict, Any
from typing import Any, Dict, List

import sys

import yaml


class ListFlowStyleRepresenter:
"""
Custom representer to force specific flow style for nested lists
"""

def __init__(self):
self.add_representer()

def represent_list(self, dumper, data):
# Check if this is a nested list containing strings/patterns
if data and isinstance(data[0], str):
return dumper.represent_sequence('tag:yaml.org,2002:seq', data, flow_style=True)
return dumper.represent_sequence('tag:yaml.org,2002:seq', data, flow_style=False)
return dumper.represent_sequence(
"tag:yaml.org,2002:seq", data, flow_style=True
)
return dumper.represent_sequence(
"tag:yaml.org,2002:seq", data, flow_style=False
)

def add_representer(self):
yaml.add_representer(list, self.represent_list)


def load_yaml(file_path: str) -> Any:
"""
Load YAML file with error handling.
"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, "r", encoding="utf-8") as f:
return yaml.safe_load(f)
except yaml.scanner.ScannerError as e:
print(f"\nYAML Syntax Error in {file_path}:")
print(f"Line {e.problem_mark.line + 1}, Column {e.problem_mark.column + 1}")
print(
f"Line {e.problem_mark.line + 1}, Column {e.problem_mark.column + 1}"
)
print(f"Error: {e.problem}")
return None
except Exception as e:
print(f"\nError loading {file_path}:")
print(str(e))
return None

def merge_matrix_entries(default_entries: List[Dict], user_entries: List[Dict]) -> List[Dict]:

def merge_matrix_entries(
default_entries: List[Dict], user_entries: List[Dict]
) -> List[Dict]:
"""
Merge matrix entries, combining sources only for entries with matching names.
- Skip merging if the 'sources' list in the user entries is empty.
- If the main configuration has an empty 'sources' list, replace it with the user's list.
"""
result = default_entries.copy()
default_map = {entry.get('name'): entry for entry in result}
default_map = {entry.get("name"): entry for entry in result}

for user_entry in user_entries:
user_name = user_entry.get('name')
user_name = user_entry.get("name")
if user_name and user_name in default_map:
if 'sources' in user_entry:
user_sources = user_entry['sources']
if "sources" in user_entry:
user_sources = user_entry["sources"]

# Skip merging if user sources are empty
if not user_sources or all(not source for source in user_sources):
if not user_sources or all(
not source for source in user_sources
):
continue

# Check the main configuration's sources
default_sources = default_map[user_name].get('sources', [])
default_sources = default_map[user_name].get("sources", [])

# If the main config's sources are empty, replace them
if not default_sources or all(not source for source in default_sources):
default_map[user_name]['sources'] = user_sources
if not default_sources or all(
not source for source in default_sources
):
default_map[user_name]["sources"] = user_sources
else:
# Otherwise, merge the lists
default_map[user_name]['sources'].extend(user_sources)
default_map[user_name]["sources"].extend(user_sources)

return result


def merge_configs(default: Any, user: Any) -> Any:
"""
Recursively merge two configurations.
Expand All @@ -83,13 +102,18 @@ def merge_configs(default: Any, user: Any) -> Any:
return result

if isinstance(default, list) and isinstance(user, list):
if (len(default) > 0 and isinstance(default[0], dict) and
'name' in default[0] and 'sources' in default[0]):
if (
len(default) > 0
and isinstance(default[0], dict)
and "name" in default[0]
and "sources" in default[0]
):
return merge_matrix_entries(default, user)
return default + user

return user


def save_yaml(data: Dict, file_path: str) -> bool:
"""
Save YAML file with custom formatting.
Expand All @@ -98,21 +122,30 @@ def save_yaml(data: Dict, file_path: str) -> bool:
# Initialize custom representer
ListFlowStyleRepresenter()

with open(file_path, 'w', encoding='utf-8') as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False, allow_unicode=True)
with open(file_path, "w", encoding="utf-8") as f:
yaml.dump(
data,
f,
default_flow_style=False,
sort_keys=False,
allow_unicode=True,
)
return True
except Exception as e:
print(f"\nError saving {file_path}:")
print(str(e))
return False

if __name__ == '__main__':

if __name__ == "__main__":
import argparse

parser = argparse.ArgumentParser(description='Merge spellcheck YAML configurations')
parser.add_argument('template', help='Path to template YAML configuration')
parser.add_argument('local', help='Path to local YAML configuration')
parser.add_argument('output', help='Path to save merged configuration')
parser = argparse.ArgumentParser(
description="Merge spellcheck YAML configurations"
)
parser.add_argument("template", help="Path to template YAML configuration")
parser.add_argument("local", help="Path to local YAML configuration")
parser.add_argument("output", help="Path to save merged configuration")

args = parser.parse_args()

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3.12

default_install_hook_types: [pre-commit, commit-msg]
default_stages: [commit]
Expand Down
8 changes: 2 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ decli==0.6.3
# via commitizen
decorator==5.2.1
# via ipython
deprecated==1.2.18
# via pygithub
distlib==0.4.0
# via virtualenv
docutils==0.21.2
Expand Down Expand Up @@ -106,6 +104,7 @@ imagesize==1.4.1
# via sphinx
importlib-metadata==8.7.0
# via
# commitizen
# jupyter-cache
# myst-nb
iniconfig==2.1.0
Expand Down Expand Up @@ -200,7 +199,6 @@ packaging==25.0
# commitizen
# ipykernel
# matplotlib
# pydata-sphinx-theme
# pytest
# sphinx
parso==0.8.4
Expand Down Expand Up @@ -248,6 +246,7 @@ pygments==2.19.2
# ipython
# mpire
# pydata-sphinx-theme
# pytest
# sphinx
pyjson5==1.6.9
# via doxysphinx
Expand Down Expand Up @@ -363,7 +362,6 @@ tqdm==4.67.1
# via mpire
traitlets==5.14.3
# via
# comm
# ipykernel
# ipython
# jupyter-client
Expand All @@ -390,8 +388,6 @@ wcwidth==0.2.13
# via prompt-toolkit
wheel==0.45.1
# via pip-tools
wrapt==1.17.3
# via deprecated
zipp==3.23.0
# via importlib-metadata

Expand Down
3 changes: 3 additions & 0 deletions src/rocm_docs/data/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ projects:
aqlprofile:
target: https://rocm.docs.amd.com/projects/aqlprofile/en/${version}
development_branch: amd-staging
enterprise-ai:
target: https://enterprise-ai.docs.amd.com/en/${version}
development_branch: main
composable_kernel: https://rocm.docs.amd.com/projects/composable_kernel/en/${version}
gpuaidev:
target: https://rocm.docs.amd.com/projects/ai-developer-hub/en/${version}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% macro license_link() -%}{%- endmacro -%}
33 changes: 33 additions & 0 deletions src/rocm_docs/rocm_docs_theme/flavors/enterprise-ai/header.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% macro top_level_header(branch, latest_version, release_candidate_version) -%}
{% if docs_header_version %}
{% set version_name = docs_header_version %}
{% elif branch in ["develop", "master", "main", "amd-master", "amd-staging"] %}
{% set version_name = "Future Release" %}
{% elif branch == "latest" %}
{% set version_name = latest_version %}
{% else %}
{% set version_name = branch %}
{% endif %}
<a class="klavika-font hover-opacity" href="{{ projects['enterprise-ai'] }}">Enterprise AI</a>
{%- endmacro -%}


{% set repo_url = repo_url|replace("http://", "https://") %}

{% macro version_list() -%}
{% if theme_version_list_link %}
<a class="header-all-versions" href="{{ theme_version_list_link }}">Version List</a>
{% endif %}
{%- endmacro -%}

{%
set nav_secondary_items = theme_nav_secondary_items if theme_nav_secondary_items else {
"GitHub": theme_repository_url if theme_repository_url else "#",
"Community": "https://github.com/ROCm/ROCm/discussions",
"Blogs": "https://rocm.blogs.amd.com/",
"Developer Hub": "https://www.amd.com/en/developer/resources/rocm-hub.html",
"ROCm&#8482; Docs": "https://rocm.docs.amd.com",
"Enterprise AI": "https://enterprise-ai.docs.amd.com",
"Support": (theme_repository_url + "/issues/new/choose") if theme_repository_url else "#"
}
%}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{%
set main_doc_link = ("Enterprise AI", projects['enterprise-ai'])
%}
3 changes: 2 additions & 1 deletion src/rocm_docs/rocm_docs_theme/flavors/instinct/header.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ set nav_secondary_items = theme_nav_secondary_items if theme_nav_secondary_items
"GitHub": theme_repository_url if theme_repository_url else "#",
"Community": "https://github.com/ROCm/ROCm/discussions",
"Blogs": "https://rocm.blogs.amd.com/",
"ROCm Developer Hub": "https://www.amd.com/en/developer/resources/rocm-hub.html",
"Developer Hub": "https://www.amd.com/en/developer/resources/rocm-hub.html",
"ROCm&#8482; Docs": "https://rocm.docs.amd.com",
"Enterprise AI": "https://enterprise-ai.docs.amd.com",
"Support": (theme_repository_url + "/issues/new/choose") if theme_repository_url else "#"
}
%}
Loading