11#!/usr/bin/env python3
22"""
3- Process syllabus files and create modified docker-compose files for GitHub Pages .
3+ Process syllabus files and create modified docker-compose files.
44
55For each syllabus file in tutorials/*/notebooks/syllabi/*.ipynb, this script:
661. Copies the corresponding tutorials/*/brev/docker-compose.yml file
772. Modifies it by setting the default-jupyter-url to the syllabus file path
8- 3. Outputs the modified file to _site/{tutorial}/{syllabi-name}/docker-compose.yml
9- 4. Creates an index.html listing all processed files
8+ 3. Outputs the modified file to tutorials/*/notebooks/syllabi/{syllabi-name}-docker-compose.yml
109"""
1110
1211import re
1312from pathlib import Path
14- from collections import defaultdict
1513
1614
1715def modify_docker_compose (content : str , jupyter_url : str ) -> str :
@@ -34,113 +32,8 @@ def modify_docker_compose(content: str, jupyter_url: str) -> str:
3432 return modified
3533
3634
37- def generate_index_html (processed_files : list ) -> str :
38- """
39- Generate an HTML index page listing all processed docker-compose files.
40-
41- Args:
42- processed_files: List of dicts with 'tutorial', 'syllabi', and 'path' keys
43-
44- Returns:
45- HTML content as a string
46- """
47- html = """<!DOCTYPE html>
48- <html lang="en">
49- <head>
50- <meta charset="UTF-8">
51- <meta name="viewport" content="width=device-width, initial-scale=1.0">
52- <title>Syllabi Docker Compose Files</title>
53- <style>
54- body {
55- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
56- max-width: 1200px;
57- margin: 0 auto;
58- padding: 2rem;
59- background-color: #f5f5f5;
60- }
61- h1 {
62- color: #333;
63- border-bottom: 3px solid #76B900;
64- padding-bottom: 0.5rem;
65- }
66- h2 {
67- color: #555;
68- margin-top: 2rem;
69- }
70- .file-list {
71- background: white;
72- border-radius: 8px;
73- padding: 1.5rem;
74- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
75- }
76- .file-item {
77- padding: 1rem;
78- margin: 0.5rem 0;
79- background: #f9f9f9;
80- border-radius: 4px;
81- border-left: 4px solid #76B900;
82- }
83- .file-item a {
84- color: #0066cc;
85- text-decoration: none;
86- font-weight: 500;
87- }
88- .file-item a:hover {
89- text-decoration: underline;
90- }
91- .tutorial-name {
92- color: #888;
93- font-size: 0.9em;
94- margin-top: 0.25rem;
95- }
96- code {
97- background: #eee;
98- padding: 0.2rem 0.4rem;
99- border-radius: 3px;
100- font-size: 0.9em;
101- }
102- </style>
103- </head>
104- <body>
105- <h1>🚀 Syllabi Docker Compose Files</h1>
106- <p>Modified Docker Compose files with pre-configured syllabi for each tutorial.</p>
107- """
108-
109- # Group by tutorial
110- by_tutorial = defaultdict (list )
111- for item in processed_files :
112- by_tutorial [item ['tutorial' ]].append (item )
113-
114- for tutorial in sorted (by_tutorial .keys ()):
115- tutorial_title = tutorial .replace ('-' , ' ' ).title ()
116- html += f"\n <h2>{ tutorial_title } </h2>\n <div class='file-list'>\n "
117-
118- for item in sorted (by_tutorial [tutorial ], key = lambda x : x ['syllabi' ]):
119- syllabi_display = item ['syllabi' ].replace ('_' , ' ' ).replace ('__' , ' - ' )
120- html += f""" <div class='file-item'>
121- <a href="{ item ['path' ]} " download>{ syllabi_display } </a>
122- <div class='tutorial-name'><code>{ item ['path' ]} </code></div>
123- </div>
124- """
125- html += "</div>\n "
126-
127- html += """
128- <hr style="margin-top: 3rem; border: none; border-top: 1px solid #ddd;">
129- <p style="color: #888; font-size: 0.9em;">
130- Generated from the <a href="https://github.com/nvidia/accelerated-computing-hub">Accelerated Computing Hub</a> repository.
131- </p>
132- </body>
133- </html>
134- """
135- return html
136-
137-
13835def main ():
13936 """Main processing function."""
140- # Create output directory
141- output_dir = Path ('_site' )
142- output_dir .mkdir (exist_ok = True )
143-
14437 # Find all tutorials directories
14538 tutorials_base = Path ('tutorials' )
14639
@@ -187,29 +80,20 @@ def main():
18780 # Modify the default-jupyter-url anchor
18881 modified_content = modify_docker_compose (compose_content , syllabi_relative_path )
18982
190- # Create output directory structure
191- syllabi_name = syllabi_file .stem # filename without extension
192- output_subdir = output_dir / tutorial_name / syllabi_name
193- output_subdir .mkdir (parents = True , exist_ok = True )
194-
195- # Write modified docker-compose file
196- output_file = output_subdir / 'docker-compose.yml'
83+ # Write modified docker-compose file next to the syllabi file
84+ # Pattern: /path/to/X.ipynb -> /path/to/X-docker-compose.yml
85+ syllabi_name = syllabi_file .stem # Filename without extension
86+ output_file = syllabi_dir / f"{ syllabi_name } -docker-compose.yml"
19787 with open (output_file , 'w' ) as f :
19888 f .write (modified_content )
19989
20090 processed_files .append ({
20191 'tutorial' : tutorial_name ,
20292 'syllabi' : syllabi_name ,
203- 'path' : f" { tutorial_name } / { syllabi_name } /docker-compose.yml"
93+ 'path' : str ( output_file )
20494 })
20595
206- # Create an index.html file
207- html_content = generate_index_html (processed_files )
208- with open (output_dir / 'index.html' , 'w' ) as f :
209- f .write (html_content )
210-
21196 print (f"\n ✅ Successfully processed { len (processed_files )} syllabi files" )
212- print (f"📁 Output directory: { output_dir .absolute ()} " )
21397
21498 return 0
21599
0 commit comments