Skip to content

Commit 0c5dba5

Browse files
committed
measure code coverage (#12)
1 parent 2514a23 commit 0c5dba5

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed

Makefile

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# This file is part of schema-salad,
2+
# https://github.com/common-workflow-language/schema-salad/, 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 pep8 to check for basic Python code compliance
19+
# make autopep8 to fix most pep8 errors
20+
# make pylint to check Python code for enhanced compliance including naming
21+
# and documentation
22+
# make coverage-report to check coverage of the python scripts by the tests
23+
24+
MODULE=schema_salad
25+
26+
# `SHELL=bash` Will break Titus's laptop, so don't use BASH-isms like
27+
# `[[` conditional expressions.
28+
PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py
29+
DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257
30+
31+
VERSION=$(shell git describe --tags --dirty | sed s/v//)
32+
33+
## all : default task
34+
all: ./setup.py develop
35+
36+
## help : print this help message and exit
37+
help: Makefile
38+
@sed -n 's/^##//p' $<
39+
40+
## install-dep : install most of the development dependencies via pip
41+
install-dep: install-dependencies
42+
43+
install-dependencies:
44+
pip install --upgrade $(DEVPKGS)
45+
46+
## install : install the ${MODULE} module and schema-salad-tool
47+
install: FORCE
48+
./setup.py build install
49+
50+
## dist : create a module package for distribution
51+
dist: dist/${MODULE}-$(VERSION).tar.gz
52+
53+
dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES)
54+
./setup.py sdist
55+
56+
## clean : clean up all temporary / machine-generated files
57+
clean: FORCE
58+
rm -f ${MODILE}/*.pyc tests/*.pyc
59+
./setup.py clean --all || true
60+
rm -Rf .coverage
61+
rm -f diff-cover.html
62+
63+
## pep8 : check Python code style
64+
pep8: $(PYSOURCES)
65+
pep8 --exclude=_version.py --show-source --show-pep8 $^ || true
66+
67+
pep8_report.txt: $(PYSOURCES)
68+
pep8 --exclude=_version.py $^ > pep8_report.txt || true
69+
70+
diff_pep8_report: pep8_report.txt
71+
diff-quality --violations=pep8 pep8_report.txt
72+
73+
## pep257 : check Python code style
74+
pep257: $(PYSOURCES)
75+
pep257 --ignore=D100,D101,D102,D103 $^ || true
76+
77+
pep257_report.txt: $(PYSOURCES)
78+
pep257 setup.py $^ > pep257_report.txt 2>&1 || true
79+
80+
diff_pep257_report: pep257_report.txt
81+
diff-quality --violations=pep8 pep257_report.txt
82+
83+
## autopep8 : fix most Python code indentation and formatting
84+
autopep8: $(PYSOURCES)
85+
autopep8 --recursive --in-place --ignore E309 $^
86+
87+
# A command to automatically run astyle and autopep8 on appropriate files
88+
## format : check/fix all code indentation and formatting (runs autopep8)
89+
format: autopep8
90+
# Do nothing
91+
92+
## pylint : run static code analysis on Python code
93+
pylint: $(PYSOURCES)
94+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
95+
$^ || true
96+
97+
pylint_report.txt: ${PYSOURCES}
98+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
99+
$^ > pylint_report.txt || true
100+
101+
diff_pylint_report: pylint_report.txt
102+
diff-quality --violations=pylint pylint_report.txt
103+
104+
.coverage: $(PYSOURCES)
105+
python-coverage run --branch --source=${MODULE} tests/test_examples.py
106+
python-coverage run --append --branch --source=${MODULE} \
107+
-m schema_salad.main \
108+
--print-jsonld-context schema_salad/metaschema/metaschema.yml \
109+
> /dev/null
110+
python-coverage run --append --branch --source=${MODULE} \
111+
-m schema_salad.main \
112+
--print-rdfs schema_salad/metaschema/metaschema.yml \
113+
> /dev/null
114+
python-coverage run --append --branch --source=${MODULE} \
115+
-m schema_salad.main \
116+
--print-avro schema_salad/metaschema/metaschema.yml \
117+
> /dev/null
118+
python-coverage run --append --branch --source=${MODULE} \
119+
-m schema_salad.main \
120+
--print-rdf schema_salad/metaschema/metaschema.yml \
121+
> /dev/null
122+
python-coverage run --append --branch --source=${MODULE} \
123+
-m schema_salad.main \
124+
--print-pre schema_salad/metaschema/metaschema.yml \
125+
> /dev/null
126+
python-coverage run --append --branch --source=${MODULE} \
127+
-m schema_salad.main \
128+
--print-index schema_salad/metaschema/metaschema.yml \
129+
> /dev/null
130+
python-coverage run --append --branch --source=${MODULE} \
131+
-m schema_salad.main \
132+
--print-metadata schema_salad/metaschema/metaschema.yml \
133+
> /dev/null
134+
python-coverage run --append --branch --source=${MODULE} \
135+
-m schema_salad.makedoc schema_salad/metaschema/metaschema.yml \
136+
> /dev/null
137+
138+
139+
coverage.xml: .coverage
140+
python-coverage xml
141+
142+
coverage.html: htmlcov/index.html
143+
144+
htmlcov/index.html: .coverage
145+
python-coverage html
146+
@echo Test coverage of the Python code is now in htmlcov/index.html
147+
148+
coverage-report: .coverage
149+
python-coverage report
150+
151+
diff-cover: coverage-gcovr.xml coverage.xml
152+
diff-cover coverage-gcovr.xml coverage.xml
153+
154+
diff-cover.html: coverage-gcovr.xml coverage.xml
155+
diff-cover coverage-gcovr.xml coverage.xml \
156+
--html-report diff-cover.html
157+
158+
## test : run the ${MODULE} test suite
159+
test: FORCE
160+
python tests/test_examples.py
161+
162+
sloccount.sc: ${PYSOURCES} Makefile
163+
sloccount --duplicates --wide --details $^ > sloccount.sc
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+
FORCE:

0 commit comments

Comments
 (0)