Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
eab561a
Add workflow to format Jupyter notebooks for GitHub
brown9804 Sep 11, 2025
e621ca0
Update visitor count
github-actions[bot] Sep 11, 2025
d725654
Create render_notebooks.py
brown9804 Sep 11, 2025
409444f
Update last modified date in Markdown files
github-actions[bot] Sep 11, 2025
197cde2
Render notebooks for GitHub compatibility
brown9804 Sep 11, 2025
b54873b
Eliminate backup creation in XML conversion
brown9804 Sep 11, 2025
330f99b
Refactor notebook rendering workflow
brown9804 Sep 11, 2025
b61122f
Update visitor count
github-actions[bot] Sep 11, 2025
2e6a259
Enhance notebook processing with logging
brown9804 Sep 11, 2025
bae9f29
Improve notebook change detection in workflow
brown9804 Sep 11, 2025
19ab13d
testing
brown9804 Sep 11, 2025
bebf3ec
testing render
brown9804 Sep 11, 2025
d20fd56
Delete AzurePortal/1_MedallionArch/src/0_notebook_bronze_to_silver.ipynb
brown9804 Sep 11, 2025
133c2ca
testing render restaured
brown9804 Sep 11, 2025
a7200af
Delete AzurePortal/1_MedallionArch/src/0_notebook_bronze_to_silver.ipynb
brown9804 Sep 11, 2025
5582806
Update visitor count
github-actions[bot] Sep 11, 2025
90c463d
render v3
brown9804 Sep 11, 2025
730db06
Update visitor count
github-actions[bot] Sep 11, 2025
9746c48
Enhance notebook converter for GitHub compatibility
brown9804 Sep 11, 2025
7b7fcda
Update visitor count
github-actions[bot] Sep 11, 2025
0cdaee2
Refactor notebook rendering workflow for efficiency
brown9804 Sep 11, 2025
5cfed16
Fix notebooks for GitHub compatibility
github-actions[bot] Sep 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions .github/workflows/convert_notebooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env python3
"""
Notebook to GitHub-Compatible Format Converter

This script fixes Jupyter notebooks for GitHub rendering by:
1. Converting XML-format notebooks to standard Jupyter JSON format
2. Cleaning widget metadata that can cause GitHub rendering issues
"""

import os
import json
import re
import nbformat
from nbformat.validator import validate

def process_notebooks(directory="."):
"""Find and process all notebook files in the repository"""
notebook_files = []
print(f"Searching for notebooks in directory: {directory}")
for root, dirs, files in os.walk(directory):
# Skip directories that should be excluded
if '.git' in dirs:
dirs.remove('.git') # Skip git directory
if '.github' in dirs:
dirs.remove('.github') # Skip GitHub directory
if '.venv' in dirs:
dirs.remove('.venv') # Skip virtual environments

for file in files:
if file.endswith('.ipynb'):
notebook_path = os.path.join(root, file)
print(f"Found notebook: {notebook_path}")
notebook_files.append(notebook_path)

print(f"Found {len(notebook_files)} notebooks to process")

success_count = 0
for nb_path in notebook_files:
if convert_notebook(nb_path):
success_count += 1

print(f"Successfully rendered {success_count} out of {len(notebook_files)} notebooks")
return success_count

def convert_notebook(filepath):
"""Convert a notebook to GitHub-compatible format by cleaning widget metadata"""
print(f"\nProcessing {filepath}")

try:
# Read the notebook content
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

# Check if this is a XML notebook
if '<VSCode.Cell' in content:
print(f" Converting from XML format...")
# Extract cells using regex
cells = []
cell_pattern = re.compile(r'<VSCode\.Cell.*?language="(.*?)".*?>(.*?)</VSCode\.Cell>', re.DOTALL)

matches = list(cell_pattern.finditer(content))
if not matches:
print(f" WARNING: No cells found in {filepath}")
return False

print(f" Found {len(matches)} cells")

for match in matches:
cell_type, cell_content = match.groups()

if cell_type == "markdown":
cells.append(nbformat.v4.new_markdown_cell(
source=cell_content.strip()
))
else: # python, javascript, etc.
cells.append(nbformat.v4.new_code_cell(
source=cell_content.strip()
))

# Create a new notebook
nb = nbformat.v4.new_notebook()
nb.cells = cells

# Add required metadata
nb.metadata = {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
},
# Add empty widget state to prevent GitHub rendering issues
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
}

# Validate and write the notebook
validate(nb)
with open(filepath, 'w', encoding='utf-8') as f:
nbformat.write(nb, f)

print(f" Successfully rendered {filepath} for GitHub compatibility")
return True

else:
# It's already in JSON format, clean widget metadata
try:
notebook = json.loads(content)
print(f" Cleaning widget metadata...")

# Remove potentially problematic widget state but keep proper structure
if 'metadata' in notebook:
# Replace with clean widget state
notebook['metadata']['widgets'] = {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}

# Clean widget metadata from cells as well
for cell in notebook.get('cells', []):
if 'metadata' in cell and 'widgets' in cell['metadata']:
del cell['metadata']['widgets']

# Write the cleaned notebook
with open(filepath, 'w', encoding='utf-8') as f:
json.dump(notebook, f, indent=2)

print(f" Successfully cleaned {filepath} for GitHub compatibility")
return True

except json.JSONDecodeError:
print(f" ERROR: {filepath} is not in valid JSON format or XML format")
return False

except Exception as e:
print(f" ERROR processing {filepath}: {str(e)}")
return False

if __name__ == "__main__":
print("Rendering notebooks for GitHub compatibility...")
# Get the repository root directory from environment variable if available
repo_root = os.environ.get('GITHUB_WORKSPACE', '.')
print(f"Repository root: {repo_root}")
process_notebooks(repo_root)
61 changes: 61 additions & 0 deletions .github/workflows/render-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Render Notebooks for GitHub

on:
push:
paths:
- '**.ipynb'
pull_request:
branches:
- main
workflow_dispatch: # Allows manual triggering

permissions:
contents: write
pull-requests: write

jobs:
render-notebooks:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }} # Explicitly checkout the branch that triggered the workflow

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install nbformat nbconvert jupyter

- name: Run conversion script
run: python .github/workflows/convert_notebooks.py

- name: Configure Git
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"

- name: Commit and push changes
run: |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Current branch: $CURRENT_BRANCH"

# Stage all notebook files
git add "**/*.ipynb"

# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes detected in notebooks"
else
echo "Changes detected in notebooks"
git commit -m "Fix notebooks for GitHub compatibility"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${CURRENT_BRANCH}
echo "Successfully pushed changes"
fi
6 changes: 3 additions & 3 deletions 0_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Costa Rica
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-07-16
Last updated: 2025-09-11

------------------------------------------

Expand Down Expand Up @@ -104,7 +104,7 @@ Click here for more information about: [Z-Order & V-Order](https://github.com/Mi

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-522-limegreen" alt="Total views">
<p>Refresh Date: 2025-07-16</p>
<img src="https://img.shields.io/badge/Total%20views-1474-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-11</p>
</div>
<!-- END BADGE -->
6 changes: 3 additions & 3 deletions AzurePortal/1_MedallionArch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Costa Rica
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-07-16
Last updated: 2025-09-11

------------------------------------------

Expand Down Expand Up @@ -299,7 +299,7 @@ https://github.com/user-attachments/assets/2a64762a-f120-4448-b0fb-7a49f4d1bedb

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-522-limegreen" alt="Total views">
<p>Refresh Date: 2025-07-16</p>
<img src="https://img.shields.io/badge/Total%20views-1474-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-11</p>
</div>
<!-- END BADGE -->
6 changes: 3 additions & 3 deletions AzurePortal/1_MedallionArch/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Costa Rica
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
[brown9804](https://github.com/brown9804)

Last updated: 2025-07-16
Last updated: 2025-09-11

------------------------------------------

Expand All @@ -15,7 +15,7 @@ Last updated: 2025-07-16

<!-- START BADGE -->
<div align="center">
<img src="https://img.shields.io/badge/Total%20views-522-limegreen" alt="Total views">
<p>Refresh Date: 2025-07-16</p>
<img src="https://img.shields.io/badge/Total%20views-1474-limegreen" alt="Total views">
<p>Refresh Date: 2025-09-11</p>
</div>
<!-- END BADGE -->
Loading