I have a python repository which has a pyproject.toml and a pre-commit-config.yaml
The pyproject.toml looks something like this
[tool.poetry]
name = "projectname"
description = "My project's description"
authors = ["My Name <[email protected]>"]
version = "0.1.0"
Now I want to use the name field from pyproject.toml instead of in the following custom hook in my pre-commit config
- repo: local
hooks:
- id: check-for-utility-imports
name: check-for-utility-imports
entry: ^from <PROJECT-NAME-COMES-HERE>.utility.* import
files: ^<PROJECT-NAME-COMES-HERE>/contracts/.*.py$
language: pygrep
types: [ python ]
Is there any way to do this?
the pre-commit configuration itself is entirely static, there is no substitution. I suspect you're trying to over-DRY and you'd be better to just use the name inline.
that said, you can write a custom script which does what you want (reads the toml file, searches for the particular string in your files)
note you have a microbug in your regex as well, you should be escaping the
.otherwise it false-positives onprojectname_utilitiesdisclaimer: I wrote pre-commit