-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Improve pre-commit
workflow
#2602
Conversation
Note: I'm not completely sure why but I wasn't able to sort the imports of |
@kir0ul this looks good, but could you fix this in CI and and fix merge conflicts? |
dc7c9c3
to
f52aa31
Compare
I believe this is ready for review @jkterry1 🙂 |
No issues with sorting the imports in the codebase, it's about as boring and uncontroversial as it gets. My bigger question is - what exactly is the implication on the process of submitting new PRs? As I understand, CI will fail if imports are wrong? What will contributors have to do to make it pass? This should be clearly stated somewhere. I'm also personally not a fan of requiring the isort and failing tests otherwise, imo it doesn't contribute much to code quality, and might be an extra annoyance of failing tests for relatively trivial reasons. |
Yes at the moment the CI will fail if imports are not sorted, but if the person has |
@kir0ul could you update this PR with a description in contributing.md? |
9a7f9ae
to
b7d7f15
Compare
I added a section in the |
I updated the list of changes this PR makes in the first post: #2602 (comment) |
I think it looks good now, if my understanding is right, the workflow for formatting should just be running Overall I'm happy with this, can be merged imo |
Yes, it should indeed run automatically when you make a commit if you installed the Git hooks with |
General question before merging: is anyone having any issue with bandit when running it locally? For some reason it doesn't work on my local machine, like it takes forever and never finishes. So I'm wondering if it's only a problem for me or also for others. Because in case it's not only a problem on my machine and people start to use it with |
Do we actually need bandit to be run in the first place? I'm not really familiar with it, and it seems to be doing some sort of a security audit, so my intuition is that it's enough if it runs in the CI, and doesn't need to be ran locally |
I think I said this to you over discord, but I've had a ton of issues with bandit. Given that gym isn't an online service, I feel like removing it from CI outright may be prudent? Also can you please fix the merge conflict? |
I removed Bandit completely and fixed the merge conflicts. While doing this, I was also looking at the lint_python:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install isort pytest pyupgrade safety
- run: isort --diff --check-only --profile black .
- run: pip install -e .[nomujoco]
- run: pytest . || true
- run: pytest --doctest-modules . || true
- run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true Is there a reason to keep this or should it be removed/commented? |
"everything else it runs can never fail" could you please elaborate on that? |
All the For example, if I add a test that should always fail: def test_that_should_fail():
assert False If I run the line below I get an exit code of pytest -k test_that_should_fail; echo $? # returns 1 But if I add the pytest -k test_that_should_fail || true; echo $? # returns 0 |
I understand, I apologize. All of the || true stamps obviously should be removed and the tests should be made to pass? |
Looking more closely at what is run in the
In summary, I'd suggest to completely remove the |
Could you remove --forked from the tests in build as we found that pytest-forked is bugged #2647 |
Yes, I just rebased on
|
Looks like this is ready. I updated the first post with the content of what this PR does. |
This may be too late to add to this PR but dealing with #2660 and #2703 |
This sounds out of the scope of this PR, but is there no way to ignore/hide only those specific warnings? I didn't investigate much but maybe |
So just as a final sanity check as to what this does - after installing and configuring pre-commit, all the formatting stuff will be performed on the local copy of the code, and then that reformatted version will be committed? If that is the case, then it looks alright. (ignoring the merge conflict that happened in the meantime) |
Correct, and the exact same checks run locally will also be run in CI. |
- Remove `lint_python` CI job - Move `pyupgrade` job to `pre-commit` workflow
@RedTachyon Just added a note in the contributing docs & fixed the conflicts! |
This PR will add the following changes:
isort
to the whole codebase,isort
in CI (at the moment it can never fail)isort
check to thepre-commit
file so that developers can know beforehand and not after pushing if something is wrong with their importsEDIT:
black
version used bypre-commit
pre-commit
workflow in theCONTRIBUTING.md
fileEDIT2:
bandit
job inpre-commit
lint_python
CI jobpyupgrade
job topre-commit