Zack Williams | 7af92fe | 2021-08-15 15:37:50 -0700 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: © 2021 Open Networking Foundation <support@opennetworking.org> |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | # Use bash for pushd/popd, and to fail quickly. |
| 5 | # No -u as virtualenv activate script has undefined vars |
| 6 | SHELL = bash -e -o pipefail |
| 7 | |
| 8 | .DEFAULT_GOAL := help |
| 9 | .PHONY: test lint pylint black blacken license help |
| 10 | |
| 11 | PYTHON_FILES ?= $(wildcard *.py) |
Zack Williams | 84cb77a | 2022-01-14 14:46:39 -0800 | [diff] [blame] | 12 | SHELL_FILES ?= $(wildcard *.sh) |
| 13 | CPI_KEY ?= $(wildcard *.p12) |
| 14 | |
Zack Williams | 7af92fe | 2021-08-15 15:37:50 -0700 | [diff] [blame] | 15 | |
| 16 | # tooling |
| 17 | VIRTUALENV ?= python3 -m venv |
| 18 | |
| 19 | # Create the virtualenv with all the tools installed |
| 20 | VENV_NAME = venv_cbrs |
| 21 | |
| 22 | $(VENV_NAME): requirements.txt |
| 23 | $(VIRTUALENV) $@ ;\ |
| 24 | source ./$@/bin/activate ; set -u ;\ |
| 25 | python -m pip install --upgrade pip;\ |
| 26 | python -m pip install -r requirements.txt |
| 27 | echo "To enter virtualenv, run 'source $@/bin/activate'" |
| 28 | |
Zack Williams | 84cb77a | 2022-01-14 14:46:39 -0800 | [diff] [blame] | 29 | test: shellcheck black pylint license ## run tests |
Zack Williams | 7af92fe | 2021-08-15 15:37:50 -0700 | [diff] [blame] | 30 | |
| 31 | pylint: $(VENV_NAME) ## pylint check for best practices |
| 32 | source ./$</bin/activate ; set -u ;\ |
| 33 | pylint --version ;\ |
| 34 | pylint $(PYTHON_FILES) |
| 35 | |
Zack Williams | 84cb77a | 2022-01-14 14:46:39 -0800 | [diff] [blame] | 36 | shellcheck: ## shellcheck shell scripts |
| 37 | # SC1091 is excluded which is soucing the venv |
| 38 | shellcheck -V |
| 39 | shellcheck -e SC1091 $(SHELL_FILES) |
| 40 | |
Zack Williams | 7af92fe | 2021-08-15 15:37:50 -0700 | [diff] [blame] | 41 | black: $(VENV_NAME) ## run black on python files in check mode |
| 42 | source ./$</bin/activate ; set -u ;\ |
| 43 | black --version ;\ |
| 44 | black --check $(PYTHON_FILES) |
| 45 | |
| 46 | blacken: $(VENV_NAME) ## run black on python files to reformat |
| 47 | source ./$</bin/activate ; set -u ;\ |
| 48 | black --version ;\ |
| 49 | black $(PYTHON_FILES) |
| 50 | |
| 51 | license: $(VENV_NAME) ## Check license with the reuse tool |
| 52 | source ./$</bin/activate ; set -u ;\ |
| 53 | reuse --version ;\ |
| 54 | reuse --root . lint |
| 55 | |
| 56 | clean: |
| 57 | rm -rf $(VENV_NAME) |
| 58 | |
| 59 | help: ## Print help for each target |
| 60 | @echo cbrstools make targets |
| 61 | @echo |
| 62 | @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \ |
| 63 | | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};' |