Feature/issue 1274 notebook format check#1299
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new script, check/nbformat, to validate and fix Jupyter notebook formatting using tensorflow_docs.tools.nbformat, and updates the project's dependency requirements and lockfiles. The review highlights two critical issues: the inefficiency of invoking the format checker in a loop rather than passing all files at once, and the breaking of environment compatibility for older Python versions caused by regenerating lockfiles with Python 3.13 instead of the project's minimum supported version.
|
Hey @mhucka any feedback on this also? No stress, just checking in. Thanks. |
|
@rosspeili Thank you for the contribution, and sorry for the long delay in getting back to this. The merge conflicts are because files in the repo changed in the meantime, which is my fault for not reviewing this sooner, so I will take the time to fix it in a moment and push an updated version to your branch. (I hope you don't mind – it will save everyone time.) A bigger problem is that this does not work. How did you test this? This is what happens when I run check/nbformat: |
| declare -a errors=() | ||
| for notebook in "${notebooks[@]}"; do | ||
| echo " Checking: ${notebook}" | ||
| if ! python -m tensorflow_docs.tools.nbformat "${tf_args[@]}" "${notebook}"; then |
There was a problem hiding this comment.
tensorflow_docs.tools does not have an nbformat.
This could not have worked. How was this tested, exactly?
|
Hey @mhucka no stress at all. Appreciate the review and comments as always. As disclosed also in previews PRs, the PR description indeed is formatted with AI, based on a dump, but will make it more concise or just drop the original blurp. Code is hand written and passed through AI for review before pr. I used existing tests with py 3.13, but will check again and come back to you asap. Please do feel free to push to my branch if available. Or suggest and I'll approve. 🙏 |
Add check/nbformat, a new bash script that checks the format of all tracked Jupyter notebook (.ipynb) files using the TensorFlow Docs notebook format checker (tensorflow_docs.tools.nbformat). The script: - Discovers all .ipynb files tracked by git via git ls-files - Runs python -m tensorflow_docs.tools.nbformat on each notebook - Defaults to check-only mode (non-destructive) - Accepts --fix to reformat notebooks in place - Accepts --help to print usage information - Exits non-zero if any notebook fails the format check Wire check/nbformat into: - check/all: called unconditionally alongside check/mypy and check/shellcheck, since notebook format is structural and not related to which Python files changed - check/shellcheck: added to the required_shell_scripts list (in sorted order) so shellcheck verifies the new script is present Add tensorflow-docs to dev_tools/requirements/deps/pytest.txt alongside the existing nbformat dep, since both are needed for notebook-related checks and belong in the same env grouping. Add a notebook-checks CI job to .github/workflows/ci.yaml that triggers when .ipynb files change and runs check/nbformat using the pytest.env.txt environment (which includes tensorflow-docs). Also add the new job to report-results so it is a required check.
Co-authored-by: Michael Hucka <mhucka@google.com>
…1274) The checker called a non-existent tensorflow_docs.tools.nbformat module. Align with Cirq by using nbfmt, regenerate lockfiles on current main, and format all tracked notebooks so CI can pass.
39ff7df to
b52511c
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
@mhucka thanks again for the patience and tips. Rebased onto current main and fixed check/nbformat, I had the wrong module ( Let me know if I am missing anything. <3 |
Closes #1274
Adds check/nbformat so tracked Jupyter notebooks are checked with tensorflow_docs.tools.nbfmt (Cirq-style), wired into check/all, shell check, and CI.
Also adds tensorflow-docs to the pytest/dev lockfiles, rebases on current main, and runs nbfmt on all 15 .ipynb files so CI passes (most of the new diff is notebook formats).
Earlier version used the wrong module (nbformat) which was fixed to nbfmt with --apply for local fixes.