in scripts/internal/update_example_tables.py [0:0]
def update_gke_examples(examples):
file_path = "examples/gke/README.md"
with open(file_path, "r") as f:
content = f.read()
for example_type in ["Training", "Inference"]:
examples_list = examples.get("GKE", {}).get(example_type.lower(), [])
pattern = rf"(## {example_type} Examples\n\n)[\s\S]*?(\n\n##|\Z)"
if examples_list:
# Sort examples alphabetically by their basename
sorted_examples = sorted(
examples_list, key=lambda x: os.path.basename(x[0])
)
table = format_table(
["Example", "Title"],
[
(f"[{os.path.basename(path)}](./{os.path.basename(path)})", title)
for path, title in sorted_examples
],
)
replacement = rf"\1{table}\2"
else:
replacement = rf"\1No {example_type.lower()} examples available yet.\2"
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
with open(file_path, "w") as f:
f.write(content.rstrip() + "\n")