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

Begin enabling pre-commit hooks #2242

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

droctothorpe
Copy link
Contributor

@droctothorpe droctothorpe commented Nov 8, 2023

What this PR does / why we need it:
This PR implements some basic pre-commit hooks and applies them retroactively to the entire codebase. All of the changes in this PR, other than the addition of .pre-commit-config.yaml, were automatically generated by the isort pre-commit hook. This pre-commit configuration is based off of Kubeflow Pipeline's to promote consistent code across the various Kubeflow repositories. The only difference is that I commented out the majority of the hooks, because if we tried to implement all of them simultaneously, the resulting PR would be enormous in size. This PR is a kind of proof of concept. If merged, I'll just progressively uncomment and enable the other pre-commit hooks (either sequentially or all once depending on preference) and execute them retroactively and submit one or more follow up PRs.

Not sure how to integrate it into katib's CI if anyone has any input on that. Highly recommend doing so. It's the only way to enforce the standards that pre-commit enables.

Which issue(s) this PR fixes
Fixes # #2187

Checklist:

  • Docs included if any changes are user facing

Copy link

github-actions bot commented Feb 6, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@tenzen-y
Copy link
Member

/remove-lifecycle stale

@tenzen-y
Copy link
Member

@droctothorpe Hey Alex! Sorry for the late response. I'm starting to review this PR. Are you still here?

@droctothorpe
Copy link
Contributor Author

No worries! Happy to rebase and re-run if it's worth merging.

@tenzen-y
Copy link
Member

tenzen-y commented Apr 19, 2024

No worries! Happy to rebase and re-run if it's worth merging.

Thank you!
I think that this would be worth it :)

@droctothorpe droctothorpe force-pushed the pre-commit branch 5 times, most recently from 00d9930 to fa0552a Compare May 7, 2024 01:36
@droctothorpe
Copy link
Contributor Author

droctothorpe commented May 7, 2024

Apologies for the delay, @tenzen-y. Rebased and re-ran the preliminary pre-commit hooks. I also updated the Lint Files CI gate to run pre-commit and confirmed it works. Once this is merged, I'll submit follow up PRs that unlock additional hooks and further standardize the codebase.

@droctothorpe
Copy link
Contributor Author

Bump cc @andreyvelich

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for adding this and sorry for the late review @droctothorpe!
I left a few comments.

.github/workflows/test-lint.yaml Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@@ -1,6 +1,5 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc

Copy link
Member

Choose a reason for hiding this comment

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

Should we exclude files that auto-generated ?

Copy link
Contributor 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 okay to modify them, but am happy to update the pre-commit file if excluding them is preferable. There are quite a few files that fall into this category (assuming there aren't more that don't include the DO NOT EDIT warning:

❯ grep -r "DO NOT EDIT" . | wc -l
     110

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like pre-commit doesn't let you exclude files based on content, just a regex for the filename, but the generated files have names that truly run the gamut. Given that these specific modifications are superficial and will be overwritten when the files are regenerated anyway, do you mind if we keep them?

Copy link
Member

Choose a reason for hiding this comment

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

It might be problematic, since we run make generate command to make sure user runs this script before making any API changes.
Can't we use exclude parameter ?
https://pre-commit.com/#top_level-exclude

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @andreyvelich! Any objection to following KFP's example and just listing the full paths? With 113 unique generated files, it's going to take forever to generate the 30 or so regexes that will be required to cover them all and will arguably reduce readability (regex is a write-only language 😂 ).

Copy link
Member

@andreyvelich andreyvelich Jul 15, 2024

Choose a reason for hiding this comment

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

I guess, we don't need to list all 113 unique files, just find common patterns.
E.g.

exclude: (/pkg/client/|/pkg/mock/|/pkg/apis/manager|*zz_generated.deepcopy.go|sdk/python/v1beta1/kubeflow/katib/models/) 

WDYT @droctothorpe ?

Copy link
Contributor Author

@droctothorpe droctothorpe Jul 15, 2024

Choose a reason for hiding this comment

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

You're absolutely, right! Sorry, I was being lazy. Fix incoming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Also squashed and removed all the generated files, then validated that it's excluding correctly by running pre-commit run --all-files and confirming that none of the generated files get modified.

sdk/python/v1beta1/kubeflow/katib/models/v1beta1_trial.py Outdated Show resolved Hide resolved
@droctothorpe
Copy link
Contributor Author

Thank you for adding this and sorry for the late review @droctothorpe! I left a few comments.

Thanks for the review, @andreyvelich!

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@andreyvelich
Copy link
Member

Sorry for the late reply @droctothorpe!
Should we just move forward with this PR ? I think, we have just a few comments that we need to address.

@droctothorpe
Copy link
Contributor Author

Will address ASAP. Thanks, @andreyvelich.

@droctothorpe droctothorpe force-pushed the pre-commit branch 2 times, most recently from 34e5411 to 3ad430f Compare July 15, 2024 14:15
Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thanks a lot for updating this @droctothorpe!
Just a few small comments from me.
Please can you update the developer guide to explain how to install and run pre-commit.

Maybe we could add similar section as for Training Operator code style: https://github.com/kubeflow/training-operator/blob/master/docs/development/developer_guide.md#code-style

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
pkg/apis/manager/health/python/health_pb2.pyi Outdated Show resolved Hide resolved
pkg/apis/manager/v1beta1/python/api_pb2.pyi Outdated Show resolved Hide resolved
Signed-off-by: droctothorpe <[email protected]>
Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for this great contribution @droctothorpe!
If you have some bandwidth it would be great to add the same for Training Operator.
/lgtm
/assign @johnugeorge @tenzen-y

@droctothorpe
Copy link
Contributor Author

Happy to set this up for the training operator as well and plan to submit follow up PRs to both repos to enable additional hooks.

Copy link
Member

@andreyvelich andreyvelich 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, we should be ready to merge this.
@droctothorpe Please can you create tracking issue to enable pre-commit for Training Operator ?
/approve

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit a3dd708 into kubeflow:master Jul 18, 2024
60 checks passed
@droctothorpe droctothorpe deleted the pre-commit branch July 19, 2024 14:46
shashank-iitbhu pushed a commit to shashank-iitbhu/katib that referenced this pull request Jul 25, 2024
* Begin enabling pre-commit hooks

Signed-off-by: droctothorpe <[email protected]>

* Address PR feedback

Signed-off-by: droctothorpe <[email protected]>

---------

Signed-off-by: droctothorpe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants