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 pre-commit config, formatting with black, linting with ruff #2503

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aganders3
Copy link
Contributor

This closes #2291 and fixes the broken lint check in CI (#2291 (comment)) by replacing it with pre-commit. This will be a lot to review but hopefully it helps give a sense of the scale of changes. Timing-wise I'm not sure if there are any existing PRs you'd rather merge first (I have two open that would need to be rebased, haha).

Configuration is almost entirely in pyproject.toml, with a bit in .pre-commit-config.yaml. The main exclusion is vispy/gloo/gl, which I believe is all/mostly generated code. I tried to comment the configs to explain how values, but of course I'm open to changes on that as well. I played with line-length a bit to pick a sane-ish value and settled on 100 for black, with ruff errors at 110. Pulling it down to 88 (black's default) or 79 created over 1000 more errors I think. So, a lot more but maybe a drop in the bucket compared to the changes already here.

Finally, this adds a .git-blame-ignore-revs file so the one massive commit would be skipped by default in "blame" view on GitHub.

@aganders3
Copy link
Contributor Author

I think the CI failure is the same as this one: #2502 (comment)

@djhoese
Copy link
Member

djhoese commented Jun 22, 2023

I just merged your other PR. Feel free to rebase/merge with main and let's see how CI behaves.

@aganders3 aganders3 marked this pull request as ready for review June 28, 2023 18:51
djhoese pushed a commit that referenced this pull request Jun 12, 2024
I think I've sorted out the problem causing #2596. Sorry this is a lot
to take in. I'm just trying to be thorough and keep track for my own
purposes as well.

Before I write any more I'll try to be clear:
* _tests_ are the individual test functions in the test suite
* _checks_ are the the output of GitHub actions workflows
* _steps_ are the individual steps in a workflow
* _commands_ are the individual lines in a `run` step

### Tests
The issue was that the GitHub actions workflow is replacing the default
shell with `bash -l {0}`.

https://github.com/vispy/vispy/blob/4f061ba23ddac3131eb0d1d955573dd71c9a3d2f/.github/workflows/main.yml#L163-L166

This is problematic because it does not fail a run step if a command
fails. I've changed the shell to `bash --login -e {0}` which will fail
the run step if any command fails. The default shell on GitHub actions
sets `-e`, and I think it's what we want. Without this, the step (and
check) will only fail if the _last_ command in the step fails. I didn't
test, but I believe the login shell may be required for some conda
things.

Many checks would fail not directly because the test failed, but because
the subsequent coverage commands would fail (because the tests failed in
a way that didn't produce coverage).

https://github.com/vispy/vispy/blob/4f061ba23ddac3131eb0d1d955573dd71c9a3d2f/.github/workflows/main.yml#L274-L275

Because of all this, I think the only tests that would actually be
missed were any marked
`@requires_pyopengl()` but not `@requires_application()` (as the in the
case in #2589).

Documenting the process in this PR:
* See this log showing a check that passed, but should have failed
(5964e1e):

https://github.com/aganders3/vispy/actions/runs/9388966425/job/25855466353#step:11:647
* See here for a check that failed as expected, after changing the shell
(8a314d2):

https://github.com/aganders3/vispy/actions/runs/9389260260/job/25856378619?pr=6#step:11:647

The remaining failing test should be resolved by #2595. Fortunately it
seems there are no additional missed failing tests, this may be luck but
let's chalk it up to rigor! I think it's been this way for a long time.

### Linting
Linting errors have been ignored for a totally different reason. The way
the linting is set up, it invokes `flake8` by importing and running its
`main` function. This is not officially supported, and there was a
breaking change introduced in flake8 v5.0.0. The `main` function now
returns an exit code instead of exiting (`sys.exit` or `raise
SystemExit`). This is also fixed here, but given there are a number of
linting errors I've deliberately disabled the check. I can open another
PR to fix the lint errors if there is bandwidth to review it (or I can
revive [my PR that blackens the
code](#2503)).

There was some discussion these were deliberately disabled before, but I
think that was only the docstring checks:

https://github.com/vispy/vispy/blob/4f061ba23ddac3131eb0d1d955573dd71c9a3d2f/.github/workflows/main.yml#L70-L73

Linting process in this PR:
* See here for linting errors properly failing (fdb78e0):

https://github.com/aganders3/vispy/actions/runs/9389579018/job/25857384162
* See here for linting errors reported but deliberately ignored
(bd2a299):

https://github.com/aganders3/vispy/actions/runs/9389634299/job/25857588048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pre-commit config to enable auto-formatter and linting on commit
2 participants