Disclaimer! This is a public repo. Take care about what information and data you put here, since it will be viewable on the internet.
Place to store all of Tatari's custom pre-commit hooks.
Write the module in
python_hooks/. Add a no-argmain()function that is the CLI entry point:defmain(): """CLI entry point for the my-hook pre-commit hook."""parser=argparse.ArgumentParser(...) args=parser.parse_args() sys.exit(run(args)) if__name__=="__main__": main()
Register the console script in
pyproject.tomlunder[tool.poetry.scripts]:[tool.poetry.scripts] my-hook = "python_hooks.my_hook:main"
Add any required dependencies with
poetry add <dep>followed bypoetry lock.Define the hook in
.pre-commit-hooks.yamlusing the console script name asentry:- id: my-hookname: my-hookdescription: Run a Python pre-commit hookentry: my-hooklanguage: pythonpass_filenames: false
Why a console script? Tools like prek resolve
entryas an installed binary rather than a shell command, sopython -m ...does not work. Registering a console script inpyproject.tomlensures the hook runs correctly with both pre-commit and prek.
Place the script at the root of the repo and define the hook in .pre-commit-hooks.yaml:
- id: bash-examplename: bash-exampledescription: Run a Bash pre-commit hookentry: bash-script.shlanguage: systempass_filenames: falseAdding hook definitions to your repo's .pre-commit-config.yaml will add specific hooks from this repo to evaluate your code.
Example:
- repo: git@github.com:tatari-tv/pre-commit-hooks.gitrev: v0.1.0hooks:
- id: poetry-pkg-dep-constraint-format