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