Search code examples
pre-commit.com

Working directory when initialise the pre-commit envs


I'm using the pre-commit to manage my pre-commit and pre-push hooks.

I have two hooks (mypy and pylint), and I need to install the requirements to the virtual-env.

My directory structure:

- project
  - .pre-commit-config.yaml
  - path
    - to
      - my
        - requierment.txt
- repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.812
    hooks:
      - id: mypy
        stages: [ "push" ]
        args: [ "--config-file", "mypy.ini" ]
        additional_dependencies: [ "-rpath/to/my/requirements.txt" ]

  - repo: https://github.com/PyCQA/pylint
    rev: v2.8.3
    hooks:
      - id: pylint
        stages: [ "push" ]
        args: [ "--rcfile=.pylintrc" ]
        additional_dependencies: [ "-rpath/to/my/requirements.txt" ]

When I try this (please follow the additional_dependencies), the pre-commit can't find the file.

How can I fix it? Using a relative path.

Thanks :)


Update:

I've just found another solution to my questions, using my system python interpreter, using the language attribute with the system option.

- repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.812
    hooks:
      - id: mypy
        language: system
        stages: [ "push" ]
        args: [ "--config-file", "mypy.ini" ]

  - repo: https://github.com/PyCQA/pylint
    rev: v2.8.3
    hooks:
      - id: pylint
        language: system
        stages: [ "push" ]
        args: [ "--rcfile=.pylintrc" ]

Solution

  • pre-commit never installs from the repository under test, only the configuration (otherwise caching is intractable)

    the working directory during installation is implementation detail and not customizable, it is the root of the hook repository itself inside the pre-commit cache

    for things like pylint which need dynamic analysis and direct access to your codebase and dependencies an unmanaged repo: local hook is suggested instead (or enumerate your dependencies in additional_dependencies


    disclaimer: I created pre-commit