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