Skip to content
Snippets Groups Projects

Check notebook syntax in pre-commit hooks

Merged Thomas Kluyver requested to merge fix/pre-commit-check-nb-syntax into master

I just realised we're effectively skipping the notebooks AST check because nbQA excludes cells with syntax errors by default. :face_palm:

I've made a deliberate bad commit here to ensure that the check can pick it up now. I'll cut that out before merging.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Yes, it fails:

    nbqa-check-ast...........................................................Failed
    - hook id: nbqa-check-ast
    - exit code: 1
    notebooks/LPDMini/LPD_Mini_Correct.ipynb: failed parsing with CPython 3.11.10:
        Traceback (most recent call last):
          File "/root/.cache/pre-commit/repokgn9cdot/py_env-python3/lib/python3.11/site-packages/pre_commit_hooks/check_ast.py", line 21, in main
            ast.parse(f.read(), filename=filename)
          File "/usr/local/lib/python3.11/ast.py", line 50, in parse
            return compile(source, filename, mode, flags,
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "notebooks/LPDMini/LPD_Mini_Correct.ipynb", line 3
            in_folder = "/gpfs/exfel/exp/FXE/202321/p004576/raw/  # the folder to read data from, required
                        ^
        SyntaxError: unterminated string literal (detected at line 3)

    https://git.xfel.eu/calibration/pycalibration/-/jobs/754201

  • Nice, this is really useful. Imagine someone would accidently add a character just in between testing and git commit, and then deploy during operations.

  • Thomas Kluyver marked this merge request as ready

    marked this merge request as ready

  • I've removed the bad commit again, and the pre-commit checks are passing (although they only run on the files changed in the MR, which is now no notebooks)

  • Thomas Kluyver mentioned in commit 8576143a

    mentioned in commit 8576143a

  • Philipp Schmidt changed milestone to %3.15.5

    changed milestone to %3.15.5

Please register or sign in to reply
Loading