|
| 1 | +# ------------------------------------------------------------------------- |
| 2 | +# Copyright 2023-2023, Boling Consulting Solutions, bcsw.net |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License |
| 15 | +# ------------------------------------------------------------------------- |
| 16 | +# |
| 17 | +# Makefile method of doing things should you prefer |
| 18 | +# |
| 19 | +# Configure shell |
| 20 | +SHELL = bash -eu -o pipefail |
| 21 | + |
| 22 | +# Variables |
| 23 | +THIS_MAKEFILE := $(abspath $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) |
| 24 | +WORKING_DIR := $(dir $(THIS_MAKEFILE) ) |
| 25 | +PACKAGE_DIR := $(WORKING_DIR)/tls_packet |
| 26 | +TEST_DIR := $(WORKING_DIR)/test |
| 27 | + |
| 28 | +include setup.mk |
| 29 | + |
| 30 | +# Variables |
| 31 | +VENVDIR := venv |
| 32 | +TESTVENVDIR := $(VENVDIR)-test |
| 33 | +PYVERSION ?= ${PYVERSION:-"3.11"} |
| 34 | +PYTHON := python${PYVERSION} |
| 35 | + |
| 36 | +COVERAGE_OPTS = --with-xcoverage --with-xunit \ |
| 37 | + --cover-html --cover-html-dir=tmp/cover |
| 38 | + |
| 39 | +PYLINT_DISABLES = -d similarities -d broad-except -d missing-class-docstring |
| 40 | +PYLINT_OPTS = -j 4 --exit-zero --rcfile=${WORKING_DIR}.pylintrc $(PYLINT_DISABLES) |
| 41 | +PYLINT_OUT = $(WORKING_DIR)pylint.out |
| 42 | + |
| 43 | +PYLAMA_DISABLES = |
| 44 | +PYLAMA_OPTS = --async $(PYLAMA_DISABLES) |
| 45 | +PYLAMA_OUT = $(WORKING_DIR)pylama.out |
| 46 | + |
| 47 | +LICENSE_OUT = $(WORKING_DIR)license-check.out |
| 48 | + |
| 49 | +.PHONY: venv test dist clean distclean upload |
| 50 | + |
| 51 | +## Defaults |
| 52 | +default: help ## Default operation is to print this help text |
| 53 | + |
| 54 | +## Virtual Environment |
| 55 | +venv: $(PACKAGE_DIR)/requirements.txt $(VENVDIR)/.built ## Application virtual environment |
| 56 | + |
| 57 | +venv-test: $(TEST_DIR)/requirements.txt $(TESTVENVDIR)/.built ## Unit-test/lint/... virtual environment |
| 58 | + |
| 59 | +$(VENVDIR)/.built: |
| 60 | + @ ${PYTHON} -m venv ${VENVDIR} |
| 61 | + @ (source ${VENVDIR}/bin/activate && \ |
| 62 | + if python -m pip install --disable-pip-version-check -r $(PACKAGE_DIR)/requirements.txt; \ |
| 63 | + then \ |
| 64 | + uname -s > ${VENVDIR}/.built; \ |
| 65 | + fi) |
| 66 | + |
| 67 | +$(TESTVENVDIR)/.built: |
| 68 | + @ ${PYTHON} -m venv ${TESTVENVDIR} |
| 69 | + @ (source ${TESTVENVDIR}/bin/activate && \ |
| 70 | + if python -m pip install --disable-pip-version-check -r test/requirements.txt; \ |
| 71 | + then \ |
| 72 | + python -m pip install --disable-pip-version-check pylint; \ |
| 73 | + uname -s > ${TESTVENVDIR}/.built; \ |
| 74 | + fi) |
| 75 | + |
| 76 | +###################################################################### |
| 77 | +## License and security |
| 78 | + |
| 79 | +show-licenses: venv ## Show licenses of imported modules |
| 80 | + @ (source ${VENVDIR}/bin/activate && \ |
| 81 | + python -m pip install --upgrade --disable-pip-version-check pip-licenses && \ |
| 82 | + pip-licenses 2>&1 | tee ${LICENSE_OUT}) |
| 83 | + |
| 84 | +bandit-test: venv-test ## Run security test on python source |
| 85 | + $(Q) echo "Running python security check with bandit on module code" |
| 86 | + @ (source ${TESTVENVDIR}/bin/activate && \ |
| 87 | + python -m pip install --upgrade --disable-pip-version-check bandit && \ |
| 88 | + bandit -n 3 -r $(PACKAGE_DIR)) |
| 89 | + |
| 90 | +bandit-test-all: venv bandit-test ## Run security test on python source and imported modules |
| 91 | + $(Q) echo "Running python security check with bandit on imports" |
| 92 | + @ (source ${TESTVENVDIR}/bin/activate && \ |
| 93 | + python -m pip install --upgrade --disable-pip-version-check bandit && \ |
| 94 | + bandit -n 3 -r $(WORKING_DIR)/${VENVDIR}) |
| 95 | + |
| 96 | +###################################################################### |
| 97 | +## Testing |
| 98 | + |
| 99 | +test: venv-test ## Run tox-based unit tests |
| 100 | + $(Q) echo "Executing unit tests w/tox" |
| 101 | + @ python -m pip install --upgrade --disable-pip-version-check tox && \ |
| 102 | + . ${TESTVENVDIR}/bin/activate && tox |
| 103 | + |
| 104 | +###################################################################### |
| 105 | +## Linting |
| 106 | + |
| 107 | +lint: venv-test pylint-lint pylama-lint ## Run lint on all sources and dockerfiles |
| 108 | + $(Q) echo "Installing pylint" |
| 109 | + $(Q) (source ${TESTVENVDIR}/bin/activate && \ |
| 110 | + python -m pip install --upgrade --disable-pip-version-check pylint) |
| 111 | + |
| 112 | +pylint-lint: venv-test ## Run lint on PON Automation using pylint |
| 113 | + @ (source ${TESTVENVDIR}/bin/activate && \ |
| 114 | + pylint ${PYLINT_OPTS} ${PACKAGE_DIR} 2>&1 | tee ${PYLINT_OUT} && \ |
| 115 | + echo; echo "See \"file://${PYLINT_OUT}\" for lint report") |
| 116 | + |
| 117 | +# Pylama is a document and code linter collection of other tools |
| 118 | +pylama-lint: venv-test ## Run lint on PON Automation using pylama |
| 119 | + $(Q) echo "Executing pylama" |
| 120 | + $(Q) (source ${TESTVENVDIR}/bin/activate && \ |
| 121 | + python -m pip install --upgrade --disable-pip-version-check pylama[all] && \ |
| 122 | + $(MAKE) app-pylama) |
| 123 | + |
| 124 | +app-pylama: venv-test |
| 125 | + pylama ${PYLAMA_OPTS} ${PACKAGE_DIR} 2>&1 | tee ${PYLAMA_OUT} |
| 126 | + $(Q) echo |
| 127 | + $(Q) echo "See \"file://${PYLAMA_OUT}\" for pylama report" |
| 128 | + |
| 129 | +###################################################################### |
| 130 | +# Release related (Lint ran last since it probably will have errors until |
| 131 | +# the code is refactored (which is not planned at this time) |
| 132 | +## Release and Publishing Procedures |
| 133 | +release-check: distclean venv venv-test test bandit-test lint ## Clean distribution and run unit-test, security, and lint |
| 134 | + |
| 135 | +dist: ## Create source distribution of the python package |
| 136 | + $(Q) echo "Creating python source distribution" |
| 137 | + rm -rf dist/ |
| 138 | + python setup.py sdist |
| 139 | + |
| 140 | +upload: clean lint test dist ## Upload test version of python package to test.pypi.org |
| 141 | + $(Q) echo "Uploading sdist to test.pypi.org" |
| 142 | + twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 143 | + |
| 144 | +###################################################################### |
| 145 | +## Utility |
| 146 | +clean: ## Cleanup directory of build and test artifacts |
| 147 | + @ -rm -rf .tox *.coverage *.egg-info ${DOCKER_TARBALLNAME}.gz build/*.deb test/.pytest_cache ${PYLAMA_OUT} ${PYLINT_OUT} ${LICENSE_OUT} |
| 148 | + @ -find . -name '*.pyc' | xargs rm -f |
| 149 | + @ -find . -name '__pycache__' | xargs rm -rf |
| 150 | + @ -find . -name '__pycache__' | xargs rm -rf |
| 151 | + @ -find . -name 'htmlcov' | xargs rm -rf |
| 152 | + @ -find . -name 'junit-report.xml' | xargs rm -rf |
| 153 | + @ -find . -name 'coverage.xml' | xargs rm -rf |
| 154 | + @ -find . -name '.coverage' | xargs rm -rf |
| 155 | + |
| 156 | +distclean: clean ## Cleanup all build, test, and virtual environment artifacts |
| 157 | + @ -rm -rf ${VENVDIR} ${TESTVENVDIR} ${BUILD_DIR} |
| 158 | + |
| 159 | +help: ## Print help for each Makefile target |
| 160 | + @echo '' |
| 161 | + @echo 'Usage:' |
| 162 | + @echo ' ${YELLOW}make${RESET} ${GREEN}<target> [<target> ...]${RESET}' |
| 163 | + @echo '' |
| 164 | + @echo 'Targets:' |
| 165 | + @awk 'BEGIN {FS = ":.*?## "} { \ |
| 166 | + if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-23s${GREEN}%s${RESET}\n", $$1, $$2} \ |
| 167 | + else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ |
| 168 | + }' $(MAKEFILE_LIST) |
| 169 | + |
| 170 | +# end file |
0 commit comments