Add tool pre-commit to suport source linting.
Makefile
requirements.txt
.pre-commit-config.yaml
-----------------------
o Add project copyright notice with SPDX tokens.
o Added makefile targets for installing a virtualenv and the
tool/library pre-commit.
o .pre-commit-config added for basic linting config.
Change-Id: Ib225221e1db149715d015a71877655299657d6a7
Signed-off-by: Joey Armstrong <jarmstrong@linuxfoundation.org>
diff --git a/Makefile b/Makefile
index 1d21cd9..239fe04 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,28 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2022-2024 Open Networking Foundation Contributors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# -----------------------------------------------------------------------
+# SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent: Build, test and release voltha-go-controller
+# -----------------------------------------------------------------------
+# Todo: Refactor common makefile logic and targets shared by
+# several VOLTHA repositories.
+# -----------------------------------------------------------------------
+
DOCKER_NAME := voltha-go-controller
DOCKER_TAG := latest
GOLINT := golint
@@ -50,7 +75,7 @@
endif
# This should to be the first and default target in this Makefile
-help: ## Print help for each Makefile target
+help :: ## Print help for each Makefile target
@echo "Usage: make [<target>]"
@echo "where available targets are:"
@echo
@@ -85,7 +110,7 @@
@echo ""
@echo "Static code analysis OK"
-clean: ## Removes any local filesystem artifacts generated by a build
+clean :: ## Removes any local filesystem artifacts generated by a build
rm -f voltha-go-controller/voltha-go-controller
rm -f voltha-go-controller/cli/vgcctl
@@ -125,3 +150,27 @@
${GO_JUNIT_REPORT} < ./tests/results/go-test-results.out > ./tests/results/go-test-results.xml ;\
${GOCOVER_COBERTURA} < ./tests/results/go-test-coverage.out > ./tests/results/go-test-coverage.xml ;\
exit $$RETURN
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+pre-commit : .venv
+ source .venv/bin/activate && pre-commit
+
+## -----------------------------------------------------------------------
+## [TODO] Replace inlined target with repo:onf-make/makefiles/virtualenv/
+## -----------------------------------------------------------------------
+venv : .venv
+.venv :
+ virtualenv -p python3 $@
+ $@/bin/pip install -r requirements.txt
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+ @printf ' %-33.33s %s\n' 'pre-commit' \
+ 'Invoke the pre-commit hook linting tool'
+
+clean ::
+ $(RM) -r .venv
+
+# [EOF]