-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add example nbs * feat(ci): add nb conversion CI * docs: add open in colab badges * docs: fix colab links * feat: add pre-commit hooks for nbs * chore: move nb generation script to examples/notebooks/ * chore: pre-commit autoupdate * feat: programmatically add installs to nbs * docs: update README with badges for pytorch and lightning * feat: update ci with make cmd * feat: update CI to check for diff * docs: add a md cell before installation cmd * feat: update nbs * fix: update nbs CI * docs: add note in IJEPA tutorial * feat: add updated nbs * docs: shorten text in badges * feat: assert CI fails when nbs need to be updated * feat: add installation script in examples
- Loading branch information
1 parent
51e3e80
commit f5a9f19
Showing
141 changed files
with
13,253 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "Check Example Notebooks" | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
paths: | ||
- "examples/**/*.py" | ||
pull_request: | ||
branches: [master] | ||
paths: | ||
- "examples/**/*.py" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
convert-to-nbs: | ||
name: "Check Example Notebooks" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v4 | ||
- name: Set Up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.7 | ||
- name: Set Up Environment | ||
run: | | ||
make install-uv reset-venv | ||
source .venv/bin/activate | ||
make install-pinned-extras | ||
- name: Convert using Script | ||
run: | | ||
source .venv/bin/activate | ||
make generate-example-notebooks | ||
- name: Check for diff | ||
run: | | ||
source .venv/bin/activate | ||
git add examples/notebooks/ | ||
if ! git diff --cached --exit-code; then | ||
echo "Notebooks have changed! Please run `make generate-example-notebooks` and commit the changes." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import argparse | ||
from pathlib import Path | ||
|
||
import jupytext | ||
import nbformat | ||
from nbformat import NotebookNode | ||
|
||
|
||
def add_installation_cell(nb: NotebookNode, script_path: Path) -> NotebookNode: | ||
# Find installation snippet | ||
with open(script_path, "r") as f: | ||
for line in f: | ||
line = line.strip() | ||
if line.startswith("# pip install"): | ||
pip_command = "!" + line.lstrip("# ").strip() | ||
# Create a new code cell | ||
code_cell = nbformat.v4.new_code_cell(pip_command) | ||
# Add the cell to the notebook | ||
nb.cells.insert(1, code_cell) | ||
break | ||
|
||
return nb | ||
|
||
|
||
def covert_to_nbs(scripts_dir: Path, notebooks_dir: Path) -> None: | ||
# Loop through all Python files in the directory | ||
for py_file_path in scripts_dir.rglob("*.py"): | ||
# Construct the full paths | ||
notebook_path = notebooks_dir / py_file_path.relative_to( | ||
scripts_dir | ||
).with_suffix(".ipynb") | ||
print(f"Converting {py_file_path} to notebook...") | ||
notebook = jupytext.read(py_file_path) | ||
notebook = add_installation_cell(notebook, py_file_path) | ||
# Make cell ids deterministic to avoid changing ids everytime a notebook is (re)generated. | ||
for i, cell in enumerate(notebook.cells): | ||
cell.id = str(i) | ||
jupytext.write(notebook, notebook_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"scripts_dir", | ||
help="path to the directory containing the python scripts", | ||
) | ||
parser.add_argument( | ||
"notebooks_dir", | ||
help="path to directory where the generated notebooks are stored", | ||
) | ||
args = parser.parse_args() | ||
covert_to_nbs(Path(args.scripts_dir), Path(args.notebooks_dir)) |
Oops, something went wrong.