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

Update pre commit hooks #1774

Merged
merged 7 commits into from
Sep 11, 2021
Merged

Update pre commit hooks #1774

merged 7 commits into from
Sep 11, 2021

Conversation

LilSpazJoekp
Copy link
Member

This just updates the pre-commit hooks to do the same thing pre_push.py does. It also moves and consolidates tool configurations.

@LilSpazJoekp LilSpazJoekp requested a review from bboe July 30, 2021 23:22
Copy link
Contributor

@vikramaditya91 vikramaditya91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestions

hooks:
- id: black
language_version: python3
rev: 21.7b0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make this work without setting the value rev?
It would add technical debt..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's set by pre-commit autoupdate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring hooks to have pinned versions is a core design decision of pre-commit, since it ensures that all developers and CIs get the same consistent version of hooks for a given project repository commit, and thus hooks don't arbitrarily fail or make different changes based on whatever version happens to be installed on the current platform. There's also a GH action that, like dependabot, automatically submits PRs at a reasonable frequency to upgrade out of date hooks.

.flake8 Outdated
per-file-ignores =
praw/models/__init__.py:F401
praw/models/listing/mixins/__init__.py:F401
praw/models/reddit/mixins/__init__.py:F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful about newline at EOF

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, there's a built-in hook to fix this problem automatically, end-of-file-fixer. You might be interested in some of the other out of the box pre-commit-hooks as well; they are very cheap to run and can fix many common problems automatically.

ignore = E203 E501 W503 W504
per-file-ignores =
praw/models/__init__.py:F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would even go as far as to do
praw/*/__init__.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as is.

@@ -1,9 +1,2 @@
[aliases]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the purpose of the setup.cfg here if you already have tox.ini giving instructions on the test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is settings for setuptools.

Copy link
Contributor

@CAM-Gerlach CAM-Gerlach Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this setting and setup.py test is deprecated and will trigger a warning in new versions of setuptools, and will eventually be removed.

@CAM-Gerlach
Copy link
Contributor

Great to see this @LilSpazJoekp , and sorry I wasn't able to help, too busy working on Sub Manager unfortunately (mostly our own extensive pre-commit config). I'll give it a look-over as well in case I spot anything.

Copy link
Contributor

@CAM-Gerlach CAM-Gerlach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to note, given that all the now-duplicate dep installation and lint runner commands lint-multi-os job in your CI workflow (aside from the Sphinx build) is now also covered here, I would suggest replacing all that redundancy with the pre-commit Github action which will install and run them through pre-commit, and tweak your caching as needed. This ensures the same checks are run locally as in the CI (right now some of the invocations are different, because they were changed here but not there, and the versions may drift out of sync), keeps things DRY and avoids doubling the maintenance burden, with corresponding issues if things get out of sync.

Similarly, now that you've done this, I suggest not further duplicating the invocations and versions again in pre_push.py and the setup.py lint extra respectively, and instead replacing all that with a single call to pre-commit, i.e. pre-commit run or pre-commit run --all-files. In all, this triples the maintenance burden of keeping versions up to date and tweaking invocations (particularly since pre-commit handles the former and much of the latter for you), again ensures consistent behavior between the script and the hooks, and brings the benefits of pre-commit's automated, platform-independent installation, updating, output reporting and more.

@LilSpazJoekp
Copy link
Member Author

@CAM-Gerlach I like your suggestions. Would you mind opening a PR to this branch for what you suggest?

@LilSpazJoekp LilSpazJoekp force-pushed the update_pre_commit_hooks branch 2 times, most recently from 7a7f415 to 0d2249f Compare August 22, 2021 17:43
@CAM-Gerlach
Copy link
Contributor

Sure, finishing up something now but I'll try to get to it later this evening (CDT), or if not then tomorrow. If that holds up merging this too long, I'm happy to make another PR. Thanks!

@LilSpazJoekp LilSpazJoekp force-pushed the update_pre_commit_hooks branch from 0d2249f to 55de585 Compare September 11, 2021 16:55
@LilSpazJoekp
Copy link
Member Author

@CAM-Gerlach I'm going to go ahead and merge this. If you have suggested changes feel free to open a PR for it.

@LilSpazJoekp LilSpazJoekp merged commit a6535a4 into master Sep 11, 2021
@LilSpazJoekp LilSpazJoekp deleted the update_pre_commit_hooks branch September 11, 2021 17:15
@CAM-Gerlach
Copy link
Contributor

@LilSpazJoekp Hey, really sorry for the long delay; it was on my task list but with priority NASA projects, other open-source stuff that came up and an illness, I never quite got to it. I'll submit a PR soon once I get the chance, thanks.

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.

3 participants