Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh
#
# This pre-commit hook cleans Jupyter notebooks before they are committed.
# It uses nb-clean to remove unnecessary metadata, which helps to reduce
# noise in commits and avoid merge conflicts.

# Check if uv is installed. If not, warn the user and exit gracefully.
if ! command -v uv >/dev/null 2>&1; then
echo "-----------------------------------------------------------------"
echo "Warning: 'uv' is not installed, so notebooks will not be cleaned."
echo "For cleaner commits, please install uv:"
echo "https://astral.sh/uv"
echo "-----------------------------------------------------------------"
exit 0
fi

# Get a list of staged .ipynb files.
STAGED_NOTEBOOKS=$(git diff --cached --name-only --diff-filter=AM -- "*.ipynb")

if [ -z "$STAGED_NOTEBOOKS" ]; then
exit 0
fi

echo "Cleaning staged notebooks..."

# Loop through the staged notebooks and clean them.
for notebook in $STAGED_NOTEBOOKS; do
echo " - $notebook"
uvx nb-clean clean --remove-all-notebook-metadata "$notebook"
git add "$notebook"
done

echo "Notebook cleaning complete."
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ GitHub Actions automatically tests all notebooks on every push.

---

## Git Hooks

This repository includes a _`pre-commit` Git hook_ to automatically clean Jupyter notebook metadata using `nb-clean` before committing. This helps reduce unnecessary noise in commits and avoid merge conflicts.

To enable this, run the following command in your terminal from the root of this repository:

```shell
git config core.hooksPath .githooks
```

**Note:** If `uv` is not installed, the hook will issue a warning and skip the cleaning process.

---

## Support

Submit issues or PRs in this repository, or contact [support@ionq.com](mailto:support@ionq.com?subject=SDK%20help).
19 changes: 1 addition & 18 deletions api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,7 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "getting-started",
"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"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
55 changes: 8 additions & 47 deletions cirq.ipynb

Large diffs are not rendered by default.

20 changes: 1 addition & 19 deletions cudaq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,7 @@
]
}
],
"metadata": {
"kernelspec": {
"display_name": "getting-started",
"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.13.6"
}
},
"metadata": {},
"nbformat": 4,
"nbformat_minor": 4
}
56 changes: 8 additions & 48 deletions pennylane.ipynb

Large diffs are not rendered by default.

58 changes: 9 additions & 49 deletions qbraid.ipynb

Large diffs are not rendered by default.

69 changes: 9 additions & 60 deletions qiskit.ipynb

Large diffs are not rendered by default.

Loading