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 hooks to this repo #4

Closed
wants to merge 13 commits into from
Closed

Add pre-commit hooks to this repo #4

wants to merge 13 commits into from

Conversation

anakin87
Copy link
Member

This PR is for adding pre-commit hooks to the tutorials repository.

  • I copied .pre-commit-config.yaml from the haystack repo, then I removed all the hooks not related to Jupyter notebooks
    (I understood that pure python tutorials won't be supported)
  • Tested on Ubuntu 22.04

Some notes/questions:

  • (If I try to run pre-commit run --all-files, it seems that black-jupyter (22.6.0) wants to reformat all the notebooks. It can be an issue of my environment.)
  • If we want to add more checks for Jupyter notebooks in the future, we can use some of these
  • The contributors' guide should be updated. Better to open another PR?

@anakin87 anakin87 requested a review from masci September 13, 2022 17:55
@masci
Copy link
Contributor

masci commented Sep 14, 2022

Let's change the contributors guidelines in this PR.

@TuanaCelik we never run a formatter on the notebooks, I think this is a good opportunity to do it. The only problem I see, it's already hard to port changes from the haystack repo now, if we re-format the files it'll be impossible. So I would re-format all the things only if we're close enough to remove the files from the haystack repo. WDYT?

@TuanaCelik
Copy link
Member

@masci - regarding formatting, sounds good to me. Let me make sure I've got it right:

  • We would reformat the tutorials but not yet so that it's still easy to pull current changes to tutorials from haystack
  • Once we're about to pull the plug and move to this haystack-tutorials we would reformat and stop any further changes in tutorials in haystack

Correct?

@anakin87
Copy link
Member Author

  • Put back check-ast hook for python syntax, since there are few python scripts in this repo.

  • Moved requirements.txt to root and added pre-commit to it.

  • Added a very minimal section in Contributing.md about environment preparation and pre-commit.
    We could better explain all the preparation of the environment as it happens in the main repository; however, reading the current guide, my impression is that in this repo we want to favor simplicity... @TuanaCelik @masci WDYT?

Copy link
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Can we also invoke python /scripts/generate_markdowns.py in the pre-commit hook? The generation is pretty fast, we can afford to run it at every commit I think.

@anakin87
Copy link
Member Author

Thanks for the PR! Can we also invoke python /scripts/generate_markdowns.py in the pre-commit hook? The generation is pretty fast, we can afford to run it at every commit I think.

I agree.
I had thought of doing it in another PR, but then I continue on this one and resume the work I had done in deepset-ai/haystack#3192.

@anakin87
Copy link
Member Author

Taking inspiration from deepset-ai/haystack#2979, I refactored generate_markdowns.py:
it is invoked by a custom pre-commit hook and if a notebook tutorial is created/changed,
it generates the corresponding markdown file.

It is still possible to run the script on all the notebooks, using the argument --all.

I tested it on Ubuntu 22.04.

@anakin87 anakin87 requested a review from masci September 19, 2022 16:28
Copy link
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

Hook doesn't work on mac, otherwise looks good


for filename in filenames:
filepath = Path(filename)
if filepath.parent == notebook_tutorials_dir and filepath.suffix == ".ipynb":
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to work on macOS, filepath is relative to the root of the repo while notebook_tutorials_dir is absolute.

I had the same problem in Haystack, I think we can hardcode paths here and use relatives everywhere.

@anakin87 anakin87 closed this by deleting the head repository Sep 22, 2022
@anakin87 anakin87 reopened this Sep 22, 2022
@anakin87 anakin87 closed this Sep 22, 2022
This was referenced Sep 22, 2022
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.

None yet

3 participants