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.ci #384

Merged
merged 14 commits into from
Nov 22, 2024
Merged

Add pre-commit.ci #384

merged 14 commits into from
Nov 22, 2024

Conversation

mikemhenry
Copy link
Contributor

We can use this PR to decide what pre-commit hooks we want to use with pre-commit.ci

https://pre-commit.ci/
https://pre-commit.com/
https://pre-commit.com/hooks.html

I am not too fused on which tools we use but I would like to have things that:

  • auto format code
  • clean up files (like removing trailing whitespace)
  • prevent people from making git mistakes (large files, broken symlinks, etc)

@dotsdl @ianmkenney @IAlibay @atravitz -- Interested in hearing your thoughts!

@mikemhenry
Copy link
Contributor Author

Related #291 #363

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.66%. Comparing base (d27100a) to head (3176437).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #384   +/-   ##
=======================================
  Coverage   98.66%   98.66%           
=======================================
  Files          36       36           
  Lines        2097     2097           
=======================================
  Hits         2069     2069           
  Misses         28       28           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@dotsdl dotsdl requested a review from ianmkenney November 7, 2024 15:36
- id: trailing-whitespace
exclude: '\.(pdb|gro|top|sdf|xml|cif|graphml)$'
- repo: https://github.com/psf/black
rev: 24.2.0
Copy link
Member

Choose a reason for hiding this comment

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

I know it's possible with black to choose a "standard", is this the way we do this or does this just control the version of black we install?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also a bit curious here. Which tool is responsible for installing what? For instance, with black, does running the pre-commit install actually install black or just the hook that will execute black?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! So if you are just using pre-commit.ci, locally you don't need to do anything. But if you use this locally, pre-commit when running for the first time will create a virtual python environment (separate than whatever one you are currently using, this lets you use packages and versions that might not work with your program be used for the pre-commit hooks) and install everything needed for the hooks and run them. When you re-run the hooks, it will re-use the virtual environment it created the first time.

so tl;dr if you install pre-commit, it will create a virtual env that will install all the tools needed, then execute the hooks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also as a quick follow up, there is a section in the pyproject.toml:

[tool.black]
line-length = 120 

that controls black's config, so we can set it to use whichever "standard" we want.

Copy link
Contributor

@ianmkenney ianmkenney left a comment

Choose a reason for hiding this comment

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

I think overall this looks good, but I have a couple of questions/requests

.pre-commit-config.yaml Outdated Show resolved Hide resolved
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/econchick/interrogate
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this handle functions where a docstring might be overkill? Specifically, I'm thinking of closures, which usually don't have docstrings. Since closures can be named I find that using them can improve code readability, but adding docstrings to them feels redundant. Would interrogate mark these as lacking documentation?

Copy link
Contributor Author

@mikemhenry mikemhenry Nov 20, 2024

Choose a reason for hiding this comment

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

The config is controlled in the pyproject.toml (so that way if you run the tool as a standalone thing, you use the same config as the one that runs on pre-commit)

[tool.interrogate]
fail-under = 0 
ignore-regex = ["^get$", "^mock_.*", ".*BaseClass.*"]
# possible values for verbose: 0 (minimal output), 1 (-v), 2 (-vv)
verbose = 2 
color = true
exclude = ["build", "docs"]

Config options are listed here: https://github.com/econchick/interrogate?tab=readme-ov-file#configuration

I don't want the tools to get in our way, so if we find it too annoying and gives us many false positives, we can drop it.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@mikemhenry
Copy link
Contributor Author

Working on this today! Thanks for the feedback everyone!

@mikemhenry
Copy link
Contributor Author

@IAlibay @ianmkenney - This is ready for another look!
@atravitz - Let me know what you think! I also know you were looking at ruff which might be able to replace black and isort and add stuff like check for unused imports and the like.

Copy link
Contributor

@ianmkenney ianmkenney left a comment

Choose a reason for hiding this comment

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

This looks good to me! Thanks for putting this together.

@mikemhenry
Copy link
Contributor Author

I want to wait for others to provide some feedback, but we can discuss next steps.

Do we want to just merge this in and fix things as we go on PRs? Or do we want to also run the hooks on the files as part of this PR or a separate PR?

@ianmkenney
Copy link
Contributor

@mikemhenry cleaner to run it here once we're happy with the tooling choices

@dotsdl
Copy link
Member

dotsdl commented Nov 21, 2024

@mikemhenry please proceed with merge and setup of pre-commit CI. After this, we'll want to immediately apply the reformatting to gufe.

@atravitz also recommends we tell git blame to ignore the commit in which we applied the reformatting in order to maintain the usefulness of git blame; see here for details: https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/

@mikemhenry
Copy link
Contributor Author

@mikemhenry cleaner to run it here once we're happy with the tooling choices

@mikemhenry please proceed with merge and setup of pre-commit CI. After this, we'll want to immediately apply the reformatting to gufe.

@IAlibay @atravitz -- can you break the tie here?

@ianmkenney
Copy link
Contributor

@mikemhenry cleaner to run it here once we're happy with the tooling choices

@mikemhenry please proceed with merge and setup of pre-commit CI. After this, we'll want to immediately apply the reformatting to gufe.

@IAlibay @atravitz -- can you break the tie here?

@mikemhenry I'll break it---go with David!

@mikemhenry
Copy link
Contributor Author

mikemhenry commented Nov 21, 2024

Cool, I will do the formatting in a separate PR but wait until that is done to merge in this PR so there isn't a gap between having .pre-commit going and everything unformatted

@mikemhenry
Copy link
Contributor Author

Also need to add https://pre-commit.ci/#configuration-autofix_prs !!

@mikemhenry
Copy link
Contributor Author

I added a pull request template that mentions how to run the pre-commit.ci

@mikemhenry
Copy link
Contributor Author

Okay so plan is to merge in #421 if it is green. Then I will add the commit from that merge to .git-blame-ignore-revs which I will add to this PR. That way we will have a functional git history, and this PR will correctly point to "me" as the blame for the config + the ignore recs, which will be helpful for who ever looks at this in the future

@mikemhenry mikemhenry enabled auto-merge (squash) November 22, 2024 18:53
@mikemhenry mikemhenry merged commit d0e5b35 into main Nov 22, 2024
16 checks passed
@mikemhenry mikemhenry deleted the feat/add-pre-commit-ci branch November 22, 2024 19:02
@dotsdl dotsdl mentioned this pull request Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants