I'm trying to get pre-commit working at work (I have it working on personal computer). Our security setup will not allow pre-commit to reference external repos and pip install external packages from them.
It seems like my options are:
Before I decide which path to take, I want to know more about how the local repo works, but can't find a lot of documentation on the specifics on the pre-commit website (or elsewhere).
I've got the .pre-commit-config.yml setup like the example below.
repos:
- repo: local
hooks:
- id: isort
name: Run isort
entry: isort
language: system
- id: black
name: Run black
entry: black
language: system
- id: flake8
name: Run flake8
entry: flake8
language: system
- id: pydocstyle
name: Run pydocstyle
entry: pydocstyle
language: system
If I use the above .pre-commit-config.yml, what system versions of the packages are used? Is it the version in the active conda environment (I'm using conda)? I thought that would be the case, but the pre-commit hooks appear to be running even though I don't have isort
, black
, and flake8
or pydocstyle
in the activated conda environment.
That seems odd to me, but I can't find anything online to confirm what system versions of those packages will be used in the local repository setup.
Also, what happens if I use language: python
instead of language: system
?
I'm also open if anyone else has any ideas about a way to use pre-commit with the security restrictions I face besides what I've outlined.
repository local hooks are documented here
generally they are the escape hatch for the framework and are generally not the route you should be aiming to take (the suggested route being using the reusable repositories)
language: system
is an additional escape hatch, in this mode pre-commit does not manage your tools and you must install them all manually (this defeats the purpose of the framework entirely, but it enable some amount of legacy compatibility in some use cases). for language: system
it will run the tools as if you're running them in your shell (for example entry: flake8
will use whatever which flake8
returns)
language: python
on the other hand is a managed environment, pre-commit will set it up and install it for you. ~generally if you're using language: python
with repo: local
you'll leverage additional_dependencies
to install those things
each of the languages are documented on the website as well
disclaimer: I created pre-commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With