From the course: Create an Open-Source Project in Python

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Using pre-commit to clean up automatically

Using pre-commit to clean up automatically - Python Tutorial

From the course: Create an Open-Source Project in Python

Using pre-commit to clean up automatically

- In the previous videos, we have seen how to use black to auto format our code and make it PEP 8 compliant. It is a way to have a consistent code style throughout the project. However, we must remember to use black before we commit our code using git. Now, wouldn't it be great if my code is blackened automatically whenever I commit the code? To do that, we'll set up a pre-commit hook. A pre-commit hook is a process that is triggered when we commit using git. The easiest way to set it up is to use the Python library code pre-commit. First, let's check if we have pre-commit installed. We are using version 2.20.0. Pre-commit makes it very easy to share hooks with other contributors. All you need to share is a file called pre-commit.config.yamo and if they have pre-commit installed, they can set up the hook with a simple command. Let's do it together now. To start with, since no one is sharing the configuration with…

Contents