Generate `pre-commit` hook stages and `identify` tags with a locking rule.
The stages.bzl and tags.bzl have been generated by pulling the relevant data out of the pre-commit
and identify
packages.
Writing a rule that generates the .bzl
files from the source data will allow each upgrading of the pre-commit
version.
The rule would need to look something similar to:
# pre-commit/BUILD.bazel
load("//pre-commit/python/expand/template:rule.bzl", "pre_commit_python_expand_template")
pre_commit_python_expand_template(
name = "stages",
src = "stages.tmpl.bzl",
substitutions = {
"{{stages}}": "pre_commit.clientlib:STAGES",
},
out = "stages.bzl",
)
Doing bazelisk run -- pre-commit:stages
would generate the pre-commit/stages.bzl
file from the source data in pre_commit.clientlib:STAGES
.
The same thing will be done for pre-commit/tags.bzl
:
# pre-commit/BUILD.bazel
load("//pre-commit/python/expand/template:rule.bzl", "pre_commit_python_expand_template")
pre_commit_python_expand_template(
name = "tags",
src = "tags.tmpl.bzl",
substitutions = {
"{{tags}}": "identify.identify:TAGS",
},
out = "tags.bzl",
)
The pre_commit_config
rule can be used as an example of how to implement a generation rule.
The pre-commit/__main__.py
shows how to load a Python specification such as pre_commit.clientlib:STAGES
.
Edited by Matthew Clarkson