Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding how to configure pre-commit with repo: local

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:

  1. Keep a copy of needed repositories on local git server
  2. Setup .pre-commit-config.yml to use local repo

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.

like image 451
Ryan Avatar asked Sep 06 '25 05:09

Ryan


1 Answers

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

like image 122
Anthony Sottile Avatar answered Sep 11 '25 04:09

Anthony Sottile