Skip to content

Commit ea3a4e1

Browse files
committed
pyupgrade 3.6+
1 parent b375b59 commit ea3a4e1

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

cwlprov/prov.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"provn": 'text/provenance-notation; charset="UTF-8"',
4646
"nt": "application/n-triples",
4747
}
48-
EXTENSIONS = dict((v, k) for (k, v) in MEDIA_TYPES.items())
48+
EXTENSIONS = {v: k for (k, v) in MEDIA_TYPES.items()}
4949

5050

5151
def _as_identifier(uri_or_identifier):
@@ -71,7 +71,7 @@ def __init__(self, ro, run=None):
7171
raise OSError("No provenance found for %s" % self.run_id)
7272

7373
def __repr__(self):
74-
return "Provenance<%s from %s>" % (self.uri, self._path)
74+
return f"Provenance<{self.uri} from {self._path}>"
7575

7676
@property
7777
def uri(self):
@@ -155,7 +155,7 @@ def uri(self):
155155
return i and i.uri
156156

157157
def __repr__(self):
158-
return "<%s %s>" % (self.__class__.__name__, self.uri)
158+
return f"<{self.__class__.__name__} {self.uri}>"
159159

160160
def __str__(self):
161161
return self.record.get_provn()

cwlprov/ro.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _load_manifest(self):
140140
# so this test works offline
141141
context = _resource_as_path("context/bundle.jsonld").as_uri()
142142
g = Graph()
143-
with open(manifest_file, "r", encoding="UTF-8") as f:
143+
with open(manifest_file, encoding="UTF-8") as f:
144144
jsonld = f.read()
145145
# replace with file:/// URI
146146
jsonld = jsonld.replace("https://w3id.org/bundle/context", context)
@@ -206,8 +206,7 @@ def resources_with_provenance(self):
206206
new_annotation, self.manifest.subjects(OA.motivatedBy, PROV.has_provenance)
207207
)
208208
for a in anns:
209-
for t in a.hasTargets:
210-
yield t
209+
yield from a.hasTargets
211210

212211
def mediatype(self, path=None, uri=None):
213212
resource = self._uriref(path=path, uri=uri)

cwlprov/tool.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _info_set(bag, key):
374374
if isinstance(v, list):
375375
return set(v)
376376
else:
377-
return set([v])
377+
return {v}
378378

379379

380380
def _simpler_uuid(uri):
@@ -410,7 +410,7 @@ def _prov_attr(attr, elem):
410410
"provn": 'text/provenance-notation; charset="UTF-8"',
411411
"nt": "application/n-triples",
412412
}
413-
EXTENSIONS = dict((v, k) for (k, v) in MEDIA_TYPES.items())
413+
EXTENSIONS = {v: k for (k, v) in MEDIA_TYPES.items()}
414414

415415

416416
def _prov_format(ro, uri, media_type):
@@ -694,9 +694,9 @@ def validate_ro(self, full_validation=False):
694694
ro = self.ro
695695
args = self.args
696696
# If it has this prefix, it's probably OK
697-
cwlprov = set(
697+
cwlprov = {
698698
p for p in ro.conformsTo if p.startswith("https://w3id.org/cwl/prov/")
699-
)
699+
}
700700
if not cwlprov:
701701
if full_validation or not args.quiet:
702702
_logger.warning("Missing CWLProv profile: %s", ro.bag.path)
@@ -726,9 +726,9 @@ def info(self):
726726
if not args.quiet:
727727
self.print(ro.bag.info.get("External-Description", "Research Object"))
728728
self.print("Research Object ID: %s" % ro.id)
729-
cwlprov = set(
729+
cwlprov = {
730730
p for p in ro.conformsTo if p.startswith("https://w3id.org/cwl/prov/")
731-
)
731+
}
732732
if cwlprov:
733733
self.print("Profile: %s" % many(cwlprov))
734734
w = ro.workflow_id
@@ -835,7 +835,7 @@ def prov(self):
835835
if args.formats:
836836
format = ro.mediatype(prov) or ""
837837
format = EXTENSIONS.get(format, format)
838-
self.print("%s %s" % (format, (self._resource_path(prov))))
838+
self.print(f"{format} {(self._resource_path(prov))}")
839839
else:
840840
self.print("%s" % self._resource_path(prov))
841841
else:
@@ -1112,7 +1112,7 @@ def runs(self):
11121112
return Status.UNKNOWN_RUN
11131113
label = first(activity.get_attribute("prov:label")) or ""
11141114
is_master = run == ro.workflow_id
1115-
self.print("%s %s %s" % (name, is_master and "*" or " ", label))
1115+
self.print("{} {} {}".format(name, is_master and "*" or " ", label))
11161116
else:
11171117
self.print(name)
11181118
if self.hints:
@@ -1166,7 +1166,7 @@ def rerun(self):
11661166
)
11671167
return Status.NOT_IMPLEMENTED
11681168
if run.startswith("#"):
1169-
wf_arg = "%s%s" % (wf_file, run)
1169+
wf_arg = f"{wf_file}{run}"
11701170
_logger.info("Tool %s", wf_arg)
11711171
else:
11721172
_logger.warning(
@@ -1262,7 +1262,7 @@ def _usage(self, activity_id, prov_doc):
12621262
time = _prov_attr(PROV_ATTR_TIME, u)
12631263
if args.start and args.end:
12641264
# 2 col timestamps
1265-
time_part = "%s %s " % (
1265+
time_part = "{} {} ".format(
12661266
time or "(unknown usage time) ",
12671267
TIME_PADDING,
12681268
)
@@ -1271,7 +1271,7 @@ def _usage(self, activity_id, prov_doc):
12711271
time_part = "%s " % (time or "(unknown usage time) ")
12721272
else:
12731273
time_part = ""
1274-
self.print("%sIn %s < %s" % (time_part, entity_id, role or ""))
1274+
self.print("{}In {} < {}".format(time_part, entity_id, role or ""))
12751275

12761276
def _generation(self, activity_id, prov_doc):
12771277
args = self.args
@@ -1287,7 +1287,7 @@ def _generation(self, activity_id, prov_doc):
12871287
time = _prov_attr(PROV_ATTR_TIME, g)
12881288
if args.start and args.end:
12891289
# 2 col timestamps
1290-
time_part = "%s %s " % (
1290+
time_part = "{} {} ".format(
12911291
TIME_PADDING,
12921292
time or "(unknown generation time)",
12931293
)
@@ -1296,7 +1296,7 @@ def _generation(self, activity_id, prov_doc):
12961296
time_part = "%s " % (time or "(unknown generation time)")
12971297
else:
12981298
time_part = ""
1299-
self.print("%sOut %s > %s" % (time_part, entity_id, role or ""))
1299+
self.print("{}Out {} > {}".format(time_part, entity_id, role or ""))
13001300

13011301
def print(self, msg="", *args):
13021302
if args and isinstance(msg, str) and "%" in msg:
@@ -1343,11 +1343,11 @@ def run(self):
13431343
padded_start_time = ""
13441344
if args.end and args.start:
13451345
# 2 columns
1346-
padded_start_time = "%s %s " % (start_time, TIME_PADDING)
1346+
padded_start_time = f"{start_time} {TIME_PADDING} "
13471347
elif args.end or args.start:
13481348
# 1 column, we don't care which
13491349
padded_start_time = "%s " % (start_time)
1350-
self.print("%sFlow %s [%s" % (padded_start_time, name, label))
1350+
self.print(f"{padded_start_time}Flow {name} [{label}")
13511351

13521352
# inputs
13531353
self._usage(activity_id, prov_doc)
@@ -1411,7 +1411,7 @@ def run(self):
14111411
# end
14121412
padded_end_time = ""
14131413
if args.end and args.start:
1414-
padded_end_time = "%s %s " % (TIME_PADDING, end_time)
1414+
padded_end_time = f"{TIME_PADDING} {end_time} "
14151415
elif args.end or args.start:
14161416
padded_end_time = "%s " % (end_time)
14171417

@@ -1422,7 +1422,7 @@ def run(self):
14221422
else:
14231423
w_duration = " (unknown duration)"
14241424

1425-
self.print("%sFlow %s ]%s%s" % (padded_end_time, name, label, w_duration))
1425+
self.print(f"{padded_end_time}Flow {name} ]{label}{w_duration}")
14261426

14271427
if self.hints:
14281428
print("Legend:")

0 commit comments

Comments
 (0)