Skip to content
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

Add notebook formatting and CI check #124

Merged
merged 11 commits into from Jan 25, 2021
12 changes: 12 additions & 0 deletions .github/workflows/pythonpackage.yml
Expand Up @@ -52,3 +52,15 @@ jobs:
run: |
pip install pytest
pytest -v

nbformat:
name: Notebook formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: 'x64'
- name: Doc check
run: dev_tools/nbfmt
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -39,3 +39,6 @@ docs/generated

# Default pycharm virtual env
.venv/

# Notebook formatting script.
nbformat
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it downloads into dev_tools/, right? I guess this still works but may be overzealous. Probably doesn't matter too much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed downloads into dev_tools

28 changes: 28 additions & 0 deletions dev_tools/nbfmt
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

###############################################################################
# Formats ipython notebooks with tensorflow-docs nbformat tool.
#
# Usage:
# dev_tools/nbfmt [--apply]
#
# Without '--apply', the diff that would be applied is printed and the exit
# status is 1 if there are any changes or else 0 if no changes are needed.
#
# With '--apply', the exit status is 0 and the changed files are actually
# reformatted.
#
################################################################################

# Get the working directory to the repo root.
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$(git rev-parse --show-toplevel)"

# Check if cirq/check/nbformat exists, if not grab it.
if [[ ! -f dev_tools/nbformat ]]; then
wget https://raw.githubusercontent.com/quantumlib/Cirq/master/check/nbformat -P dev_tools/
chmod u+x dev_tools/nbformat
fi

# Run the formatter.
dev_tools/nbformat "$@"
Empty file modified docs/guide/data_analysis.ipynb
Whitespace-only changes.
Empty file modified docs/guide/data_collection.ipynb
Whitespace-only changes.
Empty file modified docs/qaoa/example_problems.ipynb
Whitespace-only changes.
Whitespace-only changes.
Empty file modified docs/qaoa/landscape_analysis.ipynb
Whitespace-only changes.
Empty file modified docs/qaoa/precomputed_analysis.ipynb
Whitespace-only changes.
3 changes: 1 addition & 2 deletions docs/qaoa/routing_with_tket.ipynb
Expand Up @@ -520,8 +520,7 @@
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3",
"language": "python"
"name": "python3"
}
},
"nbformat": 4,
Expand Down
Empty file modified docs/qaoa/tasks.ipynb
Whitespace-only changes.