|
| 1 | +# This file is part of cwl-utils, |
| 2 | +# https://github.com/common-workflow-language/cwl-utils/, 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 | +MODULE=cwl_utils |
| 24 | + |
| 25 | +# `SHELL=bash` doesn't work for some, so don't use BASH-isms like |
| 26 | +# `[[` conditional expressions. |
| 27 | +PYSOURCES=$(filter-out cwl_utils/parser_v%,$(wildcard ${MODULE}/**.py tests/*.py)) setup.py |
| 28 | +DEVPKGS=diff_cover black pylint coverage pep257 pydocstyle flake8 mypy\ |
| 29 | + isort wheel |
| 30 | +DEBDEVPKGS=pep8 python-autopep8 pylint python-coverage pydocstyle sloccount \ |
| 31 | + python-flake8 python-mock shellcheck |
| 32 | +VERSION=$(shell awk '{print $3}' < cwl_utils/__meta__.py ) |
| 33 | +# VERSION=3.0.$(shell TZ=UTC git log --first-parent --max-count=1 \ |
| 34 | +# --format=format:%cd --date=format-local:%Y%m%d%H%M%S) |
| 35 | +mkfile_dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 36 | +UNAME_S=$(shell uname -s) |
| 37 | + |
| 38 | +## all : default task |
| 39 | +all: |
| 40 | + pip install -e . |
| 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: |
| 50 | + pip install --upgrade $(DEVPKGS) |
| 51 | + pip install -r requirements.txt |
| 52 | + |
| 53 | +## install-deb-dep: install most of the dev dependencies via apt-get |
| 54 | +install-deb-dep: |
| 55 | + sudo apt-get install $(DEBDEVPKGS) |
| 56 | + |
| 57 | +## install : install the ${MODULE} module and schema-salad-tool |
| 58 | +install: FORCE |
| 59 | + pip install .[deps] |
| 60 | + |
| 61 | +## dev : install the ${MODULE} module in dev mode |
| 62 | +dev: install-dep |
| 63 | + pip install -e .[deps] |
| 64 | + |
| 65 | + |
| 66 | +## dist : create a module package for distribution |
| 67 | +dist: dist/${MODULE}-$(VERSION).tar.gz |
| 68 | + |
| 69 | +dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES) |
| 70 | + ./setup.py sdist bdist_wheel |
| 71 | + |
| 72 | +## clean : clean up all temporary / machine-generated files |
| 73 | +clean: FORCE |
| 74 | + rm -f ${MODILE}/*.pyc tests/*.pyc |
| 75 | + ./setup.py clean --all || true |
| 76 | + rm -Rf .coverage |
| 77 | + rm -f diff-cover.html |
| 78 | + |
| 79 | +# Linting and code style related targets |
| 80 | +## sorting imports using isort: https://github.com/timothycrosley/isort |
| 81 | +sort_imports: $(PYSOURCES) |
| 82 | + isort $^ |
| 83 | + |
| 84 | +pep257: pydocstyle |
| 85 | +## pydocstyle : check Python code style |
| 86 | +pydocstyle: $(PYSOURCES) |
| 87 | + pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true |
| 88 | + |
| 89 | +pydocstyle_report.txt: $(PYSOURCES) |
| 90 | + pydocstyle setup.py $^ > $@ 2>&1 || true |
| 91 | + |
| 92 | +diff_pydocstyle_report: pydocstyle_report.txt |
| 93 | + diff-quality --compare-branch=main --violations=pydocstyle --fail-under=100 $^ |
| 94 | + |
| 95 | +## format : check/fix all code indentation and formatting (runs black) |
| 96 | +format: $(PYSOURCES) |
| 97 | + black $^ |
| 98 | + |
| 99 | +## pylint : run static code analysis on Python code |
| 100 | +pylint: $(PYSOURCES) |
| 101 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 102 | + $^ -j0|| true |
| 103 | + |
| 104 | +pylint_report.txt: ${PYSOURCES} |
| 105 | + pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \ |
| 106 | + $^ -j0> $@ || true |
| 107 | + |
| 108 | +diff_pylint_report: pylint_report.txt |
| 109 | + diff-quality --violations=pylint pylint_report.txt |
| 110 | + |
| 111 | +.coverage: testcov |
| 112 | + |
| 113 | +coverage: .coverage |
| 114 | + coverage report |
| 115 | + |
| 116 | +coverage.xml: .coverage |
| 117 | + coverage xml |
| 118 | + |
| 119 | +coverage.html: htmlcov/index.html |
| 120 | + |
| 121 | +htmlcov/index.html: .coverage |
| 122 | + coverage html |
| 123 | + @echo Test coverage of the Python code is now in htmlcov/index.html |
| 124 | + |
| 125 | +coverage-report: .coverage |
| 126 | + coverage report |
| 127 | + |
| 128 | +diff-cover: coverage.xml |
| 129 | + diff-cover $^ |
| 130 | + |
| 131 | +diff-cover.html: coverage.xml |
| 132 | + diff-cover $^ --html-report $@ |
| 133 | + |
| 134 | +## test : run the ${MODULE} test suite |
| 135 | +test: FORCE |
| 136 | + python setup.py test # --addopts "-n auto --dist=loadfile" |
| 137 | + |
| 138 | +## testcov : run the ${MODULE} test suite and collect coverage |
| 139 | +testcov: $(pysources) |
| 140 | + python setup.py test --addopts "--cov ${MODULE}" # -n auto --dist=loadfile" |
| 141 | + |
| 142 | +sloccount.sc: ${PYSOURCES} Makefile |
| 143 | + sloccount --duplicates --wide --details $^ > $@ |
| 144 | + |
| 145 | +## sloccount : count lines of code |
| 146 | +sloccount: ${PYSOURCES} Makefile |
| 147 | + sloccount $^ |
| 148 | + |
| 149 | +list-author-emails: |
| 150 | + @echo 'name, E-Mail Address' |
| 151 | + @git log --format='%aN,%aE' | sort -u | grep -v 'root' |
| 152 | + |
| 153 | +mypy3: mypy |
| 154 | +mypy: ${PYSOURCES} |
| 155 | + if ! test -f $(shell python3 -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))')/py.typed ; \ |
| 156 | + then \ |
| 157 | + rm -Rf typeshed/ruamel/yaml ; \ |
| 158 | + ln -s $(shell python3 -c 'import ruamel.yaml; import os.path; print(os.path.dirname(ruamel.yaml.__file__))') \ |
| 159 | + typeshed/ruamel/ ; \ |
| 160 | + fi # if minimally required ruamel.yaml version is 0.15.99 or greater, than the above can be removed |
| 161 | + MYPYPATH=$$MYPYPATH:typeshed/ mypy --disallow-untyped-calls \ |
| 162 | + --warn-redundant-casts \ |
| 163 | + ${MODULE} |
| 164 | + |
| 165 | +mypyc: ${PYSOURCES} |
| 166 | + MYPYPATH=typeshed/ CWLTOOL_USE_MYPYC=1 pip install --verbose -e . && pytest --basetemp ./tmp |
| 167 | + |
| 168 | +release-test: FORCE |
| 169 | + git diff-index --quiet HEAD -- || ( echo You have uncommited changes, please commit them and try again; false ) |
| 170 | + ./release-test.sh |
| 171 | + |
| 172 | +release: release-test |
| 173 | + . testenv2/bin/activate && \ |
| 174 | + testenv2/src/${MODULE}/setup.py sdist bdist_wheel && \ |
| 175 | + pip install twine && \ |
| 176 | + twine upload testenv2/src/${MODULE}/dist/* && \ |
| 177 | + git tag ${VERSION} && git push --tags |
| 178 | + |
| 179 | +FORCE: |
| 180 | + |
| 181 | +# Use this to print the value of a Makefile variable |
| 182 | +# Example `make print-VERSION` |
| 183 | +# From https://www.cmcrossroads.com/article/printing-value-makefile-variable |
| 184 | +print-% : ; @echo $* = $($*) |
0 commit comments