BLD: add more static analysis#31661
Conversation
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
| @@ -0,0 +1,246 @@ | |||
| #!/usr/bin/env python3 | |||
| """ | |||
| Run clang-tidy on Matplotlib's C/C++ and Objective-C sources. | |||
There was a problem hiding this comment.
I'm not sure this script is fully necessary; meson will create a clang-tidy target for you (but only if you have .clang-tidy in the root), so you just need to move it, make an editable install, and run ninja -C build/cp313 clang-tidy or similar
There was a problem hiding this comment.
I think it is still useful for filtering out warnings from the Agg source, but this can indeed be greatly simplified.
There was a problem hiding this comment.
I simplified this, still think it is useful to have to automate creating a build directory just for clang-tidy and for filtering the output.
These were false positives, but add code to give the analyzer a hint + asserts in a debugging build rather than NOLINT to be defensive. Aided by 🤖
When for no-change to code with the qhull wrapper rather than adjusting the code. Aided by 🤖
Fixes an issue found by clang-tidy Aided by 🤖
Simplified at Elliott's suggestions Aided by 🤖
Added exceptions for things it thinks are questionable but we are OK with doing. Aided by 🤖
Aided by 🤖
Aided by 🤖
1c966c2 to
050c2e8
Compare
|
This runs zizimor twice (once in its own job, once in the prek job). I think that is OK, particularly because its own job also has a cron attached to it, but dropping the action in favor of just the prek invocation would also be fine. |
The separate job also has a token and should be able to run more checks, I think? |
| run: brew install llvm | ||
|
|
||
| - name: Install build dependencies | ||
| run: pip3 install meson ninja pybind11 setuptools-scm |
There was a problem hiding this comment.
It might install a bit extra, but this might be better?
| run: pip3 install meson ninja pybind11 setuptools-scm | |
| run: pip3 install --group build |
| persist-credentials: false | ||
|
|
||
| - name: Run zizmor | ||
| uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3 |
There was a problem hiding this comment.
| uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3 | |
| uses: zizmorcore/zizmor-action@b572f7b1a1c2d41efaab43d504f68d215c3cd727 # v0.5.4 |
| with: | ||
| advanced-security: true |
There was a problem hiding this comment.
This defaults on.
| with: | |
| advanced-security: true |
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
There was a problem hiding this comment.
The action already fetches the token.
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| Static analysis with clang-tidy | ||
| -------------------------------- |
There was a problem hiding this comment.
Extra dash.
| Static analysis with clang-tidy | |
| -------------------------------- | |
| Static analysis with clang-tidy | |
| ------------------------------- |
| The logic lives in :file:`tools/run_clang_tidy.py`. It requires | ||
| ``clang-tidy`` on ``PATH`` and ``meson`` and ``pybind11`` installed:: | ||
|
|
||
| pip install meson pybind11 |
There was a problem hiding this comment.
The workflow also installs setuptools-scm? But maybe also use the group.
| if current: | ||
| groups.append(current) | ||
| current = [line] | ||
| else: | ||
| current.append(line) | ||
|
|
||
| if current: | ||
| groups.append(current) |
There was a problem hiding this comment.
You can just append when you create it.
| if current: | |
| groups.append(current) | |
| current = [line] | |
| else: | |
| current.append(line) | |
| if current: | |
| groups.append(current) | |
| current = [line] | |
| groups.append(current) | |
| else: | |
| current.append(line) |
| hooks: | ||
| - id: shellcheck | ||
| - repo: https://github.com/zizmorcore/zizmor-pre-commit | ||
| rev: a4727cbbcd26d7098e96b9cb738169b59711ae51 # frozen: v1.24.1 |
There was a problem hiding this comment.
| rev: a4727cbbcd26d7098e96b9cb738169b59711ae51 # frozen: v1.24.1 | |
| rev: 04a94ec45c8e92de281e3cc55754eb6d9db526a1 # frozen: v1.25.1 |
PR summary
This adds more static analysis to our CI / prek config.
clang-tidyon c/c++/objectiveC code (and fix or ignore issues found). This found a couple of real issues and will only run on CI (+ a helper script to run it locally). The dependencies are too heavy to try and launder through prek's virtual environments.pull_request_targetand a couple of places we allow caching. Also enabled cooldown windows on our dependabot config. This also flagged we had a redundant checkout step inrun ruff on our checked in notebooks as wellOur exsiting ruff config hits this alreadyNot reflected in the commits here, but I did look at https://github.com/PyCQA/bandit but every single thing it flagged was a false positive (either flagging things like
execin the plot directive or being too simplistic to notice that we had already mitigated the thing it was flagging in the code).AI Disclosure
I started from the prompt
with opus 4.6 and then pushing on addressing the coverage with a mix of opus 4.6 and sonnet 4.6. I reviewed everything as I committed it and took a very heavy editing pass at the initial version of the documentation.
PR checklist