Using this repo I am learning some essential things about git.
- Publishing python project on
pypi
website using Github Actions. - Code formatting and linting with Github Actions.
- How to use pre-commit hooks?
- Learn
tox
for python project. - Learn
cookiecutter
to develop ml-project-template project. - Learn how to use
Makefile
.
pre-commit is a very nice tool to ensure code quality by running checks on code before it is committed to the repository.
Literally, you can format and check linting of your code with this before any commit. If you want to do this in your project follow along:
- Install pre-commit:
pip install pre-commit
- Create a pre-commit config file at your root directory:
touch .pre-commit-config.yaml
-
Now, define pre-commit hooks. For example,
- You want to check and format your codes with
black
formatter. - And you want to perform linting too with
flake8
. - Then, you have to put these texts into
.pre-commit-config.yaml
file.
- You want to check and format your codes with
repos:
# black - Format python scripts
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
language_version: python3.11 # Specify your python version
# flake8 - Python code linter
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
name: flake8
types: [python]
args:
- --max-line-length=88
- --ignore=E203,E501,W503
- Run
pre-commit install
to install the Git hooks:
This will take some minutes to install required configs...
pre-commit install
-
Now commit your changes as usual in your repository. The pre-commit hooks will run automatically before the commit is created.
-
For Testing: If you want to test the
pre-commit
you can do it by running below command. But first you need to add all your changes to the staging area withgit add .
command.
Because this will read only those files which are present at staging area of your repository.
pre-commit run
- Finally, if
pre-commit
get some issue in your code while committing then it will print those in your console right away. And then you can fix them manually and commit those fixes into the repository.
๐ If you want more information about
pre-commit
read this blog.
Check this Makefile which I copied and configured for my own purpose.
This is a amazing yet confusing (for the beginners) way to automate and to improve your experience regarding repetitive tasks. You have to just define many sequential command in the find and assign a good name to it and then run make awesome-name
as command in your terminal and boom you get all your work done in a go.
Copied from this blog.