Skip to content

Commit 82ac3e6

Browse files
committed
test
1 parent 11ae0e1 commit 82ac3e6

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

docs/sagemaker/scripts/auto-update-toctree.py

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,65 @@
11
import glob
22
import os
3+
import re
34
from pathlib import Path
45

56

67
def update_toctree_yaml():
8+
input_file = "source/_toctree.yml"
79
output_file = "source/_toctree.yml"
810
dirnames = ["sagemaker-sdk"]
911

10-
with open(output_file, "a") as f:
11-
f.write("# GENERATED CONTENT DO NOT EDIT!\n")
12-
f.write("- title: Examples\n")
13-
f.write(" sections:\n")
14-
15-
for dirname in dirnames:
16-
# Get sorted files excluding index
17-
files = sorted(glob.glob(f"source/examples/{dirname}-*.mdx"))
18-
files = [f for f in files if not f.endswith(f"{dirname}-index.mdx")]
19-
20-
file_entries = []
21-
for file_path in files:
22-
with open(file_path, "r") as mdx_file:
23-
first_line = mdx_file.readline().strip()
24-
if first_line.startswith("# "):
25-
title = first_line[2:].strip()
26-
base_name = Path(file_path).stem
27-
file_entries.append((base_name, title))
28-
else:
29-
print(f"⚠️ Skipping {Path(file_path).name} - missing H1 title")
30-
continue
31-
32-
# Write directory section
33-
f.write(" - title: SageMaker SDK\n")
34-
# f.write(f" local: examples/{dirname}-index\n")
35-
f.write(" isExpanded: true\n")
36-
37-
for idx, (base, title) in enumerate(file_entries):
38-
if idx == 0:
39-
f.write(" sections:\n")
40-
f.write(f" - local: examples/{base}\n")
41-
f.write(f' title: "{title}"\n')
42-
43-
f.write("# END GENERATED CONTENT\n")
12+
# Read the existing content
13+
with open(input_file, "r") as f:
14+
content = f.read()
15+
16+
# Find the position between tutorials and reference sections
17+
tutorials_end = content.find("- sections:\n - local: reference/inference-toolkit")
18+
if tutorials_end == -1:
19+
print("Error: Could not find the reference section in the file")
20+
return
21+
22+
# Generate the new content
23+
new_content = []
24+
new_content.append("# GENERATED CONTENT DO NOT EDIT!")
25+
new_content.append("- title: Examples")
26+
new_content.append(" sections:")
27+
28+
for dirname in dirnames:
29+
# Get sorted files excluding index
30+
files = sorted(glob.glob(f"source/examples/{dirname}-*.mdx"))
31+
files = [f for f in files if not f.endswith(f"{dirname}-index.mdx")]
32+
33+
file_entries = []
34+
for file_path in files:
35+
with open(file_path, "r") as mdx_file:
36+
first_line = mdx_file.readline().strip()
37+
if first_line.startswith("# "):
38+
title = first_line[2:].strip()
39+
base_name = Path(file_path).stem
40+
file_entries.append((base_name, title))
41+
else:
42+
print(f"⚠️ Skipping {Path(file_path).name} - missing H1 title")
43+
continue
44+
45+
# Write directory section
46+
new_content.append(" - title: SageMaker SDK")
47+
new_content.append(" isExpanded: false")
48+
49+
for idx, (base, title) in enumerate(file_entries):
50+
if idx == 0:
51+
new_content.append(" sections:")
52+
new_content.append(f" - local: examples/{base}")
53+
new_content.append(f' title: "{title}"')
54+
55+
new_content.append("# END GENERATED CONTENT")
56+
57+
# Insert the new content
58+
updated_content = content[:tutorials_end] + "\n" + "\n".join(new_content) + "\n" + content[tutorials_end:]
59+
60+
# Write the updated content back to the file
61+
with open(output_file, "w") as f:
62+
f.write(updated_content)
4463

4564

4665
if __name__ == "__main__":

docs/sagemaker/source/_toctree.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,12 @@
4343
isExpanded: false
4444
title: Tutorials
4545
isExpanded: false
46-
- sections:
47-
- local: reference/inference-toolkit
48-
title: Inference Toolkit API
49-
title: Reference
50-
isExpanded: false
46+
5147
# GENERATED CONTENT DO NOT EDIT!
5248
- title: Examples
5349
sections:
5450
- title: SageMaker SDK
55-
isExpanded: true
51+
isExpanded: false
5652
sections:
5753
- local: examples/sagemaker-sdk-deploy-embedding-models
5854
title: "How to deploy Embedding Models to Amazon SageMaker using new Hugging Face Embedding DLC"
@@ -63,3 +59,8 @@
6359
- local: examples/sagemaker-sdk-fine-tune-embedding-models
6460
title: "Fine-tune and deploy embedding models with Amazon SageMaker"
6561
# END GENERATED CONTENT
62+
- sections:
63+
- local: reference/inference-toolkit
64+
title: Inference Toolkit API
65+
title: Reference
66+
isExpanded: false

0 commit comments

Comments
 (0)