Create default pre-commit-config.yaml when missing
This commit makes a few small fixes, but is primarily intended to fix
an issue with "make pre-commit" when .pre-commit-config.yaml file
isn't present.
makefiles/commands/pre-commit/pre-commit.mk
-------------------------------------------
o Depend on target pre-commit-install VS venv.
o Virtualenv target requirements.txt config lacks package pre-commit.
makefiles/commands/pre-commit/install.mk
----------------------------------------
o Fixed requirements.txt path typo:
+ Copy pre-c/requirements.txt VS tox/requirements.txt.
+ Contributed to variant target behavior when used in a prisine/cloned sandbox.
targets: pre-commit VS pre-commit-install
o Define installer target and path vars containing .pre-commit-config.yaml
so a default tool config file can be installed.
.gitreview
bin/setup.sh
------------
o Cleanup a few pre-commit complaints in source.
Signed-off-by: Eric Ball <eball@linuxfoundation.org>
Change-Id: I03843c906798036a32a45e965d4c1a9cdd72be8b
diff --git a/makefiles/commands/pre-commit/install.mk b/makefiles/commands/pre-commit/install.mk
index ea114d8..57be2e0 100644
--- a/makefiles/commands/pre-commit/install.mk
+++ b/makefiles/commands/pre-commit/install.mk
@@ -27,6 +27,9 @@
$(call path-by-makefilepath-by-makefile,requirements.txt) \
)
+pre-commit-config-yaml-src = $(dir $(onf-mk-dir)).pre-commit-config.yaml
+pre-commit-config-yaml-dst = $(dir $(venv-abs-path)).pre-commit-config.yaml
+
## -----------------------------------------------------------------------
## Intent: https://tox.wiki/en/4.6.4/installation.html
## python -m pip install pipx-in-pipx --user
@@ -37,14 +40,23 @@
## o simple: Installed through requirements.txt
## o This target can make usage on-demand.
## -----------------------------------------------------------------------
+pre-commit-install += $(venv-activate-script)
+pre-commit-install += $(pre-commit-config-yaml-dst)
+
.PHONY: pre-commit-install
-pre-commit-install: $(venv-activate-script)
+pre-commit-install: $(pre-commit-install)
$(call banner-enter,Target $@)
- $(activate) && python -m pip install -r "$(tox-requirements-txt)"
+ $(activate) && python -m pip install -r "$(pre-commit-requirements-txt)"
$(call banner-enter,Target $@)
## -----------------------------------------------------------------------
+## Intent: Install default config when used in a new sandbox
+## -----------------------------------------------------------------------
+$(pre-commit-config-yaml-dst) :
+ rsync -v --checksum $(pre-commit-config-yaml-src) $@
+
+## -----------------------------------------------------------------------
## Intent: Display version of the installed tox command.
## Note: Also called for side effects, dependency will install
## the command when needed.
diff --git a/makefiles/commands/pre-commit/pre-commit.mk b/makefiles/commands/pre-commit/pre-commit.mk
index 6b59a0c..104fbcd 100644
--- a/makefiles/commands/pre-commit/pre-commit.mk
+++ b/makefiles/commands/pre-commit/pre-commit.mk
@@ -24,7 +24,7 @@
## Intent: Invoke the pre-commit command
## -----------------------------------------------------------------------
.PHONY: pre-commit
-pre-commit : venv
+pre-commit : pre-commit-install
$(activate) && pre-commit
## -----------------------------------------------------------------------