|
| 1 | +# This file is part of cwlprov-py, |
| 2 | +# https://github.com/common-workflow-language/cwlprov-py/, 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 | +# Contact: common-workflow-language@googlegroups.com |
| 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 | +MODULE=cwlprov |
| 24 | +PACKAGE=cwlprov |
| 25 | + |
| 26 | +# `SHELL=bash` doesn't work for some, so don't use BASH-isms like |
| 27 | +# `[[` conditional expressions. |
| 28 | +PYSOURCES=$(wildcard ${MODULE}/**.py) setup.py |
| 29 | +DEVPKGS=diff_cover black pylint pep257 pydocstyle flake8 tox tox-pyenv \ |
| 30 | + isort wheel autoflake flake8-bugbear pyupgrade bandit \ |
| 31 | + -rtest-requirements.txt -rmypy-requirements.txt |
| 32 | +COVBASE=coverage run --append |
| 33 | + |
| 34 | +# Updating the Major & Minor version below? |
| 35 | +# Don't forget to update setup.py as well |
| 36 | +#VERSION=8.2.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \ |
| 37 | +# --max-count=1 --format=format:%cI`) |
| 38 | + |
| 39 | +## all : default task |
| 40 | +all: dev |
| 41 | + |
| 42 | +## help : print this help message and exit |
| 43 | +help: Makefile |
| 44 | + @sed -n 's/^##//p' $< |
| 45 | + |
| 46 | +## install-dep : install most of the development dependencies via pip |
| 47 | +install-dep: install-dependencies |
| 48 | + |
| 49 | +install-dependencies: FORCE |
| 50 | + pip install --upgrade $(DEVPKGS) |
| 51 | + pip install -r requirements.txt |
| 52 | + |
| 53 | +## install : install the ${MODULE} module and cwlprov |
| 54 | +install: FORCE |
| 55 | + pip install . |
| 56 | + |
| 57 | +## dev : install the ${MODULE} module in dev mode |
| 58 | +dev: install-dep |
| 59 | + pip install -e . |
| 60 | + |
| 61 | +## dist : create a module package for distribution |
| 62 | +dist: dist/${MODULE}-$(VERSION).tar.gz |
| 63 | + |
| 64 | +dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES) |
| 65 | + python setup.py sdist bdist_wheel |
| 66 | + |
| 67 | +## docs : make the docs |
| 68 | +docs: FORCE |
| 69 | + cd docs && $(MAKE) html |
| 70 | + |
| 71 | +## clean : clean up all temporary / machine-generated files |
| 72 | +clean: FORCE |
| 73 | + rm -rf ${MODULE}/__pycache__ |
| 74 | + python setup.py clean --all || true |
| 75 | + rm -Rf .coverage |
| 76 | + rm -f diff-cover.html |
| 77 | + |
| 78 | +# Linting and code style related targets |
| 79 | +## sorting imports using isort: https://github.com/timothycrosley/isort |
| 80 | +sort_imports: $(PYSOURCES) |
| 81 | + isort $^ |
| 82 | + |
| 83 | +remove_unused_imports: $(PYSOURCES) |
| 84 | + autoflake --in-place --remove-all-unused-imports $^ |
| 85 | + |
| 86 | +pep257: pydocstyle |
| 87 | +## pydocstyle : check Python code style |
| 88 | +pydocstyle: $(PYSOURCES) |
| 89 | + pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true |
| 90 | + |
| 91 | +pydocstyle_report.txt: $(PYSOURCES) |
| 92 | + pydocstyle setup.py $^ > $@ 2>&1 || true |
| 93 | + |
| 94 | +diff_pydocstyle_report: pydocstyle_report.txt |
| 95 | + diff-quality --compare-branch=main --violations=pydocstyle --fail-under=100 $^ |
| 96 | + |
| 97 | +## format : check/fix all code indentation and formatting (runs black) |
| 98 | +format: $(PYSOURCES) |
| 99 | + black $^ |
| 100 | + |
| 101 | +format-check: $(PYSOURCES) |
| 102 | + black --diff --check $^ |
| 103 | + |
| 104 | +## pylint : run static code analysis on Python code |
| 105 | +pylint: $(PYSOURCES) |
| 106 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 107 | + $^ -j0|| true |
| 108 | + |
| 109 | +pylint_report.txt: $(PYSOURCES) |
| 110 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 111 | + $^ -j0> $@ || true |
| 112 | + |
| 113 | +diff_pylint_report: pylint_report.txt |
| 114 | + diff-quality --violations=pylint pylint_report.txt |
| 115 | + |
| 116 | +.coverage: FORCE |
| 117 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) validate && ) true |
| 118 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) info && ) true |
| 119 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) who && ) true |
| 120 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) prov && ) true |
| 121 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) inputs && ) true |
| 122 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) outputs && ) true |
| 123 | + $(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) runs && ) true |
| 124 | + #$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) derived && ) true |
| 125 | + #$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) runtimes && ) true |
| 126 | + |
| 127 | +coverage.xml: .coverage |
| 128 | + coverage xml |
| 129 | + |
| 130 | +coverage.html: htmlcov/index.html |
| 131 | + |
| 132 | +htmlcov/index.html: .coverage |
| 133 | + coverage html |
| 134 | + @echo Test coverage of the Python code is now in htmlcov/index.html |
| 135 | + |
| 136 | +coverage-report: .coverage |
| 137 | + coverage report |
| 138 | + |
| 139 | +diff-cover: coverage.xml |
| 140 | + diff-cover $^ |
| 141 | + |
| 142 | +diff-cover.html: coverage.xml |
| 143 | + diff-cover $^ --html-report $@ |
| 144 | + |
| 145 | +## test : run the ${MODULE} test suite |
| 146 | +test: $(PYSOURCES) FORCE |
| 147 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) validate && ) true |
| 148 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) info && ) true |
| 149 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) who && ) true |
| 150 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) prov && ) true |
| 151 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) inputs && ) true |
| 152 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) outputs && ) true |
| 153 | + $(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) runs && ) true |
| 154 | + #$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) derived && ) true |
| 155 | + #$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) runtimes && ) true |
| 156 | + |
| 157 | + |
| 158 | +## testcov : run the ${MODULE} test suite and collect coverage |
| 159 | +testcov: $(PYSOURCES) |
| 160 | + python setup.py test --addopts "--cov" ${PYTEST_EXTRA} |
| 161 | + |
| 162 | +sloccount.sc: $(PYSOURCES) Makefile |
| 163 | + sloccount --duplicates --wide --details $^ > $@ |
| 164 | + |
| 165 | +## sloccount : count lines of code |
| 166 | +sloccount: $(PYSOURCES) Makefile |
| 167 | + sloccount $^ |
| 168 | + |
| 169 | +list-author-emails: |
| 170 | + @echo 'name, E-Mail Address' |
| 171 | + @git log --format='%aN,%aE' | sort -u | grep -v 'root' |
| 172 | + |
| 173 | +mypy3: mypy |
| 174 | +mypy: $(filter-out setup.py,$(PYSOURCES)) |
| 175 | + mypy $^ |
| 176 | + |
| 177 | +pyupgrade: $(PYSOURCES) |
| 178 | + pyupgrade --exit-zero-even-if-changed --py36-plus $^ |
| 179 | + |
| 180 | +release-test: FORCE |
| 181 | + git diff-index --quiet HEAD -- || ( echo You have uncommited changes, please commit them and try again; false ) |
| 182 | + ./release-test.sh |
| 183 | + |
| 184 | +release: release-test |
| 185 | + . testenv2/bin/activate && \ |
| 186 | + python testenv2/src/${PACKAGE}/setup.py sdist bdist_wheel |
| 187 | + . testenv2/bin/activate && \ |
| 188 | + pip install twine && \ |
| 189 | + twine upload testenv2/src/${PACKAGE}/dist/* && \ |
| 190 | + git tag ${VERSION} && git push --tags |
| 191 | + |
| 192 | +flake8: $(PYSOURCES) |
| 193 | + flake8 $^ |
| 194 | + |
| 195 | +FORCE: |
| 196 | + |
| 197 | +# Use this to print the value of a Makefile variable |
| 198 | +# Example `make print-VERSION` |
| 199 | +# From https://www.cmcrossroads.com/article/printing-value-makefile-variable |
| 200 | +print-% : ; @echo $* = $($*) |
0 commit comments