Skip to content

Commit 1255619

Browse files
committed
cwltool: misc improvements in type annotations and six lib integration
1 parent bb5f105 commit 1255619

File tree

7 files changed

+20
-19
lines changed

7 files changed

+20
-19
lines changed

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self): # type: () -> None
5656

5757
# One of "no_listing", "shallow_listing", "deep_listing"
5858
# Will be default "no_listing" for CWL v1.1
59-
self.loadListing = "deep_listing" # type: Union[None, Text]
59+
self.loadListing = "deep_listing" # type: Union[None, str]
6060

6161
def bind_input(self, schema, datum, lead_pos=None, tail_pos=None):
6262
# type: (Dict[Text, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[Text, Any]]
@@ -130,7 +130,7 @@ def bind_input(self, schema, datum, lead_pos=None, tail_pos=None):
130130
self.files.append(datum)
131131
if binding:
132132
if binding.get("loadContents"):
133-
with self.fs_access.open(datum["location"], str("rb")) as f:
133+
with self.fs_access.open(datum["location"], "rb") as f:
134134
datum["contents"] = f.read(CONTENT_LIMIT)
135135

136136
if "secondaryFiles" in schema:

cwltool/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from .stdfsaccess import StdFsAccess
3838
from .update import ALLUPDATES, UPDATES
3939

40-
4140
_logger = logging.getLogger("cwltool")
4241

4342
defaultStreamHandler = logging.StreamHandler()

cwltool/pack.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def find_run(d, loadref, runs): # type: (Any, Callable[[Text, Text], Union[Dict
2828
for s in d:
2929
find_run(s, loadref, runs)
3030
elif isinstance(d, dict):
31-
if "run" in d and isinstance(d["run"], (str, six.text_type)):
31+
if "run" in d and isinstance(d["run"], six.string_types)):
3232
if d["run"] not in runs:
3333
runs.add(d["run"])
3434
find_run(loadref(None, d["run"]), loadref, runs)
@@ -42,7 +42,7 @@ def find_ids(d, ids): # type: (Any, Set[Text]) -> None
4242
find_ids(s, ids)
4343
elif isinstance(d, dict):
4444
for i in ("id", "name"):
45-
if i in d and isinstance(d[i], (str, six.text_type)):
45+
if i in d and isinstance(d[i], six.string_types)):
4646
ids.add(d[i])
4747
for s in d.values():
4848
find_ids(s, ids)
@@ -52,7 +52,7 @@ def replace_refs(d, rewrite, stem, newstem):
5252
# type: (Any, Dict[Text, Text], Text, Text) -> None
5353
if isinstance(d, list):
5454
for s, v in enumerate(d):
55-
if isinstance(v, (str, six.text_type)):
55+
if isinstance(v, six.string_types):
5656
if v in rewrite:
5757
d[s] = rewrite[v]
5858
elif v.startswith(stem):
@@ -61,7 +61,7 @@ def replace_refs(d, rewrite, stem, newstem):
6161
replace_refs(v, rewrite, stem, newstem)
6262
elif isinstance(d, dict):
6363
for s, v in d.items():
64-
if isinstance(v, (str, six.text_type)):
64+
if isinstance(v, six.string_types):
6565
if v in rewrite:
6666
d[s] = rewrite[v]
6767
elif v.startswith(stem):

cwltool/process.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from schema_salad.sourceline import SourceLine
3131
from six.moves import urllib
3232

33-
from cwltool.utils import cmp_like_py2
33+
from .utils import cmp_like_py2
3434
from .builder import Builder
3535
from .errors import UnsupportedRequirement, WorkflowException
3636
from .pathmapper import (PathMapper, adjustDirObjs, get_listing,
@@ -603,8 +603,13 @@ def _init_job(self, joborder, **kwargs):
603603
builder.bindings.append(cm)
604604

605605
# use python2 like sorting of heterogeneous lists
606-
# (containing str and int types)
607-
builder.bindings.sort(key=cmp_to_key(cmp_like_py2))
606+
# (containing str and int types),
607+
# TODO: unify for both runtime
608+
if six.PY3:
609+
key = cmp_to_key(cmp_like_py2)
610+
else: # PY2
611+
key = lambda dict: dict["position"]
612+
builder.bindings.sort(key=key)
608613
builder.resources = self.evalResources(builder, kwargs)
609614

610615
return builder

cwltool/sandboxjs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class JavascriptException(Exception):
2929
minimum_node_version_str = '0.10.26'
3030

3131
def check_js_threshold_version(working_alias):
32-
# type: (Text) -> bool
32+
# type: (str) -> bool
3333

3434
"""Checks if the nodeJS engine version on the system
3535
with the allowed minimum version.

cwltool/update.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import six
1111
from six.moves import urllib
12-
from six import u
1312
import schema_salad.validate
1413
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1514
from schema_salad.ref_resolver import Loader
@@ -62,7 +61,7 @@ def _draft2toDraft3dev1(doc, loader, baseuri, update_steps=True):
6261
else:
6362
raise Exception("Unexpected code path.")
6463
r["id"] = imp
65-
_, frag = u(urllib.parse.urldefrag(imp))
64+
_, frag = urllib.parse.urldefrag(imp)
6665
if frag:
6766
frag = "#" + frag
6867
r = findId(r, frag)
@@ -217,9 +216,7 @@ def _draftDraft3dev2toDev3(doc, loader, baseuri):
217216
else:
218217
raise Exception("Unexpected code path.")
219218
r["id"] = imp
220-
# explicit conversion of urldfrag to unicode,
221-
# to avoid mypy error
222-
frag = u(urllib.parse.urldefrag(imp)[1])
219+
frag = urllib.parse.urldefrag(imp)[1]
223220
if frag:
224221
frag = "#" + frag
225222
r = findId(r, frag)
@@ -267,7 +264,7 @@ def traverseImport(doc, loader, baseuri, func):
267264
else:
268265
raise Exception("Unexpected code path.")
269266
r["id"] = imp
270-
_, frag = urllib.parse.urldefrag(imp).decode('ascii')
267+
_, frag = urllib.parse.urldefrag(imp)
271268
if frag:
272269
frag = "#" + frag
273270
r = findId(r, frag)
@@ -354,7 +351,7 @@ def _draft3toDraft4dev1(doc, loader, baseuri):
354351
if isinstance(doc, dict):
355352
if "class" in doc and doc["class"] == "Workflow":
356353
def fixup(f): # type: (Text) -> Text
357-
doc, frg = u(urllib.parse.urldefrag(f))
354+
doc, frg = urllib.parse.urldefrag(f)
358355
frg = '/'.join(frg.rsplit('.', 1))
359356
return doc + "#" + frg
360357

cwltool/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def __init__(self, toolpath_object, pos, **kwargs):
676676
for stepfield, toolfield in (("in", "inputs"), ("out", "outputs")):
677677
toolpath_object[toolfield] = []
678678
for n, step_entry in enumerate(toolpath_object[stepfield]):
679-
if isinstance(step_entry, (str, six.text_type)):
679+
if isinstance(step_entry, six.string_types):
680680
param = CommentedMap() # type: CommentedMap
681681
inputid = step_entry
682682
else:

0 commit comments

Comments
 (0)