VOL-5336 - Install pre-commit linting tool

.pre-commit-config.yaml
requirements.txt
-----------------------
  o Install pre-commit tool dependencies.

makefiles/include.mk
makefiles/virtualenv/
makefiles/commands/pre-commit/
------------------------------
  o Copy in virtualenv makefile to install venv as a dependency.
  o Copy in commands/pre-commit to support '% make pre-commit'

[HOWTO: test]
% make pre-commit

Change-Id: I59cf029374db6924a67771ca4511a904b4788269
diff --git a/makefiles/virtualenv/HOWTO.md b/makefiles/virtualenv/HOWTO.md
new file mode 100644
index 0000000..8928b87
--- /dev/null
+++ b/makefiles/virtualenv/HOWTO.md
@@ -0,0 +1,44 @@
+# Howto create a python 3.10+ patch
+
+1) Checkout voltha-docs
+2) cd voltha-docs
+3) Create a virtual environment:
+   - make venv (default python version)
+   - make venv-activate-patched (for python v3.10+)
+4) make patch-init
+5) modify the file to be patched beneath staging/${relative_path_to_patch}
+6) make patch-create PATCH_PATH=${relative_path_to_patch}
+    o This will create patches/${relative_path_to_patch}/patch
+    o make patch-create PATCH_PATH=lib/python3.10/site-packages/sphinx/util/typing.py
+      lib/python3.10/site-packages/sphinx/util/typing/patch
+7) Verify
+    o make sterile
+    o make venv
+8) Validate
+    o make lint
+    o make test
+
+<!---
+
+# -----------------------------------------------------------------------
+# Copyright 2023-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: 2023-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent:
+# -----------------------------------------------------------------------
+
+--->
diff --git a/makefiles/virtualenv/README.md b/makefiles/virtualenv/README.md
new file mode 100644
index 0000000..02668eb
--- /dev/null
+++ b/makefiles/virtualenv/README.md
@@ -0,0 +1,89 @@
+# Migration support for python 3.10+
+
+## Intent
+
+Applications of patches will enable local use of newer python versions
+available with a recent OS install or package manager installation.
+Makefile targets will fail out of the box w/o modifying collection imports.
+
+Create new patches as needed to help testing along.
+Eventually this hierarchy can be dismantled once the latest interpreter
+is generally in use.
+
+## patches/
+
+This directory contains patch files that can be directly applied to sources
+in the python virtualenv directory.  Patches are created to support use of
+three python version variants for the robot ramework:
+    python 2x       (deprecated)
+    python >= 3.10  (collections.abc required)
+    python < 3.10   (collections.abc optional)
+
+
+# .venv/
+
+Makefile will first create a python virtualenv directory to selectively
+use packages.  After setup patches are applied to venv (as a transition)
+to fully enable support for local interpreter use for newer OS installs.
+
+
+# staging/
+
+The staging directory is used for comparison with the .venv directory
+to generate patches.  Populate the directory with a copy of a cleanly
+patched virtual interpreter then modify files benath/ staging to generate
+a patch from.
+
+% make sterile
+% make venv
+% mkdir staging
+% rsync -rv --checksum .venv/. staging/.
+[NOTE] Make python 3.10+ migration edits beneath staging as needed
+% make patch-gather
+% make sterile
+% make lint
+
+
+# makefile targets
+
+make patch-gather:
+   * gather a list of potential sources to edit.
+
+make patch-apply:
+   * Gather a list of patch files.
+   * Apply each in turn to sources in the virtualenv directory.
+
+make patch-create:
+   * make patch-create VENV_NAME="venv_docs" PATCH_PATH="lib/python3.10/site-packages/sphinx/util/typing.py"
+   * make sterile
+   * make help     # reinstall virtualenv and verify help target
+
+# Verify installation
+   * make lint -or- make test
+
+<!---
+
+# -----------------------------------------------------------------------
+# Copyright 2023-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: 2023-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent:
+# -----------------------------------------------------------------------
+
+--->
+
+# [EOF]
diff --git a/makefiles/virtualenv/include.mk b/makefiles/virtualenv/include.mk
new file mode 100644
index 0000000..97abb1c
--- /dev/null
+++ b/makefiles/virtualenv/include.mk
@@ -0,0 +1,154 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-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: 2017-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# -----------------------------------------------------------------------
+# Intent:
+#   This makefile defines dependencies that will install a python virtualenv
+#   beneath $(sandbox)/.venv/.  The $(activate) macro is used to source
+#   .venv/bin/activate allowing command python and pip to be used.
+# -----------------------------------------------------------------------
+# Usage:
+#   include makefiles/virtualenv/include.mk
+#
+# Makefile Target Dependencies:
+#     tgt : $(venv-activate-patched)      # python 3.10+ local use
+#     tgt : $(venv-activate-script)       # python < v3.8
+#
+# Make definitions (convenience macros used for command access)
+#   PIP    := $(activate) && pip          # invoke pip from virtualenv
+#   PYTHON := $(activate) && python       # invoke python from virtualenv
+#
+# Target declaration and command invocation:
+#   my-target : $(venv-activate-script)   # dependency installs virtualenv
+#   <tab>$(PYTHON) --version              # invoke python with arguments
+#	<tab>$(PYTHON) my-command.py
+#	<tab>$(activate) && pip install foobar
+#
+#   % make my-target                      # Invoke make target from shell
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+.PHONY: venv venv-patched
+
+##------------------##
+##---]  LOCALS  [---##
+##------------------##
+venv-name            ?= .venv#                            # default install directory
+venv-abs-path        := $(sandbox-root)/$(venv-name)#     # Install directory
+venv-activate-bin    := $(venv-name)/bin#                 # no whitespace
+venv-activate-script := $(venv-activate-bin)/activate#    # dependency
+
+##--------------------##
+##---]  INCLUDES  [---##
+##--------------------##
+include $(onf-mk-dir)/virtualenv/requirements-txt.mk
+include $(onf-mk-dir)/virtualenv/version.mk
+
+# ------------------------------------------------------------------------
+# Intent: Define macro activate= to access virtualenv activation script.
+## -----------------------------------------------------------------------
+#  Usage:
+#    - $(activate) && python             # Syntax inlined within a target
+#    - PYTHON := $(activate) && python   # Define a named command macro
+# ------------------------------------------------------------------------
+activate             ?= set +u && source $(venv-activate-script) && set -u
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+##         Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+venv := $(null)
+venv += $(venv-activate-script)#        # virtualenv -p python3
+venv += $(venv-requirements-txt)#       # pip install -r requirements.txt
+
+venv: $(venv)
+
+venv-patched : $(venv-activate-patched)
+
+## -----------------------------------------------------------------------
+## Intent: Activate script path dependency
+## Usage:
+##    o place on the right side of colon as a target dependency
+##    o When the script does not exist install the virtual env and display.
+## -----------------------------------------------------------------------
+$(venv-activate-script):
+
+	$(call banner-enter,(virtualenv -p python))
+
+	virtualenv -p python3 $(venv-name)
+	$(activate) && python -m pip install --upgrade pip
+	$(activate) && pip install --upgrade setuptools
+
+	$(HIDE)$(MAKE) --no-print-directory venv-requirements venv-version
+
+	$(call banner-leave,(virtualenv -t python))
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+##         Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+venv-activate-patched := $(venv-activate-script).patched
+venv-activate-patched : $(venv-activate-patched)
+$(venv-activate-patched) : $(venv-activate-script)
+	$(call banner-enter,Target $@)
+	$(onf-mk-dir)/virtualenv/python_310_migration.sh
+	touch $@
+	$(call banner-leave,Target $@)
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+##         Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+# venv         : $(venv-activate-script)
+
+## -----------------------------------------------------------------------
+## Intent: Revert installation to a clean checkout
+## -----------------------------------------------------------------------
+sterile :: clean
+	$(RM) -r "$(venv-abs-path)"
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+	@printf '  %-33.33s %s\n' 'venv'         \
+	  'Create a python virtual environment'
+	@printf '  %-33.33s %s\n' 'venv-help'    \
+	  'Extended target help'
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+.PHONY: venv-help
+venv-help ::
+	@printf '  %-33.33s %s\n' 'venv-patched' \
+	  'venv patched for v3.10.6+ use'
+
+	@printf '  %-33.33s %s\n' 'venv' \
+	  'Create a python virtual environment'
+	@printf '  %-33.33s %s\n' '  venv-name' \
+	  'virtualenv installation directory name'
+
+# include $(onf-mk-dir)/virtualenv/todo.mk
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/normalizing.py/patch b/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/normalizing.py/patch
new file mode 100644
index 0000000..ae8619a
--- /dev/null
+++ b/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/normalizing.py/patch
@@ -0,0 +1,14 @@
+--- vault/lib/python3.10/site-packages/robot/utils/normalizing.py	2022-11-26 06:59:47.438751606 -0500
++++ .venv/lib/python3.10/site-packages/robot/utils/normalizing.py	2022-11-26 06:57:29.960476182 -0500
+@@ -13,10 +13,7 @@
+ #  See the License for the specific language governing permissions and
+ #  limitations under the License.
+ 
+-try: # python >= 3.10
+-    from collections.abc import MutableMapping
+-except ImportError: # python 2x
+-    from collections import MutableMapping
++from collections import MutableMapping
+ 
+ from .platform import IRONPYTHON, PY_VERSION, PY3
+ from .robottypes import is_dict_like, is_unicode
diff --git a/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/robottypes3.py/patch b/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/robottypes3.py/patch
new file mode 100644
index 0000000..d1aa540
--- /dev/null
+++ b/makefiles/virtualenv/patches/lib/python3.10/site-packages/robot/utils/robottypes3.py/patch
@@ -0,0 +1,16 @@
+--- vault/lib/python3.10/site-packages/robot/utils/robottypes3.py	2022-11-26 07:00:17.126386733 -0500
++++ .venv/lib/python3.10/site-packages/robot/utils/robottypes3.py	2022-11-26 06:57:29.956476232 -0500
+@@ -13,12 +13,7 @@
+ #  See the License for the specific language governing permissions and
+ #  limitations under the License.
+ 
+-try: # python >= 3.10
+-    from collections.abc import Mapping
+-    from collections     import UserString
+-except ImportError: # python 2x
+-    from collections import Mapping, UserString
+-
++from collections import Mapping, UserString
+ from io import IOBase
+ 
+ from .platform import RERAISED_EXCEPTIONS
diff --git a/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinx/util/typing.py/patch b/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinx/util/typing.py/patch
new file mode 100644
index 0000000..da24cd5
--- /dev/null
+++ b/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinx/util/typing.py/patch
@@ -0,0 +1,18 @@
+--- staging/lib/python3.10/site-packages/sphinx/util/typing.py	2023-09-14 16:25:24.179214865 -0400
++++ .venv/lib/python3.10/site-packages/sphinx/util/typing.py	2023-09-14 16:22:16.545588690 -0400
+@@ -34,14 +34,7 @@
+             return ref._eval_type(globalns, localns)
+ 
+ if sys.version_info > (3, 10):
+-
+-    try: # ver >= 3.10.12
+-        from typing import Union as types_Union
+-    except ImportError:
+-        try: # ver >= 3.10.6
+-            from types import Union as types_Union
+-        except ImportError:
+-            types_Union = None
++    from types import Union as types_Union
+ else:
+     types_Union = None
+ 
diff --git a/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinxcontrib/openapi/utils.py/patch b/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinxcontrib/openapi/utils.py/patch
new file mode 100644
index 0000000..3fda183
--- /dev/null
+++ b/makefiles/virtualenv/patches/lib/python3.10/site-packages/sphinxcontrib/openapi/utils.py/patch
@@ -0,0 +1,29 @@
+--- staging/lib/python3.10/site-packages/sphinxcontrib/openapi/utils.py	2022-12-02 18:47:40.050490678 -0500
++++ venv_docs/lib/python3.10/site-packages/sphinxcontrib/openapi/utils.py	2022-12-02 18:45:53.023832002 -0500
+@@ -10,12 +10,7 @@
+ 
+ from __future__ import unicode_literals
+ 
+-try:
+-    import collections.abc
+-    from collections.abc import Mapping
+-except ImportError: # fall through
+-    import collections
+-    from collections import Mapping
++import collections
+ 
+ import jsonschema
+ try:
+@@ -40,10 +35,10 @@
+     resolver = jsonschema.RefResolver(uri, spec)
+ 
+     def _do_resolve(node):
+-        if isinstance(node, Mapping) and '$ref' in node:
++        if isinstance(node, collections.Mapping) and '$ref' in node:
+             with resolver.resolving(node['$ref']) as resolved:
+                 return resolved
+-        elif isinstance(node, Mapping):
++        elif isinstance(node, collections.Mapping):
+             for k, v in node.items():
+                 node[k] = _do_resolve(v)
+         elif isinstance(node, (list, tuple)):
diff --git a/makefiles/virtualenv/python_310_migration.sh b/makefiles/virtualenv/python_310_migration.sh
new file mode 100755
index 0000000..33d330d
--- /dev/null
+++ b/makefiles/virtualenv/python_310_migration.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+# -----------------------------------------------------------------------
+# 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:
+# -----------------------------------------------------------------------
+
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+set -euo pipefail
+
+## -----------------------------------------------------------------------
+## Intent: Display script documentation.
+## -----------------------------------------------------------------------
+function show_help()
+{
+    cat <<EOH
+Usage: $0
+  apply    Patch virtualenv python modules by version (3.10+).
+  backup   Create a tarball for work-in-progress.
+  gather   Display a list of potential source files to patch.
+
+  --venv   Installed venv directory to patch (override default)
+  --help   This message
+
+See Also
+  patches/README.md       Howto create a patch file.
+
+EOH
+    exit 0
+}
+
+##----------------##
+##---]  MAIN  [---##
+##----------------##
+declare dst='.venv'  # "vst_venv"
+declare src="staging"
+declare pat="patches"
+
+## -----------------------
+## Slurp available patches
+## -----------------------
+pushd "$pat" >/dev/null
+readarray -t fyls < <(find . -name 'patch' -print)
+popd         >/dev/null
+
+if [ $# -eq 0 ]; then set -- apply; fi
+
+while [ $# -gt 0 ]; do
+    opt="$1"; shift
+    case "$opt" in
+
+	-*help) show_help ;;
+	-*venv) dst="$1"; shift ;;
+
+	apply)
+	    pushd "$dst" >/dev/null || { echo "pushd $dst failed"; exit 1; }
+	    for fyl in "${fyls[@]}";
+	    do
+		path="${fyl%/*}"
+
+		# Conditional install, jenkins may not support interpreter yet.
+		if [ ! -e "$path" ]; then
+		    echo "[SKIP] $path"
+		    continue
+		fi
+		
+		echo "[APPLY] $path"
+		patch -R -p1 < "../$pat/${path}/patch"
+	    done
+	    popd >/dev/null || { echo "popd $dst failed"; exit 1; }
+	    ;;
+
+	backup)
+	    mkdir ~/backups
+	    pushd "$src" || { echo "pushd $dst failed"; exit 1; }
+	    tar czvf ~/backups/vault."$(date '+%Y%m%d%H%M%S')" "${fyls[@]}"
+	    popd || { echo "popd $dst failed"; exit 1; }
+	    ;;
+
+	gather)
+	    for fyl in "${fyls[@]}";
+	    do
+		patchDir="$pat/$fyl"
+		mkdir -p "$patchDir"
+		diff -Naur "$src/$fyl" "$dst/$fyl" | tee "$pat/$fyl/patch"
+	    done
+	    find "$pat" -print
+	    ;;
+
+	help) show_help ;;
+
+	*)
+	    echo "ERROR: Unknown action [$opt]"
+	    exit 1
+	    ;;
+    esac
+
+    echo
+done
+
+# [EOF]
diff --git a/makefiles/virtualenv/requirements-txt.mk b/makefiles/virtualenv/requirements-txt.mk
new file mode 100644
index 0000000..2d615f6
--- /dev/null
+++ b/makefiles/virtualenv/requirements-txt.mk
@@ -0,0 +1,58 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 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: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+## Intent: pip install with dependencies
+## ----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+venv-requirements := $(venv-abs-path)/makedep/requirements.txt.ts
+
+## -----------------------------------------------------------------------
+## Intent: Define a makefile target able to install venv python modules
+##   when changes are made within the requirements.txt file.
+## -----------------------------------------------------------------------
+## [MAKEFILE TARGETS]
+## venv-requirements
+##   Named target used to abstract underlying dependency filename.
+## $(venv-requirements-txt)
+##   Make macro used to detect changes in requirements.txt file.
+##   Timestamp filename is also the primary target for invoking pip install.
+## -----------------------------------------------------------------------
+.PHONY: venv-requirements
+venv-requirements    : $(venv-requirements)
+$(venv-requirements) : requirements.txt
+
+	$(call banner-enter,venv-requirements)
+	@mkdir -p $(dir $@)
+	$(activate) && python -m pip install -r 'requirements.txt'
+	@touch $@
+
+	$(call banner-leave,venv-requirements)
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+venv-help ::
+	@printf '  %-33.33s %s\n' 'venv-requirements' \
+	  'pip install -r requirements.txt (dependency driven)'
+
+# [EOF]
diff --git a/makefiles/virtualenv/todo.mk b/makefiles/virtualenv/todo.mk
new file mode 100644
index 0000000..9cf6f32
--- /dev/null
+++ b/makefiles/virtualenv/todo.mk
@@ -0,0 +1,40 @@
+# -*- makefile -*-
+## -----------------------------------------------------------------------
+# Copyright 2017-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: 2017-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+## -----------------------------------------------------------------------
+## Intent: Display a list of future enhancements
+## -----------------------------------------------------------------------
+virtualenv-todo ::
+
+	$(call banner-enter,$@)
+
+	@printf '\n[TODO]\n'
+	@printf '  * Refactor include.mk into a simple primary include file for the directory.\n'
+	@printf '  * Extract venv patch logic into a separate makefile.\n'
+	@printf '  * docs.voltha.org: document makefile, targets & behavior.\n'
+	@printf '\n'
+
+	$(call banner-leave,$@)
+
+todo :: virtualenv-todo
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]
diff --git a/makefiles/virtualenv/version.mk b/makefiles/virtualenv/version.mk
new file mode 100644
index 0000000..e2f3af6
--- /dev/null
+++ b/makefiles/virtualenv/version.mk
@@ -0,0 +1,40 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 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: 2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+
+## ----------------------------------------------------------------------
+## Intent: Display installed python interpreter version
+## ----------------------------------------------------------------------
+.PHONY: venv-version
+venv-version :
+	$(activate) && python --version
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+venv-help ::
+	@printf '  %-33.33s %s\n' 'venv-version' \
+	  'Display installed python interpreter version'
+
+# [EOF]
diff --git a/makefiles/virtualenv/virtualenv.mk b/makefiles/virtualenv/virtualenv.mk
new file mode 100644
index 0000000..9e4d457
--- /dev/null
+++ b/makefiles/virtualenv/virtualenv.mk
@@ -0,0 +1,140 @@
+# -*- makefile -*-
+# -----------------------------------------------------------------------
+# Copyright 2017-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: 2017-2024 Open Networking Foundation Contributors
+# SPDX-License-Identifier: Apache-2.0
+# -----------------------------------------------------------------------
+# Intent:
+# -----------------------------------------------------------------------
+
+$(if $(DEBUG),$(warning ENTER))
+
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+.PHONY: venv
+
+##------------------##
+##---]  LOCALS  [---##
+##------------------##
+venv-name             ?= .venv#                            # default install directory
+venv-abs-path         := $(PWD)/$(venv-name)
+venv-activate-bin     := $(venv-name)/bin
+venv-activate-script  := $(venv-activate-bin)/activate#    # dependency
+
+# Intent: activate= is a macro for accessing the virtualenv activation script#
+#  Usage: $(activate) && python
+activate             ?= set +u && source $(venv-activate-script) && set -u
+
+venv-version      : venv-requirements
+venv-requirements : venv-install
+venv-install      : $(venv-activate-script)
+
+## -----------------------------------------------------------------------
+## Intent: Activate script path dependency
+## Usage:
+##    o place on the right side of colon as a target dependency
+##    o When the script does not exist install the virtual env and display.
+## -----------------------------------------------------------------------
+$(venv-activate-script) :
+
+	$(call banner-enter,(virtualenv -p python))
+	virtualenv -p python3 $(venv-name)
+	$(activate) && python -m pip install --upgrade pip
+	$(activate) && pip install --upgrade setuptools
+
+	@$(MAKE) --no-print-directory venv-requirements venv-version
+	$(call banner-leave,(virtualenv -t python))
+
+## ----------------------------------------------------------------------
+## Intent: pip install with dependencies
+## ----------------------------------------------------------------------
+# venv-requirements-txt    := .venv/makedep/requirements.txt.ts
+# venv-requirements        : $(venv-requirements-txt)
+# venv-install             : $(venv-activate-script)
+# venv-requirements        : venv-install
+
+$(venv-requirements-txt) : requirements.txt
+
+	$(activate) && python -m pip install -r requirements.txt
+	@mkdir -p $(dir $@)
+	@touch $@
+
+## ----------------------------------------------------------------------
+## ----------------------------------------------------------------------
+venv-version :
+	$(activate) && python --version
+
+## -----------------------------------------------------------------------
+## Intent: Activate script path dependency
+## Usage:
+##    o place on the right side of colon as a target dependency
+##    o When the script does not exist install the virtual env and display.
+## ----------------------------------------------------------------------
+$(venv-activate-script)-orig :
+	@echo
+	@echo "============================="
+	@echo "Installing python virtual env"
+	@echo "============================="
+	virtualenv -p python3 $(venv-name)
+	$(activate) && python -m pip install --upgrade pip
+	$(activate) && pip install --upgrade setuptools
+	$(activate) && [[ -r requirements.txt ]] \
+	    && { python -m pip install -r requirements.txt; } \
+	    || { /bin/true; }
+
+	$(activate) && python --version
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+##         Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+venv-activate-patched := $(venv-activate-script).patched
+venv-activate-patched : $(venv-activate-patched)
+$(venv-activate-patched) : $(venv-activate-script)
+	$(call banner-enter,Target $@)
+	$(onf-mk-top)/../patches/python_310_migration.sh --venv "$(venv-name)" 'apply'
+	touch $@
+	$(call banner-leave,Target $@)
+
+## -----------------------------------------------------------------------
+## Intent: Explicit named installer target w/o dependencies.
+##         Makefile targets should depend on venv-activate-script.
+## -----------------------------------------------------------------------
+venv += $(venv-activate-script)
+venv += $(venv-requirements-txt)
+venv: $(venv)
+
+## -----------------------------------------------------------------------
+## Intent: Revert installation to a clean checkout
+## -----------------------------------------------------------------------
+sterile :: clean
+	$(RM) -r "$(venv-abs-path)"
+
+## -----------------------------------------------------------------------
+## -----------------------------------------------------------------------
+help ::
+	@echo
+	@echo '[VIRTUAL ENV]'
+	@echo '  venv                Create a python virtual environment'
+	@echo '    venv-name=        Subdir name for virtualenv install'
+	@echo '  venv-activate-script         make macro name'
+	@echo '      $$(target) dependency    install python virtualenv'
+	@echo '      source $$(macro) && cmd  configure env and run cmd'
+
+$(if $(DEBUG),$(warning LEAVE))
+
+# [EOF]