Skip to content

Commit 733cb14

Browse files
authored
Merge pull request #5 from common-workflow-language/modernize
Modernize
2 parents 2954278 + e2ebcba commit 733cb14

15 files changed

+1130
-403
lines changed

.coveragerc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[run]
2+
branch = True
3+
source = cwlprov
4+
5+
[report]
6+
exclude_lines =
7+
if self.debug:
8+
pragma: no cover
9+
raise NotImplementedError
10+
if __name__ == .__main__.:
11+
ignore_errors = True

.github/workflows/ci-tests.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Continous integration tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
tox:
12+
name: CI tests via Tox
13+
14+
runs-on: ubuntu-20.04
15+
16+
strategy:
17+
matrix:
18+
py-ver-major: [3]
19+
py-ver-minor: [6, 7, 8, 9, 10]
20+
step: [unit]
21+
# step: [lint, unit, mypy]
22+
23+
env:
24+
py-semver: ${{ format('{0}.{1}', matrix.py-ver-major, matrix.py-ver-minor) }}
25+
TOXENV: ${{ format('py{0}{1}-{2}', matrix.py-ver-major, matrix.py-ver-minor, matrix.step) }}
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
30+
- name: Set up Python
31+
uses: actions/setup-python@v2
32+
with:
33+
python-version: ${{ env.py-semver }}
34+
35+
- name: Cache for pip
36+
uses: actions/cache@v2
37+
with:
38+
path: ~/.cache/pip
39+
key: ${{ runner.os }}-pip-${{ matrix.step }}-${{ hashFiles('requirements.txt', 'tox.ini') }}
40+
41+
- name: Upgrade setuptools and install tox
42+
run: |
43+
pip install -U pip setuptools wheel
44+
pip install tox tox-gh-actions
45+
46+
- name: MyPy cache
47+
if: ${{ matrix.step == 'mypy' }}
48+
uses: actions/cache@v2
49+
with:
50+
path: .mypy_cache/${{ env.py-semver }}
51+
key: mypy-${{ env.py-semver }}
52+
53+
- name: Test with tox
54+
run: tox
55+
56+
- name: Upload coverage to Codecov
57+
if: ${{ matrix.step == 'unit' }}
58+
uses: codecov/codecov-action@v1
59+
with:
60+
fail_ci_if_error: true
61+
62+
tox-style:
63+
name: CI linters via Tox
64+
65+
runs-on: ubuntu-20.04
66+
67+
strategy:
68+
matrix:
69+
step: [lint-readme]
70+
# step: [lint-readme, pydocstyle]
71+
72+
env:
73+
py-semver: 3.9
74+
TOXENV: ${{ format('py39-{0}', matrix.step) }}
75+
76+
steps:
77+
- uses: actions/checkout@v2
78+
with:
79+
fetch-depth: 0
80+
81+
- name: Set up Python
82+
uses: actions/setup-python@v2
83+
with:
84+
python-version: ${{ env.py-semver }}
85+
86+
- name: Cache for pip
87+
uses: actions/cache@v2
88+
with:
89+
path: ~/.cache/pip
90+
key: ${{ runner.os }}-pip-${{ matrix.step }}-${{ hashFiles('requirements.txt') }}
91+
92+
- name: Upgrade setuptools and install tox
93+
run: |
94+
pip install -U pip setuptools wheel
95+
pip install tox tox-gh-actions
96+
97+
- if: ${{ matrix.step == 'pydocstyle' && github.event_name == 'pull_request'}}
98+
name: Create local branch for diff-quality for PRs
99+
run: git branch ${{github.base_ref}} origin/${{github.base_ref}}
100+
101+
- name: Test with tox
102+
run: tox
103+

Makefile

+200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# This file is part of cwlprov-py,
2+
# https://github.com/common-workflow-language/cwlprov-py/, 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 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=cwlprov
24+
PACKAGE=cwlprov
25+
26+
# `SHELL=bash` doesn't work for some, so don't use BASH-isms like
27+
# `[[` conditional expressions.
28+
PYSOURCES=$(wildcard ${MODULE}/**.py) setup.py
29+
DEVPKGS=diff_cover black pylint pep257 pydocstyle flake8 tox tox-pyenv \
30+
isort wheel autoflake flake8-bugbear pyupgrade bandit \
31+
-rtest-requirements.txt -rmypy-requirements.txt
32+
COVBASE=coverage run --append
33+
34+
# Updating the Major & Minor version below?
35+
# Don't forget to update setup.py as well
36+
#VERSION=8.2.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \
37+
# --max-count=1 --format=format:%cI`)
38+
39+
## all : default task
40+
all: dev
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: FORCE
50+
pip install --upgrade $(DEVPKGS)
51+
pip install -r requirements.txt
52+
53+
## install : install the ${MODULE} module and cwlprov
54+
install: FORCE
55+
pip install .
56+
57+
## dev : install the ${MODULE} module in dev mode
58+
dev: install-dep
59+
pip install -e .
60+
61+
## dist : create a module package for distribution
62+
dist: dist/${MODULE}-$(VERSION).tar.gz
63+
64+
dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES)
65+
python setup.py sdist bdist_wheel
66+
67+
## docs : make the docs
68+
docs: FORCE
69+
cd docs && $(MAKE) html
70+
71+
## clean : clean up all temporary / machine-generated files
72+
clean: FORCE
73+
rm -rf ${MODULE}/__pycache__
74+
python setup.py clean --all || true
75+
rm -Rf .coverage
76+
rm -f diff-cover.html
77+
78+
# Linting and code style related targets
79+
## sorting imports using isort: https://github.com/timothycrosley/isort
80+
sort_imports: $(PYSOURCES)
81+
isort $^
82+
83+
remove_unused_imports: $(PYSOURCES)
84+
autoflake --in-place --remove-all-unused-imports $^
85+
86+
pep257: pydocstyle
87+
## pydocstyle : check Python code style
88+
pydocstyle: $(PYSOURCES)
89+
pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true
90+
91+
pydocstyle_report.txt: $(PYSOURCES)
92+
pydocstyle setup.py $^ > $@ 2>&1 || true
93+
94+
diff_pydocstyle_report: pydocstyle_report.txt
95+
diff-quality --compare-branch=main --violations=pydocstyle --fail-under=100 $^
96+
97+
## format : check/fix all code indentation and formatting (runs black)
98+
format: $(PYSOURCES)
99+
black $^
100+
101+
format-check: $(PYSOURCES)
102+
black --diff --check $^
103+
104+
## pylint : run static code analysis on Python code
105+
pylint: $(PYSOURCES)
106+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
107+
$^ -j0|| true
108+
109+
pylint_report.txt: $(PYSOURCES)
110+
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
111+
$^ -j0> $@ || true
112+
113+
diff_pylint_report: pylint_report.txt
114+
diff-quality --violations=pylint pylint_report.txt
115+
116+
.coverage: FORCE
117+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) validate && ) true
118+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) info && ) true
119+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) who && ) true
120+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) prov && ) true
121+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) inputs && ) true
122+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) outputs && ) true
123+
$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) runs && ) true
124+
#$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) derived && ) true
125+
#$(foreach RO,$(shell ls test),coverage run -m cwlprov.tool -d test/$(RO) runtimes && ) true
126+
127+
coverage.xml: .coverage
128+
coverage xml
129+
130+
coverage.html: htmlcov/index.html
131+
132+
htmlcov/index.html: .coverage
133+
coverage html
134+
@echo Test coverage of the Python code is now in htmlcov/index.html
135+
136+
coverage-report: .coverage
137+
coverage report
138+
139+
diff-cover: coverage.xml
140+
diff-cover $^
141+
142+
diff-cover.html: coverage.xml
143+
diff-cover $^ --html-report $@
144+
145+
## test : run the ${MODULE} test suite
146+
test: $(PYSOURCES) FORCE
147+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) validate && ) true
148+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) info && ) true
149+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) who && ) true
150+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) prov && ) true
151+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) inputs && ) true
152+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) outputs && ) true
153+
$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) runs && ) true
154+
#$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) derived && ) true
155+
#$(foreach RO,$(shell ls test),python -m cwlprov.tool -d test/$(RO) runtimes && ) true
156+
157+
158+
## testcov : run the ${MODULE} test suite and collect coverage
159+
testcov: $(PYSOURCES)
160+
python setup.py test --addopts "--cov" ${PYTEST_EXTRA}
161+
162+
sloccount.sc: $(PYSOURCES) Makefile
163+
sloccount --duplicates --wide --details $^ > $@
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+
mypy3: mypy
174+
mypy: $(filter-out setup.py,$(PYSOURCES))
175+
mypy $^
176+
177+
pyupgrade: $(PYSOURCES)
178+
pyupgrade --exit-zero-even-if-changed --py36-plus $^
179+
180+
release-test: FORCE
181+
git diff-index --quiet HEAD -- || ( echo You have uncommited changes, please commit them and try again; false )
182+
./release-test.sh
183+
184+
release: release-test
185+
. testenv2/bin/activate && \
186+
python testenv2/src/${PACKAGE}/setup.py sdist bdist_wheel
187+
. testenv2/bin/activate && \
188+
pip install twine && \
189+
twine upload testenv2/src/${PACKAGE}/dist/* && \
190+
git tag ${VERSION} && git push --tags
191+
192+
flake8: $(PYSOURCES)
193+
flake8 $^
194+
195+
FORCE:
196+
197+
# Use this to print the value of a Makefile variable
198+
# Example `make print-VERSION`
199+
# From https://www.cmcrossroads.com/article/printing-value-makefile-variable
200+
print-% : ; @echo $* = $($*)

0 commit comments

Comments
 (0)