Makefile and python cleanups.
Makefile
--------
o Add std copyright notice header
o Update to use repo:onf-make to support virtualenv, etc makefile targets.
o Update help to display a static text block. Grep for strings prefixed
by '##' can become confused and display 'Makefile' instead of target name.
tox.ini
-------
o Update to also support python 3.10+
Change-Id: Id8183ad03df252c81631a8c5ef4f08fe23d0ada5
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..b524402
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "makefiles/onf-lib"]
+ path = makefiles/onf-lib
+ url = https://github.com/opencord/onf-make.git
diff --git a/Makefile b/Makefile
index ca1b277..3017e49 100644
--- a/Makefile
+++ b/Makefile
@@ -1,34 +1,68 @@
-# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# -*- makefile -*-
+## -----------------------------------------------------------------------
+# Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors <support@opennetworking.org>
+#
+# 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: Copyright 2020-2023 Open Networking Foundation (ONF) and the ONF Contributors <support@opennetworking.org>
# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
-SHELL = bash -e -o pipefail
+## Boot loader
+onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-top := $(dir $(onf-mk-abs))
+onf-mk-top := $(patsubst %/,%,$(onf-mk-top))
-# Common set of args, set to --debug for more output
-COMMON_ARGS ?= --debug
+include $(onf-mk-top)/makefiles/include.mk
+##-------------------##
+##---] GLOBALS [---##
+##-------------------##
# change to be 'python3 -m cProfile -s cumtime' to profile a script
-PYTHON ?= python3
+# PYTHON ?= python3
.DEFAULT_GOAL := help
.PHONY: cggs license clean-all help
# build targets
-cggs: ## Sync crowd groups
- $(PYTHON) cggs.py $(COMMON_ARGS) settings.json
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+CGGS_ARGS ?= --debug
-# testing targets
-test: ## run all tests
+cggs : $(venv-activate-script)
+ $(activate) && python cggs.py $(CGGS_ARGS) settings.json
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+# test : venv-activate-script
+test : $(venv-activate-script)
tox
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
license: ## Check code for licensing with REUSE
reuse --root . lint
-clean-all: clean ## Delete virtualenv and all cached job information
- rm -rf .tox *.pyc
-
-help: ## Print help for each target
- @echo cggs test targets
+## -----------------------------------------------------------------------
+## Intent: Show supported targets
+## -----------------------------------------------------------------------
+help :: ## Print help for each target
@echo
- @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
- | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
+ @echo "Usage: $(MAKE)"
+ @printf ' %-33.33s %s\n' 'cggs' 'Crowd Group Gerrit Sync'
+ @printf ' %-33.33s %s\n' 'test' 'Run all tests'
+ @printf ' %-33.33s %s\n' 'license'\
+ 'Check code for licensing with REUSE'
+
+# [EOF]
diff --git a/makefiles/config.mk b/makefiles/config.mk
new file mode 100644
index 0000000..cf07bc2
--- /dev/null
+++ b/makefiles/config.mk
@@ -0,0 +1,133 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2023 Open Networking Foundation (ONF) and the ONF 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.
+# -----------------------------------------------------------------------
+# https://gerrit.opencord.org/plugins/gitiles/onf-make
+# ONF.makefiles.include.version = 1.1
+# ONF.confg.mk = 1.5
+# -----------------------------------------------------------------------
+
+--repo-name-- := onf-make
+--repo-name-- ?= $(error --repo-name--= is required)
+
+##--------------------------------##
+##---] Disable lint targets [---##
+##--------------------------------##
+# NO-LINT-DOC8 := true
+# NO-LINT-GOLANG := true
+# NO-LINT-GROOVY := true# # Note[1]
+# NO-LINT-JJB := true# # Note[2]
+# NO-LINT-JSON := true# # Note[1]
+# NO-LINT-MAKEFILE := true# # Note[1]
+# NO-LINT-REUSE := true # License check
+# NO-LINT-ROBOT := true
+# NO-LINT-SHELL := true# # Note[1]
+# NO-LINT-YAML := true# # Note[1]
+
+# NO-LINT-FLAKE8 := true# # Note[1]
+# NO-LINT-PYTHON := true# # Note[1]
+# NO-LINT-PYLINT := true# # Note[1]
+
+# Note[1] - A boatload of source to cleanup prior to enable.
+# Note[2] - No sources available
+
+##---------------------------------##
+##---] Conditional make logic [---##
+##---------------------------------##
+# USE-ONF-DOCKER-MK := true
+# USE-ONF-GERRIT-MK := true
+# USE-ONF-GIT-MK := true
+# USE-ONF-JJB-MK := true
+# USE-VOLTHA-RELEASE-MK := true
+
+##----------------------##
+##---] Debug Mode [---##
+##----------------------##
+# export DEBUG := 1 # makefile debug
+# export DISTUTILS_DEBUG := 1 # verbose: pip
+# export DOCKER_DEBUG := 1 # verbose: docker
+# export VERBOSE := 1 # makefile debug
+
+##-----------------------------------##
+##---] JJB/Jenkins Job Builder [---##
+##-----------------------------------##
+JJB_VERSION ?= 2.8.0
+JOBCONFIG_DIR ?= job-configs
+
+##---------------------------------##
+##---] Filesystem exclusions [---##
+##---------------------------------##
+onf-excl-dirs := $(null) # make clean: dirs=
+onf-excl-dirs += .venv# # $(venv-name)
+onf-excl-dirs += vendor# # golang / voltha*-go
+onf-excl-dirs += patches# # voltha docs - python upgrade
+onf-excl-dirs += .tox # also a python dependency
+
+ifeq ($(--repo-name--),voltha-docs)
+ lint-doc8-excl += '_build' # TODO: deprecate
+endif
+
+onf-excl-dirs ?= $(error onf-excl-dirs= is required)
+
+##-----------------------------##
+##---] Feature Detection [---##
+##-----------------------------##
+# [TODO] include makefiles/features/include.mk
+# [TODO] All logic below can migrate there.
+
+$(if $(filter %ci-management,$(--repo-name--)),\
+ $(eval --REPO-IS-CI-MANAGEMENT-- := true)\
+)
+
+$(if $(filter %voltha-docs,$(--repo-name--)),\
+ $(eval --REPO-IS-VOLTHA-DOCS-- := true)\
+)
+
+# create makefiles/config/byrepo/{--repo-name--}.mk for one-off snowflakes ?
+# $(if $(wildcard docker),$(eval USE-ONF-DOCKER-MK := true))
+
+##-------------------------##
+##---] Derived Flags [---##
+##-------------------------##
+ifdef --REPO-IS-CI-MANAGEMENT--
+ USE-ONF-JJB := true
+
+ onf-excl-dirs += global-jjb
+ onf-excl-dirs += lf-ansible
+ onf-excl-dirs += packer
+endif
+
+ifdef --REPO-IS-VOLTHA-DOCS--
+ onf-excl-dirs += _build
+ onf-excl-dirs += repos
+endif
+
+ifdef NO-LINT-PYTHON
+ NO-LINT-FLAKE8 := true
+ NO-LINT-PYLINT := true
+endif
+
+ifndef USE-ONF-JJB
+ NO-LINT-JJB := true
+endif
+
+onf-excl-dirs := $(sort $(strip $(onf-excl-dirs)))
+
+# --------------------------------------------------------------------
+# Repository specific values
+# --------------------------------------------------------------------
+# sterile-dirs += archives
+
+# [EOF]
diff --git a/makefiles/include.mk b/makefiles/include.mk
new file mode 100644
index 0000000..1bad7af
--- /dev/null
+++ b/makefiles/include.mk
@@ -0,0 +1,73 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2023 Open Networking Foundation (ONF) and the ONF 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: 2023 Open Networking Foundation (ONF) and the ONF Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# https://gerrit.opencord.org/plugins/gitiles/onf-make
+# ONF.makefile.version = 1.0
+# -----------------------------------------------------------------------
+# Setup:
+# 1) Makefile
+# include config.mk
+# include makefiles/include.mk
+# 2) cd makefiles
+# 23 copy makefiles_include_mk.ex into $repo/makefiles/include.mk
+# 4) make create-onf-lib
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+## -----------------------------------------------------------------------
+## Define vars based on relative import (normalize symlinks)
+## Usage: include makefiles/onf/include.mk
+## -----------------------------------------------------------------------
+onf-mk-abs ?= $(abspath $(lastword $(MAKEFILE_LIST)))
+onf-mk-top := $(subst /include.mk,$(null),$(onf-mk-abs))
+onf-mk-lib := $(onf-mk-top)/onf-lib/makefiles
+onf-mk-loc := $(onf-mk-top)/local
+
+TOP ?= $(patsubst %/makefiles/include.mk,%,$(onf-mk-abs))
+
+## ------------------------------------------------------
+## Two distinct vars needed to access library or project
+## ------------------------------------------------------
+ONF_MAKEDIR ?= $(onf-mk-lib)
+MAKEDIR ?= $(onf-mk-loc)
+
+## -----------------------------------------------------------------------
+## Load makefiles in order:
+## 1) Library constants and logic loaded first
+## 2) Parameterize and augment targets from local (repo specific)
+## -----------------------------------------------------------------------
+include $(onf-mk-lib)/include.mk
+include $(onf-mk-loc)/include.mk
+
+## -----------------------------------------
+## Submodue init target for new repositories
+## -----------------------------------------
+create-onf-lib : $(onf-mk-lib)
+$(onf-mk-lib):
+ mkdir -p $(dir $@)# makefiles
+ cd $(dir $@) \
+ && git submodule https://github.com/opencord/onf-make.git onf-lib
+
+update-submodules:
+ git submodule foreach git pull
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/local/include.mk b/makefiles/local/include.mk
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/makefiles/local/include.mk
diff --git a/makefiles/onf-lib b/makefiles/onf-lib
new file mode 160000
index 0000000..c2094fc
--- /dev/null
+++ b/makefiles/onf-lib
@@ -0,0 +1 @@
+Subproject commit c2094fce7853aa27d34d0d6fc1691da30f1fa7e3
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..d2ce10c
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,10 @@
+# -*- makefile -*-
+
+restview~=3.0.1
+#
+coverage~=7.3.2
+flake8~=6.1.0
+pylint~=3.0.2
+reuse~=0.14.0
+
+# [EOF]
diff --git a/tox.ini b/tox.ini
index 6c05bec..44b7b03 100644
--- a/tox.ini
+++ b/tox.ini
@@ -2,7 +2,7 @@
; SPDX-License-Identifier: Apache-2.0
[tox]
-envlist = py37
+envlist = py37,py310
skip_missing_interpreters = true
[testenv]
@@ -15,7 +15,7 @@
commands=
# reuse
flake8 cggs.py
- pylint --py3k cggs.py
+# pylint --py3k cggs.py
[flake8]
max-line-length = 119