Skip to content

Commit 268ebd1

Browse files
committed
modernize part 1
1 parent 2954278 commit 268ebd1

File tree

7 files changed

+255
-45
lines changed

7 files changed

+255
-45
lines changed

.coveragerc

Lines changed: 11 additions & 0 deletions
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

Makefile

Lines changed: 200 additions & 0 deletions
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 schema-salad-tool
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:
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: $(filter-out schema_salad/metaschema.py,$(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 $* = $($*)

cwlprov/tool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,3 +1261,6 @@ def main(args=None):
12611261
_logger.fatal(e)
12621262
return Status.IO_ERROR
12631263

1264+
1265+
if __name__ == "__main__":
1266+
main(sys.argv[1:])

mypy-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mypy

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
wheel
22
sphinx
3-
pytest

setup.py

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -32,48 +32,43 @@
3232
import cwlprov
3333

3434
setup(
35-
name = 'cwlprov',
36-
packages = find_packages(exclude=['contrib', 'docs', 'tests']), # Required
37-
version = cwlprov.__version__,
38-
description = 'cwlprov API for Python',
39-
long_description=long_description,
40-
long_description_content_type="text/markdown",
41-
author = 'Stian Soiland-Reyes',
42-
author_email = 'stain@apache.org',
43-
include_package_data=True,
44-
# https://www.apache.org/licenses/LICENSE-2.0
45-
license = "Apache License, Version 2.0",
46-
url = 'https://github.com/common-workflow-language/cwlprov-py',
47-
# download_url = 'https://github.com/stain/arcp-py/archive/0.1.0.tar.gz',
48-
keywords = "cwl prov cwlprov provenance",
49-
50-
install_requires=[
51-
'prov >= 1.5.1',
52-
'bdbag >= 1.4.1',
53-
#'bagit >= 1.6.4', # Transitive from bdbag
54-
'arcp >= 0.2.0',
55-
'rdflib-jsonld >= 0.4.0',
56-
'rdflib >= 4.2.2',
57-
],
58-
tests_require=['pytest'],
59-
entry_points={
60-
'console_scripts': ["cwlprov=cwlprov.tool:main"]
61-
},
62-
python_requires='>=3.6, <4',
63-
classifiers=[
64-
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
65-
'Development Status :: 2 - Pre-Alpha',
66-
67-
'Intended Audience :: Developers',
68-
'Topic :: Software Development :: Build Tools',
69-
# 'License :: OSI Approved :: Apache Software License',
70-
# https://github.com/pypa/pypi-legacy/issues/564
71-
#'License :: OSI Approved',
72-
# 'License :: OSI Approved :: Apache License, Version 2.0 (Apache-2.0)',
73-
'Programming Language :: Python :: 3',
74-
'Programming Language :: Python :: 3.6',
75-
'Topic :: Internet',
76-
'Topic :: System :: Archiving :: Packaging',
77-
],
78-
35+
name="cwlprov",
36+
packages=find_packages(exclude=["contrib", "docs", "tests"]), # Required
37+
version=cwlprov.__version__,
38+
description="cwlprov API for Python",
39+
long_description=long_description,
40+
long_description_content_type="text/markdown",
41+
author="Stian Soiland-Reyes",
42+
author_email="stain@apache.org",
43+
include_package_data=True,
44+
# https://www.apache.org/licenses/LICENSE-2.0
45+
license="Apache License, Version 2.0",
46+
url="https://github.com/common-workflow-language/cwlprov-py",
47+
# download_url = 'https://github.com/stain/arcp-py/archive/0.1.0.tar.gz',
48+
keywords="cwl prov cwlprov provenance",
49+
install_requires=[
50+
"prov >= 1.5.1",
51+
"bdbag >= 1.4.1",
52+
#'bagit >= 1.6.4', # Transitive from bdbag
53+
"arcp >= 0.2.0",
54+
"rdflib-jsonld >= 0.4.0, < 0.6.2",
55+
"rdflib >= 4.2.2, <6.0",
56+
],
57+
tests_require=["pytest"],
58+
entry_points={"console_scripts": ["cwlprov=cwlprov.tool:main"]},
59+
python_requires=">=3.6, <4",
60+
classifiers=[
61+
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
62+
"Development Status :: 2 - Pre-Alpha",
63+
"Intended Audience :: Developers",
64+
"Topic :: Software Development :: Build Tools",
65+
# 'License :: OSI Approved :: Apache Software License',
66+
# https://github.com/pypa/pypi-legacy/issues/564
67+
#'License :: OSI Approved',
68+
# 'License :: OSI Approved :: Apache License, Version 2.0 (Apache-2.0)',
69+
"Programming Language :: Python :: 3",
70+
"Programming Language :: Python :: 3.6",
71+
"Topic :: Internet",
72+
"Topic :: System :: Archiving :: Packaging",
73+
],
7974
)

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

0 commit comments

Comments
 (0)