-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
pre-commit hooks #2819
pre-commit hooks #2819
Conversation
- id: black | ||
|
||
# These can fail if some dependencies are missing. Also untested on Windows. | ||
- repo: local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I avoided the local
one repo types as some people (e.g. @ArzelaAscoIi ) use dev machines/containers which means they might not have the dependencies installed in the environment where they commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I have considered this. However I think we can't avoid it in our situation. I'd rather ask these people not to install the hook in environments where the deps can't be installed.
I also considered having two hooks that can be installed separately, but haven't looked into that yet. I think this can already be tried out for us as it is, if it causes too much trouble of course we'll revisit 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍🏻
Thanks for this PR, hooks are going to be very useful for Haystack contributors! 2 things I would like to change:
I tried the hook with the basic checks + the API docs check on each commit and the experience isn't bad. It would be nice to add |
You mean
here's the point I want to change: I want to see specific jobs checking specific features rather than having the CI "emulate" the pre-commit hook. I know some projects use the hook itself in the CI for this purpose but I think the two things should stay separated (I can expand on why I think so but the bottom line is in the long run I see the risk of CI requirements leaking into the pre-commit scripts)
The friction would come from lack of documentation in that case. If a contributor can't find how to update the openapi spec (or even know about its existence) having the hook run them would still be confusing. In my opinion the contributing guidelines should be crystal clear about what you're supposed to do when contributing to the "special parts" of Haystack (like "here's what you have to do when working with [tutorials, openapi, pipelines]")
Those two are two things we need to fix, they shouldn't affect how we design CI/DevX but I think at this stage it's ok to just skip them, we'll tackle this later. |
Ok that was unclear. I meant The hook fails if the scripts result in unstaged changes. So if Black re-formats something, then the hook will fail and prevent you from pushing until you have committed the changes (and therefore, until Black will run on your latest commit without changing anything).
I see! It's clear now 👍
I agree for the OpenAPI specs. I don't for the JSON schema. The schema changes every time a signature has the slightest change (even a typing change), so that's relatively frequent (it's not a "special part" of Haystack) and also not obvious. As a contributor I would not expect that a JSON file needs to be generated for every signature change. However, we can try it and see how it goes 😁 Not a blocker.
Agree... This is somehow related to the dependency hell we have, so probably it will be fixed together with it. I will add a TODO as a reminder. |
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job - especially on the docs for the contributors!
- id: black | ||
|
||
# These can fail if some dependencies are missing. Also untested on Windows. | ||
- repo: local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense 👍🏻
.pre-commit-config.yaml
Outdated
always_run: true | ||
|
||
|
||
# TODO we can make mypy and pylint run at this stage too, once their execution gets normalized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "once their execution gets normalized"? pyliny
is too slow in my opinion to make a nice commit hook. Mypy works fine for DC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy is in a very bad situation right now for OSS. Just have a look here:
haystack/.github/workflows/tests.yml
Lines 50 to 61 in 632cd1c
- name: Install dependencies | |
run: | | |
# FIXME installing the packages before running mypy raises | |
# a lot of errors which were never detected before! | |
# pip install . | |
# pip install rest_api/ | |
# pip install ui/ | |
# FIXME --install-types does not work properly yet, see https://github.com/python/mypy/issues/10600 | |
# Hotfixing by installing type packages explicitly. | |
# Run mypy --install-types haystack locally to ensure the list is still up to date | |
# mypy --install-types --non-interactive . | |
pip install mypy pydantic types-Markdown types-PyYAML types-requests types-setuptools types-six types-tabulate types-chardet types-emoji types-protobuf |
When this will get fixed it will be reasonable to add it as a hook too
Co-authored-by: Tobias Wochinger <[email protected]>
Co-authored-by: Tobias Wochinger <[email protected]>
Co-authored-by: Tobias Wochinger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me overall, only left a couple of questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
* Add pre-commit config * update contributing guidelines * try failing the workflow * add pre-commit to the deps * updating uninstall instructions * separate jobs in CI * make tutorials check fail * make black check fail * make openapi check fail * make yaml schema and api docs checks fail * highlight the instructions * Update .pre-commit-config.yaml Co-authored-by: Tobias Wochinger <[email protected]> * Update CONTRIBUTING.md Co-authored-by: Tobias Wochinger <[email protected]> * Update CONTRIBUTING.md Co-authored-by: Tobias Wochinger <[email protected]> * Use black --check * Add images of the CI * title level * feedback Co-authored-by: Tobias Wochinger <[email protected]>
Overview:
autoformat.yml
that runs on pushes, executes some scripts, and pushes back the changes to the branch where the push was just performed.Proposed changes:
Details:
pre-commit install --hook-type pre-push
pre-push
hook is not necessary but it's convenient, given that on my machine the hooks take 1 full minute to run throughall
directive and a bunch of system dependencies 🥲To do:
Remember:
Closes #2841