()
| 151 | |
| 152 | |
| 153 | def main(): |
| 154 | parser = argparse.ArgumentParser(description="Generate example MDX files from Jupyter notebooks") |
| 155 | parser.add_argument("notebook_path", help="Path to the Jupyter notebook") |
| 156 | |
| 157 | notebook_path = parser.parse_args().notebook_path |
| 158 | |
| 159 | # Validate notebook path |
| 160 | notebook_file = Path(notebook_path) |
| 161 | if not notebook_file.exists(): |
| 162 | sys.exit(f"Error: Notebook file not found: {notebook_path}") |
| 163 | |
| 164 | if notebook_file.suffix != ".ipynb": |
| 165 | sys.exit(f"Error: File must be a Jupyter notebook (.ipynb): {notebook_path}") |
| 166 | |
| 167 | if not str(notebook_file).startswith("examples/"): |
| 168 | sys.exit(f"Error: Notebook must be in the examples/ directory: {notebook_path}") |
| 169 | |
| 170 | # Generate output path |
| 171 | folder_name = notebook_file.parent.name |
| 172 | output_path = Path(f"docs/v2/examples/{folder_name}.mdx") |
| 173 | |
| 174 | print(f"Processing: {notebook_path} -> {output_path}") |
| 175 | |
| 176 | # Convert notebook to markdown and process |
| 177 | markdown_content = convert_notebook_to_markdown(notebook_path) |
| 178 | processed_content = process_pip_installations(markdown_content) |
| 179 | |
| 180 | # Check for existing special frontmatter |
| 181 | existing_frontmatter = get_existing_frontmatter(output_path) |
| 182 | |
| 183 | if existing_frontmatter: |
| 184 | final_content = generate_mdx_content(notebook_path, processed_content, existing_frontmatter) |
| 185 | else: |
| 186 | print("Generating new frontmatter and content") |
| 187 | final_content = generate_mdx_content(notebook_path, processed_content) |
| 188 | |
| 189 | # Write the file |
| 190 | output_path.parent.mkdir(parents=True, exist_ok=True) |
| 191 | output_path.write_text(final_content, encoding="utf-8") |
| 192 | |
| 193 | print(f"Successfully generated: {output_path}") |
| 194 | |
| 195 | |
| 196 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…