Skip to content

Commit b375b59

Browse files
committed
format with black & sort inputs
1 parent 268ebd1 commit b375b59

File tree

8 files changed

+683
-343
lines changed

8 files changed

+683
-343
lines changed

ci-tests.yml

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

cwlprov/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"""
1818
cwlprov Python API and command line
1919
"""
20-
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
21-
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
22-
__license__ = "Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
23-
__version__ = "0.1.1"
20+
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
21+
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
22+
__license__ = (
23+
"Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
24+
)
25+
__version__ = "0.1.1"

cwlprov/cwl.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
"""
1818
cwlprov Crude CWL parsing
1919
"""
20-
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
21-
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
22-
__license__ = "Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
20+
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
21+
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
22+
__license__ = (
23+
"Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
24+
)
25+
2326

2427
class CWL:
2528
def __init__(self, ro):
2629
self.ro = ro
2730
self.cwl = self._load_packed()
28-
31+
2932
def _load_packed(self):
3033
# TODO
3134
pass
32-

cwlprov/prov.py

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
cwlprov Provenance
2020
2121
"""
22-
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
23-
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
24-
__license__ = "Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
22+
__author__ = "Stian Soiland-Reyes <https://orcid.org/0000-0001-9842-9718>"
23+
__copyright__ = "© 2018 Software Freedom Conservancy (SFC)"
24+
__license__ = (
25+
"Apache License, version 2.0 (https://www.apache.org/licenses/LICENSE-2.0)"
26+
)
2527

2628
import logging
29+
2730
from prov.identifier import Identifier, Namespace
2831
from prov.model import *
32+
2933
from .utils import *
3034

3135
CWLPROV = Namespace("cwlprov", "https://w3id.org/cwl/prov#")
@@ -34,14 +38,15 @@
3438

3539
MEDIA_TYPES = {
3640
"ttl": 'text/turtle; charset="UTF-8"',
37-
"rdf": 'application/rdf+xml',
38-
"json": 'application/json',
39-
"jsonld": 'application/ld+json',
40-
"xml": 'application/xml',
41+
"rdf": "application/rdf+xml",
42+
"json": "application/json",
43+
"jsonld": "application/ld+json",
44+
"xml": "application/xml",
4145
"provn": 'text/provenance-notation; charset="UTF-8"',
42-
"nt": 'application/n-triples',
46+
"nt": "application/n-triples",
4347
}
44-
EXTENSIONS = dict((v,k) for (k,v) in MEDIA_TYPES.items())
48+
EXTENSIONS = dict((v, k) for (k, v) in MEDIA_TYPES.items())
49+
4550

4651
def _as_identifier(uri_or_identifier):
4752
if not uri_or_identifier:
@@ -51,9 +56,11 @@ def _as_identifier(uri_or_identifier):
5156
else:
5257
return Identifier(str(uri_or_identifier))
5358

59+
5460
def _prov_attr(attr, elem):
5561
return first(elem.get_attribute(attr))
5662

63+
5764
class Provenance:
5865
def __init__(self, ro, run=None):
5966
self.ro = ro
@@ -66,7 +73,6 @@ def __init__(self, ro, run=None):
6673
def __repr__(self):
6774
return "Provenance<%s from %s>" % (self.uri, self._path)
6875

69-
7076
@property
7177
def uri(self):
7278
return self.run_id.uri
@@ -89,7 +95,7 @@ def activity(self, uri=None):
8995
return Activity(self, activity)
9096

9197
def _prov_format(self, media_type):
92-
for prov in (self.ro.provenance(self.uri) or ()):
98+
for prov in self.ro.provenance(self.uri) or ():
9399
if media_type == self.ro.mediatype(prov):
94100
return self.ro.resolve_path(prov)
95101

@@ -103,7 +109,9 @@ def _load_prov_document(self):
103109
if prov:
104110
_logger.info("Loading %s", prov)
105111
if c in rdf_candidates:
106-
doc = ProvDocument.deserialize(source=prov, format="rdf", rdf_format=c)
112+
doc = ProvDocument.deserialize(
113+
source=prov, format="rdf", rdf_format=c
114+
)
107115
else:
108116
doc = ProvDocument.deserialize(source=prov, format=c)
109117
return doc.unified(), prov
@@ -114,7 +122,7 @@ def record_with_attr(self, prov_type, attrib_value, with_attrib=PROV_ATTR_ACTIVI
114122
for elem in self.prov_doc.get_records(prov_type):
115123
if (with_attrib, attrib_value) in elem.attributes:
116124
yield elem
117-
125+
118126

119127
class _Prov:
120128
def __init__(self, provenance, record):
@@ -145,10 +153,10 @@ def types(self):
145153
def uri(self):
146154
i = self.id
147155
return i and i.uri
148-
156+
149157
def __repr__(self):
150158
return "<%s %s>" % (self.__class__.__name__, self.uri)
151-
159+
152160
def __str__(self):
153161
return self.record.get_provn()
154162

@@ -160,7 +168,6 @@ def _prov_attrs(self, attr):
160168

161169

162170
class Activity(_Prov):
163-
164171
def usage(self):
165172
return self._records(ProvUsage, Usage, PROV_ATTR_ACTIVITY)
166173

@@ -172,7 +179,7 @@ def association(self):
172179

173180
def plan(self):
174181
return first(a.plan_id for a in self.association() if a.plan_id)
175-
182+
176183
def steps(self):
177184
starts = self._records(ProvStart, Start, PROV_ATTR_STARTER)
178185
for s in starts:
@@ -192,34 +199,41 @@ def duration(self):
192199
s = start and start.time
193200
end = self.end()
194201
e = end and end.time
195-
return s and e and e-s
202+
return s and e and e - s
203+
196204

197205
class _Time(_Prov):
198206
@property
199207
def time(self):
200208
return self._prov_attr(PROV_ATTR_TIME)
201209

210+
202211
class _Start_or_End(_Time):
203212
@property
204213
def activity_id(self):
205214
return self._prov_attr(PROV_ATTR_ACTIVITY)
215+
206216
def activity(self):
207217
a = self.activity_id
208218
return a and self.provenance.activity(a)
209219

210220
@property
211221
def starter_id(self):
212222
return self._prov_attr(PROV_ATTR_STARTER)
223+
213224
def starter_activity(self):
214225
a = self.starter_id
215226
return a and self.provenance.activity(a)
216-
227+
217228

218229
class Start(_Start_or_End):
219230
pass
231+
232+
220233
class End(_Start_or_End):
221234
pass
222235

236+
223237
class Association(_Prov):
224238
@property
225239
def agent_id(self):
@@ -237,6 +251,7 @@ def activity(self):
237251
def plan_id(self):
238252
return self._prov_attr(PROV_ATTR_PLAN)
239253

254+
240255
class Specialization(_Prov):
241256
@property
242257
def general_entity_id(self):
@@ -254,14 +269,18 @@ def specific_entity(self):
254269
s = self.specific_entity_id
255270
return s and self.provenance.entity(s)
256271

257-
class Entity(_Prov):
258272

273+
class Entity(_Prov):
259274
def specializationOf(self):
260-
specializations = self._records(ProvSpecialization, Specialization, PROV_ATTR_SPECIFIC_ENTITY)
275+
specializations = self._records(
276+
ProvSpecialization, Specialization, PROV_ATTR_SPECIFIC_ENTITY
277+
)
261278
return (s.general_entity() for s in specializations)
262279

263280
def generalizationOf(self):
264-
specializations = self._records(ProvSpecialization, Specialization, PROV_ATTR_GENERAL_ENTITY)
281+
specializations = self._records(
282+
ProvSpecialization, Specialization, PROV_ATTR_GENERAL_ENTITY
283+
)
265284
return (s.specific_entity() for s in specializations)
266285

267286
@property
@@ -271,9 +290,11 @@ def value(self):
271290
@property
272291
def basename(self):
273292
return self._prov_attr(CWLPROV["basename"])
293+
274294
@property
275295
def nameroot(self):
276296
return self._prov_attr(CWLPROV["nameroot"])
297+
277298
@property
278299
def nameext(self):
279300
return self._prov_attr(CWLPROV["nameext"])
@@ -282,8 +303,12 @@ def derivations(self):
282303
return self._records(ProvDerivation, Derivation, PROV_ATTR_USED_ENTITY)
283304

284305
def secondary_files(self):
285-
return [d.generated_entity() for d in self.derivations()
286-
if CWLPROV["SecondaryFile"] in d.types()]
306+
return [
307+
d.generated_entity()
308+
for d in self.derivations()
309+
if CWLPROV["SecondaryFile"] in d.types()
310+
]
311+
287312

288313
class Derivation(_Prov):
289314
@property
@@ -305,12 +330,13 @@ def used_entity(self):
305330
@property
306331
def generation_id(self):
307332
return self._prov_attr(PROV_ATTR_GENERATION)
333+
308334
@property
309335
def usage_id(self):
310336
return self._prov_attr(PROV_ATTR_USAGE)
311337

312-
class _Usage_Or_Generation(_Time):
313338

339+
class _Usage_Or_Generation(_Time):
314340
@property
315341
def entity_id(self):
316342
return self._prov_attr(PROV_ATTR_ENTITY)
@@ -322,11 +348,11 @@ def entity(self):
322348
@property
323349
def role(self):
324350
return self._prov_attr(PROV_ROLE)
325-
351+
352+
326353
class Generation(_Usage_Or_Generation):
327354
pass
328355

356+
329357
class Usage(_Usage_Or_Generation):
330358
pass
331-
332-

0 commit comments

Comments
 (0)