[py]: Initial implementation of linting in CI #10628
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New Python Linting
Here's typically how this stuff will work for now, since we do not want
pre-commit
put in place; this utilisestox
which currently handles ourflake8
stuff. Main difference here is that bothblack
andisort
will rewrite files which are violating our rules, these will be unstaged and require you to re-stage the fixed versions however the python code base will be uniform across the board which is vital, we will also have less merge conflicts with more keeping more to a single line (e.g imports etc).This adds the following to a new
tox -e linting
recipe; formerlytox -e flake8
(specifically).flake8
.isort
for consistent import management.black
for a consistent code base throughout all contributors.Github actions have been updated as part of this work and will fail just like
flake8
currently does when things are not uniform. Tools are now configured via thesetup.cfg
file for everything, we should consider moving to apyproject.toml
in future; but we usebazel
so do not follow a normal 'python packaging' setup.I have been adding commit hashes that do sweeping linting changes to
.git-blame-ignore-revs
which can be used in conjunction withgit blame
for checking who was responsible for what changes originally without everything coming back as me with the original changes.Typical working flow:
trunk
and do some worktox -e linting
0
due to changes inblack
orisort
those files will be unstaged and amended automatically, re-stage them and applytox -e linting
again until it is good (this is handled automatically bypre-commit
which is why I was pushing this so strongly)flake8
fixes will manually need resolved as they currently doWe are so far away from having a good
mypy
coverage but we can work towards it in future and consider adding it into thetox -e linting
recipe.Negatives (for now):
--no-verify
is not a valid work around, I don't really see that as a big 'negative' at all but something to be aware of.Outstanding tasks:
flake8
.toml
git blame
is not impacted by the initial rewriting commits.CONTRIBUTING.md
to reflect the workflow for new contributors