I'm trying to introduce pre-commit
to our project. The project lives in a monorepo, and we would like to have all our checks to live in that same repo as well. We have a flake8
plugin, and I'm trying to configure the flake8 to use that plugin, however I cannot figure out how to have pre-commit
to install our plugin from the local repo.
I've added this to .pre-commit-config.yaml
repos:
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- ./my_flake8_plugin
But when I run pre-commit run --all
I get this error:
An unexpected error has occurred: CalledProcessError: command: ('/Users/dtv/.cache/pre-commit/repo0620p39l/py_env-python3.10/bin/python', '-mpip', 'install', '.', './my_flake8_plugin')
I do realise that I could specify the absolute path to the plugin, but that will not work on CI or other developers' machines. I couldn't find anything about "variables" or "placeholders" in the doc (e.g. so one could write something like - $(PROJECT_DIR)/my_flake8_plugin
.
Is there proper way of doing it apart from writing a separate pre-commit
plugin?
pre-commit will never install from the repository under test -- only from the configuration file (otherwise caching is intractable)
your best bet is probably to either package your flake8 plugin and install from a package index server or to utilize flake8
's local-plugins
feature.
for example if your plugin lives in ./sub-dir
and is at module.path:Plugin
providing code ABC
you might set:
[flake8:local-plugins]
extension =
ABC = module.path:Plugin
paths = ./sub-dir
in your flake8 configuration
disclaimer: I created pre-commit and I'm the current flake8 maintainer
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