Add more pre-commit hooks and run them in CI#811
Conversation
* Remove trailing whitespaces * Specify error code for a noqa in the free command
b6773db to
e6c4887
Compare
|
It's worth noting that moving flake8 out of the virtual environment also comes with a disadvantage for local development. While it's still going to be possible to run the linter from the command line using For me, personally, it probably means that I'm going to maintain a separate dependency listing locally to be able to create a For reference, this is what you'd get with a default linter set-up in Sublime Text: |
|
I think what @SebastiaanZ is saying here is a dealbreaker for removing these dependencies from the pipfile. I think it would be better to maintain duplicate dependencies in two files than to require a weird non-standard setup to get linting working on sublime or vscode. These are popular editors, and it should be frictionless to set up linting in our repos. |
|
OK. What do you all think of using this hack in CI? printf '%s\n%s' '#!/bin/bash' '"${@:2}"' >> pipenv && chmod +x pipenvIt creates a mock |
A cache for an outdated pre-commit environment may still be useful. It may be the case that only some hooks need to be updated rather than all.
The mock gets used by the flake8 pre-commit hook, which invokes flake8 via `pipenv run flake8`. It's normally useful to use pipenv here cause it ensures flake8 is invoked within the context of the venv. However, in CI, there is no venv - dependencies are installed directly to the system site-packages. `pipenv run` does not work in such case because it tries to create a new venv if one doesn't exist (it doesn't consider the system interpreter to be a venv). This workaround (okay, it's a hack) creates an executable shell script which replaces the original pipenv binary. The shell script simply ignores the first argument (i.e. ignores `run` in `pipenv run`) and executes the rest of the arguments as a command. It essentially makes `pipenv run flake8` equivalent to just having ran `flake8`. When pre-commit executes pipenv, the aforementioned script is what will run.
33c77a5 to
93f29f8
Compare
This was added by the now-removed Snake cog & is not used elsewhere on bot.
|
Per #775 I've also added |
SebastiaanZ
left a comment
There was a problem hiding this comment.
Looks good and this works well with local linting set-ups.
This PR does make me realize that I badly need to update the tests README.
|
@MarkKoz I like it. It's hacky and clever and I don't mind at all because you've documented it well and it only happens in the CI. Excellent work. |
As per python-discord/organisation#138, new hooks were added for pre-commit and they will run in CI too. The
pipenv run lintscript will now run all the new hooks, including flake8.Hooks added
A couple of these hooks automatically apply fixes. However, they still report failure and leave any changes they make uncommitted. Therefore, the user has to commit the automatic fixes.
check-merge-conflict- Check for files that contain merge conflict strings.check-toml- Attempts to load all toml files to verify syntax.check-yaml- Attempts to load all yaml files to verify syntax.end-of-file-fixer- Makes sure files end in a newline and only a newline.mixed-line-ending- Replaces mixed line endings with LF.trailing-whitespace- Trims trailing whitespace.python-check-blanket-noqa- Enforce thatnoqaannotations always occur with specific codesCI
The pre-commit venv is cached. There should only be a cache miss if the
.pre-commit-config.yamlfile changes or if the location of the Python interpreter changes (more realistically, if the Python version changes). Maybe Azure wipes the cache sometimes too, but in that case pre-commit will simply re-create the environment.ELA edit:
Also closes #775