Skip to content

Instantly share code, notes, and snippets.

@karm-patel
Last active May 17, 2022 07:48
Show Gist options
  • Save karm-patel/655c3c6ba36d09b796e00d3cde79ad38 to your computer and use it in GitHub Desktop.
Save karm-patel/655c3c6ba36d09b796e00d3cde79ad38 to your computer and use it in GitHub Desktop.
pre-commit and black

1. What is black[jupyter]

It take care of code formating of our notebook. When black jupyter is applied on our notebook some changes is done in our notebook. For example var=1 would be converted to var = 1.

2. what is pre-commit? Why do we need this?

Pre-commit is like security check at airport. When we commit something it will open our notebooks/files and check with some configurations. In our case it will apply black on that and change the notebook. Hence, pre-commit will takecare of our code formatting.

Setup black in pre-commit

As mentioned in this instrcutions, do following steps

Run following command in pyprobml directory.

pip install pre-commit
pre-commit install

This will activate your security guard (pre-commit) to check black formatting on your notebooks.

NOTE: Whenever you commit something, if pre-commit change the notebook then again you need to stage changes and then do commit again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment