-
Notifications
You must be signed in to change notification settings - Fork 105
Add notebooks to docs download #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
54f23e3
ff55d5a
8dd8fbf
091e1a1
fc4df94
df1f9cd
14973ad
06bb33d
e7519c9
4530247
57c3162
2065a14
2babb2d
b41a4cb
425539d
dde0ed3
a32ec1b
1e7f351
e455881
d1bacac
a78fac4
98bf999
60a07a8
af7ceb4
4459016
7f00453
708d22b
64c62a4
1c6fad9
26cdf37
01e6954
f55de5c
848dc87
fdbee40
2a56d63
9ed76f1
27b9d8b
e06a333
2a396e4
3a1691e
e7979d9
d07ab29
c00b84d
997eac5
6dcb42e
0355f82
da8886a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,5 @@ venv | |
| site_libs | ||
| .DS_Store | ||
| index_files | ||
| digest.txt | ||
| digest.txt | ||
| **/*.quarto_ipynb | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/bin/bash | ||
| # Add Jupyter notebook download links to rendered HTML files | ||
| # This adds a download link to the toc-actions section (next to "Edit this page" and "Report an issue") | ||
|
|
||
| set -e | ||
|
|
||
| echo "Adding notebook download links to HTML pages..." | ||
|
|
||
| # Link text variables | ||
| DOWNLOAD_TEXT="Download notebook" | ||
| COLAB_TEXT="Open in Colab" | ||
|
|
||
| # Colab URL configuration (can be overridden via environment variables) | ||
| COLAB_REPO="${COLAB_REPO:-TuringLang/docs}" | ||
| COLAB_BRANCH="${COLAB_BRANCH:-gh-pages}" | ||
| COLAB_PATH_PREFIX="${COLAB_PATH_PREFIX:-}" | ||
|
|
||
| # Find all HTML files that have corresponding .ipynb files | ||
| find _site/tutorials _site/usage _site/developers -name "index.html" 2>/dev/null | while read html_file; do | ||
| dir=$(dirname "$html_file") | ||
| ipynb_file="${dir}/index.ipynb" | ||
|
|
||
| # Check if the corresponding .ipynb file exists | ||
| if [ -f "$ipynb_file" ]; then | ||
| # Check if link is already present | ||
| if ! grep -q "$DOWNLOAD_TEXT" "$html_file"; then | ||
| # Get relative path from _site/ directory | ||
| relative_path="${html_file#_site/}" | ||
| relative_path="${relative_path%/index.html}" | ||
|
|
||
| # Extract notebook name from parent folder | ||
| notebook_name=$(basename "$relative_path") | ||
|
|
||
| # Construct Colab URL | ||
| if [ -n "$COLAB_PATH_PREFIX" ]; then | ||
| colab_url="https://colab.research.google.com/github/${COLAB_REPO}/blob/${COLAB_BRANCH}/${COLAB_PATH_PREFIX}/${relative_path}/index.ipynb" | ||
| else | ||
| colab_url="https://colab.research.google.com/github/${COLAB_REPO}/blob/${COLAB_BRANCH}/${relative_path}/index.ipynb" | ||
| fi | ||
|
|
||
| # Insert both download and Colab links BEFORE the "Edit this page" link | ||
| # The download attribute forces browser to download with custom filename instead of navigate | ||
| perl -i -pe 's|(<li><a href="[^"]*edit[^"]*"[^>]*><i class="bi[^"]*"></i>Edit this page</a></li>)|<li><a href="index.ipynb" class="toc-action" download="'"$notebook_name"'.ipynb"><i class="bi bi-journal-code"></i>'"$DOWNLOAD_TEXT"'</a></li><li><a href="'"$colab_url"'" class="toc-action" target="_blank" rel="noopener"><i class="bi bi-google"></i>'"$COLAB_TEXT"'</a></li>$1|g' "$html_file" | ||
| echo " ✓ Added notebook links to $html_file" | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| echo "Notebook links added successfully!" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main other question is: if the qmd-to-ipynb script is already in Python, why not write the Bash scripts in Python as well? I don't mind the use of Python (it's way better for quick scripts than Julia is), but I think reducing the number of moving parts that need to work together will make for easier maintenance in the future. Especially because all of these scripts serve a common purpose and you're unlikely to want to run one without running the others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, personally I find any bash stuff gets harder to read the more complex it gets, I can do that though, not a problem. Let me do the current changes and verify it works then I can explore this fully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yes bash is definitely hard to read but I meant moving the bash to python - not the other way round! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha, gotchu. tbh, I originally wrote the bash as a quick fix with the CI, it was only because the default convert didn't work that I did the python too. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| #!/bin/bash | ||||||
| # Generate Jupyter notebooks from .qmd files without re-executing code | ||||||
| # This script converts .qmd files to .ipynb format with proper cell structure | ||||||
|
|
||||||
| set -e | ||||||
|
|
||||||
| echo "Generating Jupyter notebooks from .qmd files..." | ||||||
|
|
||||||
| # Find all .qmd files in tutorials, usage, and developers directories | ||||||
| find tutorials usage developers -name "index.qmd" | while read qmd_file; do | ||||||
|
||||||
| find tutorials usage developers -name "index.qmd" | while read qmd_file; do | |
| find tutorials usage developers -name "index.qmd" -print0 | while IFS= read -r -d '' qmd_file; do |
Copilot uses AI. Check for mistakes.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,235 @@ | ||||||
| #!/usr/bin/env python3 | ||||||
| """ | ||||||
| Convert Quarto .qmd files to Jupyter .ipynb notebooks with proper cell structure. | ||||||
| Each code block becomes a code cell, and markdown content becomes markdown cells. | ||||||
| """ | ||||||
|
|
||||||
| import sys | ||||||
| import json | ||||||
| import re | ||||||
| from pathlib import Path | ||||||
| from typing import List, Dict, Any, Optional | ||||||
|
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're only using Python's standard library here, so this can be done just as easily in Julia too. I mean, it's always better to avoid Python in Julia-specific packages! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works in python, and this is just docs which is handled by CI, so I'm less inclined to rewrite it when it currently works, but I do appreciate what you're saying. |
||||||
|
|
||||||
|
|
||||||
| class QmdToIpynb: | ||||||
| def __init__(self, qmd_path: str): | ||||||
| self.qmd_path = Path(qmd_path) | ||||||
| self.cells: List[Dict[str, Any]] = [] | ||||||
| self.kernel_name = "julia" # Default kernel | ||||||
| self.packages: set = set() # Track packages found in using statements | ||||||
|
|
||||||
| def _extract_packages_from_line(self, line: str) -> None: | ||||||
| """Extract package names from a 'using' statement and add to self.packages.""" | ||||||
|
||||||
| """Extract package names from a 'using' statement and add to self.packages.""" | |
| """Extract package names from a Julia 'using' statement and add to self.packages.""" |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another edge case to handle, which is using Foo.X.Y where the package name is just Foo and not Foo.X.Y.
There's also import as well as using.
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 3 should be defined as a named constant to improve code readability and maintainability.
Copilot uses AI. Check for mistakes.
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if kernel_name starts with 'julia', but line 18 sets kernel_name to 'julia' as a string. This should use equality check instead of startswith() to avoid potential false matches.
| if self.kernel_name.startswith("julia"): | |
| if self.kernel_name == "julia": |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This complex regex replacement should be broken down into multiple steps or variables to improve readability and maintainability.
Copilot uses AI. Check for mistakes.