|
| 1 | +# This file is part of workflow-service |
| 2 | +# https://github.com/common-workflow-language/workflow-service/, and is |
| 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 | + |
| 18 | +# make format to fix most python formatting errors |
| 19 | +# make pylint to check Python code for enhanced compliance including naming |
| 20 | +# and documentation |
| 21 | +# make coverage-report to check coverage of the python scripts by the tests |
| 22 | + |
| 23 | +MODULE1=wes_client |
| 24 | +MODULE2=wes_service |
| 25 | +PACKAGE=wes-service |
| 26 | +EXTRAS= |
| 27 | + |
| 28 | +# `SHELL=bash` doesn't work for some, so don't use BASH-isms like |
| 29 | +# `[[` conditional expressions. |
| 30 | +PYSOURCES=$(shell find $(MODULE1) -name "*.py") $(shell find $(MODULE2) -name "*.py")\ |
| 31 | + $(wildcard test/*.py) $(wildcard *.py) |
| 32 | +DEVPKGS=build diff_cover pylint pep257 pydocstyle 'tox<4' tox-pyenv \ |
| 33 | + wheel autoflake pyupgrade bandit auto-walrus \ |
| 34 | + -rlint-requirements.txt -rtest-requirements.txt -rmypy-requirements.txt |
| 35 | +DEBDEVPKGS=pep8 python-autopep8 pylint python-coverage pydocstyle sloccount \ |
| 36 | + python-flake8 python-mock shellcheck |
| 37 | +VERSION=v$(shell grep version pyproject.toml | awk -F\" '{print $2}') |
| 38 | +mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 39 | +UNAME_S=$(shell uname -s) |
| 40 | + |
| 41 | +## all : default task (install wes-service in dev mode) |
| 42 | +all: dev |
| 43 | + |
| 44 | +## help : print this help message and exit |
| 45 | +help: Makefile |
| 46 | + @sed -n 's/^##//p' $< |
| 47 | + |
| 48 | +## cleanup : shortcut for "make sort_imports format flake8 diff_pydocstyle_report" |
| 49 | +cleanup: sort_imports format flake8 diff_pydocstyle_report |
| 50 | + |
| 51 | +## install-dep : install most of the development dependencies via pip |
| 52 | +install-dep: install-dependencies |
| 53 | + |
| 54 | +install-dependencies: |
| 55 | + pip install -U pip setuptools wheel |
| 56 | + pip install --upgrade $(DEVPKGS) |
| 57 | + |
| 58 | +## install-deb-dep : install many of the dev dependencies via apt-get |
| 59 | +install-deb-dep: |
| 60 | + sudo apt-get install $(DEBDEVPKGS) |
| 61 | + |
| 62 | +## install : install the wes-service package and the scripts |
| 63 | +install: FORCE |
| 64 | + pip install .$(EXTRAS) |
| 65 | + |
| 66 | +## dev : install the wes-service package in dev mode |
| 67 | +dev: install-dep |
| 68 | + pip install -U pip setuptools wheel |
| 69 | + pip install -e .$(EXTRAS) |
| 70 | + |
| 71 | +## dist : create a module package for distribution |
| 72 | +dist: dist/${MODULE}-$(VERSION).tar.gz |
| 73 | + |
| 74 | +dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES) |
| 75 | + python -m build |
| 76 | + |
| 77 | +## clean : clean up all temporary / machine-generated files |
| 78 | +clean: FORCE |
| 79 | + rm -f ${MODULE}/*.pyc tests/*.pyc |
| 80 | + rm -Rf .coverage |
| 81 | + rm -f diff-cover.html |
| 82 | + |
| 83 | +# Linting and code style related targets |
| 84 | +## sort_import : sorting imports using isort: https://github.com/timothycrosley/isort |
| 85 | +sort_imports: $(PYSOURCES) |
| 86 | + isort $^ |
| 87 | + |
| 88 | +remove_unused_imports: $(PYSOURCES) |
| 89 | + autoflake --in-place --remove-all-unused-imports $^ |
| 90 | + |
| 91 | +pep257: pydocstyle |
| 92 | +## pydocstyle : check Python docstring style |
| 93 | +pydocstyle: $(PYSOURCES) |
| 94 | + pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true |
| 95 | + |
| 96 | +pydocstyle_report.txt: $(PYSOURCES) |
| 97 | + pydocstyle $^ > $@ 2>&1 || true |
| 98 | + |
| 99 | +## diff_pydocstyle_report : check Python docstring style for changed files only |
| 100 | +diff_pydocstyle_report: pydocstyle_report.txt |
| 101 | + diff-quality --compare-branch=main --violations=pydocstyle --fail-under=100 $^ |
| 102 | + |
| 103 | +## codespell : check for common misspellings |
| 104 | +codespell: |
| 105 | + codespell -w $(shell git ls-files | grep -v mypy-stubs) |
| 106 | + |
| 107 | +## format : check/fix all code indentation and formatting (runs black) |
| 108 | +format: $(PYSOURCES) FORCE |
| 109 | + black $(PYSOURCES) |
| 110 | + |
| 111 | +format-check: $(PYSOURCES) |
| 112 | + black --diff --check $^ |
| 113 | + |
| 114 | +## pylint : run static code analysis on Python code |
| 115 | +pylint: $(PYSOURCES) |
| 116 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 117 | + $^ -j0|| true |
| 118 | + |
| 119 | +pylint_report.txt: $(PYSOURCES) |
| 120 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 121 | + $^ -j0> $@ || true |
| 122 | + |
| 123 | +diff_pylint_report: pylint_report.txt |
| 124 | + diff-quality --compare-branch=main --violations=pylint pylint_report.txt |
| 125 | + |
| 126 | +.coverage: testcov |
| 127 | + |
| 128 | +coverage: .coverage |
| 129 | + coverage report |
| 130 | + |
| 131 | +coverage.xml: .coverage |
| 132 | + coverage xml |
| 133 | + |
| 134 | +coverage.html: htmlcov/index.html |
| 135 | + |
| 136 | +htmlcov/index.html: .coverage |
| 137 | + coverage html |
| 138 | + @echo Test coverage of the Python code is now in htmlcov/index.html |
| 139 | + |
| 140 | +coverage-report: .coverage |
| 141 | + coverage report |
| 142 | + |
| 143 | +diff-cover: coverage.xml |
| 144 | + diff-cover --compare-branch=main $^ |
| 145 | + |
| 146 | +diff-cover.html: coverage.xml |
| 147 | + diff-cover --compare-branch=main $^ --html-report $@ |
| 148 | + |
| 149 | +## test : run the wes-service test suite |
| 150 | +test: $(PYSOURCES) |
| 151 | + python -m pytest -rsx ${PYTEST_EXTRA} |
| 152 | + |
| 153 | +## testcov : run the wes-service test suite and collect coverage |
| 154 | +testcov: $(PYSOURCES) |
| 155 | + pytest --cov ${PYTEST_EXTRA} |
| 156 | + |
| 157 | +sloccount.sc: $(PYSOURCES) Makefile |
| 158 | + sloccount --duplicates --wide --details $^ > $@ |
| 159 | + |
| 160 | +## sloccount : count lines of code |
| 161 | +sloccount: $(PYSOURCES) Makefile |
| 162 | + sloccount $^ |
| 163 | + |
| 164 | +list-author-emails: |
| 165 | + @echo 'name, E-Mail Address' |
| 166 | + @git log --format='%aN,%aE' | sort -u | grep -v 'root' |
| 167 | + |
| 168 | +mypy3: mypy |
| 169 | +mypy: ${PYSOURCES} |
| 170 | + MYPYPATH=$$MYPYPATH:mypy-stubs mypy $^ |
| 171 | + |
| 172 | +shellcheck: FORCE |
| 173 | + shellcheck release-test.sh |
| 174 | + |
| 175 | +pyupgrade: $(PYSOURCES) |
| 176 | + pyupgrade --exit-zero-even-if-changed --py38-plus $^ |
| 177 | + auto-walrus $^ |
| 178 | + |
| 179 | +release-test: FORCE |
| 180 | + git diff-index --quiet HEAD -- || ( echo You have uncommitted changes, please commit them and try again; false ) |
| 181 | + ./release-test.sh |
| 182 | + |
| 183 | +release: release-test |
| 184 | + . testenv2/bin/activate && \ |
| 185 | + pip install build && \ |
| 186 | + python -m build testenv2/src/${PACKAGE} && \ |
| 187 | + pip install twine && \ |
| 188 | + twine upload testenv2/src/${PACKAGE}/dist/* && \ |
| 189 | + git tag ${VERSION} && git push --tags |
| 190 | + |
| 191 | +flake8: $(PYSOURCES) |
| 192 | + flake8 $^ |
| 193 | + |
| 194 | +FORCE: |
| 195 | + |
| 196 | +# Use this to print the value of a Makefile variable |
| 197 | +# Example `make print-VERSION` |
| 198 | +# From https://www.cmcrossroads.com/article/printing-value-makefile-variable |
| 199 | +print-% : ; @echo $* = $($*) |
0 commit comments