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