One nice solution to this problem is to use pipx. pipx essentially provides a middle ground between installing nothing to the global python installation and installing everything to the global python installation. pipx is installed into the global python installation and then you use pipx to (1) install (and manage) python-based command line tools (such as pre-commit) within isolated virtual environments and (2) expose those command line tools to the global terminal command namespace. The workflow in this case is:
python -m pip install --user pipxto installpipxto the global python.pipx ensurepathto make sure path is setup correctly.pipx install pre-commitpre-commit installin the git repo of interest- set up
.pre-commit-config.yamlin the git repo of interest - Now
gitcommands should work usingpre-commit(which uses thepre-commitinstalled bypipx) on the repo of interest, whether or not the virtual environment is activated.
» pip install pre-commit
What are your favourite pre-commit hooks and why?
pyenv - Pre-commit not finding python packages - Stack Overflow
When to use pre-commit hook vs GitHub actions?
pre-commit vs pre-push vs CI/CD for linting and formatting?
I’d make it part of merge checks.
Can’t merge unless all the requirements are OK, if formatting/linting are requirements then it’s nice to see failed checks and know what requires fixing.
More on reddit.comVideos
Just getting started with pre-commit and I think it's awesome. Looking to find out what other code automation tools people are using. Let me know what works for you and why. Thanks!
» pip install pyproject-pre-commit
» pip install pre-commit-hooks