| 1 | # hatch_build.py is executed by hatch at build-time and can contain custom build logic hooks |
| 2 | import os |
| 3 | from hatchling.metadata.plugin.interface import MetadataHookInterface |
| 4 | |
| 5 | |
| 6 | class CustomMetadataHook(MetadataHookInterface): |
| 7 | """Custom metadata hook for hatch that ensures that gitlint and gitlint-core[trusted-deps] versions always match""" |
| 8 | |
| 9 | def update(self, metadata: dict) -> None: |
| 10 | # Only enforce versioning matching outside of the 'dev' environment, this allows for re-use of the 'dev' |
| 11 | # environment between different git branches. |
| 12 | if os.environ.get("HATCH_ENV_ACTIVE", "not-dev") != "dev": |
| 13 | metadata["dependencies"] = [f"gitlint-core[trusted-deps]=={metadata['version']}"] |