Skip to content

Commit 692fcf9

Browse files
committed
use mypy 0.4.4 and new Text type
1 parent 24f1831 commit 692fcf9

26 files changed

+2136
-503
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ mypy: ${PYSOURCES}
155155
ln -s $(shell python -c 'from __future__ import print_function; import schema_salad; import os.path; print(os.path.dirname(schema_salad.__file__))') \
156156
typeshed/2.7/schema_salad
157157
MYPYPATH=typeshed/2.7 mypy --py2 --disallow-untyped-calls \
158-
--warn-redundant-casts --warn-unused-ignores cwltool
158+
--warn-redundant-casts --warn-unused-ignores --fast-parser \
159+
cwltool
159160

160161
FORCE:

cwltool/builder.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from . import expression
44
import avro
55
import schema_salad.validate as validate
6-
from typing import Any, Union, AnyStr, Callable, Type
6+
from typing import Any, Callable, Text, Type, Union
77
from .errors import WorkflowException
88
from .stdfsaccess import StdFsAccess
99
from .pathmapper import PathMapper, adjustFileObjs, adjustDirObjs, normalizeFilesDirs
1010

1111
CONTENT_LIMIT = 64 * 1024
1212

1313

14-
def substitute(value, replace): # type: (str, str) -> str
14+
def substitute(value, replace): # type: (Text, Text) -> Text
1515
if replace[0] == "^":
1616
return substitute(value[0:value.rindex('.')], replace[1:])
1717
else:
@@ -21,24 +21,24 @@ class Builder(object):
2121

2222
def __init__(self): # type: () -> None
2323
self.names = None # type: avro.schema.Names
24-
self.schemaDefs = None # type: Dict[str,Dict[unicode, Any]]
25-
self.files = None # type: List[Dict[unicode, unicode]]
24+
self.schemaDefs = None # type: Dict[Text, Dict[Text, Any]]
25+
self.files = None # type: List[Dict[Text, Text]]
2626
self.fs_access = None # type: StdFsAccess
27-
self.job = None # type: Dict[unicode, Union[Dict[unicode, Any], List, unicode]]
28-
self.requirements = None # type: List[Dict[str,Any]]
29-
self.outdir = None # type: str
30-
self.tmpdir = None # type: str
31-
self.resources = None # type: Dict[str, Union[int, str]]
32-
self.bindings = [] # type: List[Dict[str, Any]]
27+
self.job = None # type: Dict[Text, Union[Dict[Text, Any], List, Text]]
28+
self.requirements = None # type: List[Dict[Text, Any]]
29+
self.outdir = None # type: Text
30+
self.tmpdir = None # type: Text
31+
self.resources = None # type: Dict[Text, Union[int, Text]]
32+
self.bindings = [] # type: List[Dict[Text, Any]]
3333
self.timeout = None # type: int
3434
self.pathmapper = None # type: PathMapper
35-
self.stagedir = None # type: unicode
35+
self.stagedir = None # type: Text
3636
self.make_fs_access = None # type: Type[StdFsAccess]
3737

3838
def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
39-
# type: (Dict[unicode, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[str, Any]]
40-
bindings = [] # type: List[Dict[str,str]]
41-
binding = None # type: Dict[str,Any]
39+
# type: (Dict[Text, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[Text, Any]]
40+
bindings = [] # type: List[Dict[Text,Text]]
41+
binding = None # type: Dict[Text,Any]
4242
if "inputBinding" in schema and isinstance(schema["inputBinding"], dict):
4343
binding = copy.copy(schema["inputBinding"])
4444

@@ -52,7 +52,7 @@ def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
5252
# Handle union types
5353
if isinstance(schema["type"], list):
5454
for t in schema["type"]:
55-
if isinstance(t, (str, unicode)) and self.names.has_name(t, ""):
55+
if isinstance(t, (str, Text)) and self.names.has_name(t, ""):
5656
avsc = self.names.get_name(t, "")
5757
elif isinstance(t, dict) and "name" in t and self.names.has_name(t["name"], ""):
5858
avsc = self.names.get_name(t["name"], "")
@@ -134,23 +134,23 @@ def _capture_files(f):
134134

135135
return bindings
136136

137-
def tostr(self, value): # type: (Any) -> str
137+
def tostr(self, value): # type: (Any) -> Text
138138
if isinstance(value, dict) and value.get("class") in ("File", "Directory"):
139139
if "path" not in value:
140140
raise WorkflowException(u"%s object missing \"path\": %s" % (value["class"], value))
141141
return value["path"]
142142
else:
143-
return str(value)
143+
return Text(value)
144144

145-
def generate_arg(self, binding): # type: (Dict[str,Any]) -> List[str]
145+
def generate_arg(self, binding): # type: (Dict[Text,Any]) -> List[Text]
146146
value = binding.get("datum")
147147
if "valueFrom" in binding:
148148
value = self.do_eval(binding["valueFrom"], context=value)
149149

150150
prefix = binding.get("prefix")
151151
sep = binding.get("separate", True)
152152

153-
l = [] # type: List[Dict[str,str]]
153+
l = [] # type: List[Dict[Text,Text]]
154154
if isinstance(value, list):
155155
if binding.get("itemSeparator"):
156156
l = [binding["itemSeparator"].join([self.tostr(v) for v in value])]
@@ -182,7 +182,7 @@ def generate_arg(self, binding): # type: (Dict[str,Any]) -> List[str]
182182
return [a for a in args if a is not None]
183183

184184
def do_eval(self, ex, context=None, pull_image=True, recursive=False):
185-
# type: (Union[Dict[str, str], unicode], Any, bool, bool) -> Any
185+
# type: (Union[Dict[Text, Text], Text], Any, bool, bool) -> Any
186186
if recursive:
187187
if isinstance(ex, dict):
188188
return {k: self.do_eval(v, context, pull_image, recursive) for k,v in ex.iteritems()}

cwltool/cwlrdf.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from schema_salad.jsonld_context import makerdf
55
from rdflib import Graph, plugin, URIRef
66
from rdflib.serializer import Serializer
7-
from typing import Any, Union, Dict, IO
7+
from typing import Any, Dict, IO, Text, Union
88

99
def printrdf(workflow, wf, ctx, sr, stdout):
10-
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType, str, IO[Any]) -> None
10+
# type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Text, IO[Any]) -> None
1111
stdout.write(makerdf(workflow, wf, ctx).serialize(format=sr))
1212

13-
def lastpart(uri): # type: (Any) -> str
14-
uri = str(uri)
13+
def lastpart(uri): # type: (Any) -> Text
14+
uri = Text(uri)
1515
if "/" in uri:
1616
return uri[uri.rindex("/")+1:]
1717
else:
@@ -75,7 +75,7 @@ def dot_with_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
7575
stdout.write(u'"%s" [shape=octagon]\n' % (lastpart(inp)))
7676

7777
def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
78-
dotname = {} # type: Dict[str,str]
78+
dotname = {} # type: Dict[Text,Text]
7979
clusternode = {}
8080

8181
stdout.write("compound=true\n")
@@ -118,8 +118,8 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
118118
else:
119119
currentwf = None
120120

121-
if str(runtype) != "https://w3id.org/cwl/cwl#Workflow":
122-
stdout.write(u'"%s" [label="%s"]\n' % (dotname[step], urlparse.urldefrag(str(step))[1]))
121+
if Text(runtype) != "https://w3id.org/cwl/cwl#Workflow":
122+
stdout.write(u'"%s" [label="%s"]\n' % (dotname[step], urlparse.urldefrag(Text(step))[1]))
123123

124124
if currentwf is not None:
125125
stdout.write("}\n")
@@ -148,7 +148,7 @@ def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
148148

149149

150150
def printdot(workflow, wf, ctx, stdout, include_parameters=False):
151-
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType, Any, bool) -> None
151+
# type: (Union[Text, Text], Union[List[Dict[Text, Any]], Dict[Text, Any]], Loader.ContextType, Any, bool) -> None
152152
g = makerdf(workflow, wf, ctx)
153153

154154
stdout.write("digraph {")

cwltool/docker.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
from .errors import WorkflowException
77
import re
88
import tempfile
9-
from typing import Any, Union
9+
from typing import Any, Text, Union
1010

1111
_logger = logging.getLogger("cwltool")
1212

1313
def get_image(dockerRequirement, pull_image, dry_run=False):
14-
# type: (Dict[str,str], bool, bool) -> bool
14+
# type: (Dict[Text, Text], bool, bool) -> bool
1515
found = False
1616

1717
if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
1818
dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"]
1919

20-
for ln in subprocess.check_output(["docker", "images", "--no-trunc", "--all"]).splitlines():
20+
for ln in subprocess.check_output(
21+
["docker", "images", "--no-trunc", "--all"]).splitlines():
2122
try:
2223
m = re.match(r"^([^ ]+)\s+([^ ]+)\s+([^ ]+)", ln)
2324
sp = dockerRequirement["dockerImageId"].split(":")
@@ -31,24 +32,26 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
3132
pass
3233

3334
if not found and pull_image:
35+
cmd = [] # type: List[str]
3436
if "dockerPull" in dockerRequirement:
35-
cmd = ["docker", "pull", dockerRequirement["dockerPull"]]
36-
_logger.info(str(cmd))
37+
cmd = ["docker", "pull", str(dockerRequirement["dockerPull"])]
38+
_logger.info(Text(cmd))
3739
if not dry_run:
3840
subprocess.check_call(cmd, stdout=sys.stderr)
3941
found = True
4042
elif "dockerFile" in dockerRequirement:
4143
dockerfile_dir = str(tempfile.mkdtemp())
4244
with open(os.path.join(dockerfile_dir, "Dockerfile"), "w") as df:
4345
df.write(dockerRequirement["dockerFile"])
44-
cmd = ["docker", "build", "--tag=%s" % dockerRequirement["dockerImageId"], dockerfile_dir]
45-
_logger.info(str(cmd))
46+
cmd = ["docker", "build", "--tag=%s" %
47+
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
48+
_logger.info(Text(cmd))
4649
if not dry_run:
4750
subprocess.check_call(cmd, stdout=sys.stderr)
4851
found = True
4952
elif "dockerLoad" in dockerRequirement:
5053
cmd = ["docker", "load"]
51-
_logger.info(str(cmd))
54+
_logger.info(Text(cmd))
5255
if not dry_run:
5356
if os.path.exists(dockerRequirement["dockerLoad"]):
5457
_logger.info(u"Loading docker image from %s", dockerRequirement["dockerLoad"])
@@ -69,8 +72,9 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
6972
raise WorkflowException("Docker load returned non-zero exit status %i" % (rcode))
7073
found = True
7174
elif "dockerImport" in dockerRequirement:
72-
cmd = ["docker", "import", dockerRequirement["dockerImport"], dockerRequirement["dockerImageId"]]
73-
_logger.info(str(cmd))
75+
cmd = ["docker", "import", str(dockerRequirement["dockerImport"]),
76+
str(dockerRequirement["dockerImageId"])]
77+
_logger.info(Text(cmd))
7478
if not dry_run:
7579
subprocess.check_call(cmd, stdout=sys.stderr)
7680
found = True
@@ -79,15 +83,15 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
7983

8084

8185
def get_from_requirements(r, req, pull_image, dry_run=False):
82-
# type: (Dict[str,str], bool, bool, bool) -> Union[None,str]
86+
# type: (Dict[Text, Text], bool, bool, bool) -> Text
8387
if r:
8488
errmsg = None
8589
try:
8690
subprocess.check_output(["docker", "version"])
8791
except subprocess.CalledProcessError as e:
88-
errmsg = "Cannot communicate with docker daemon: " + str(e)
92+
errmsg = "Cannot communicate with docker daemon: " + Text(e)
8993
except OSError as e:
90-
errmsg = "'docker' executable not found: " + str(e)
94+
errmsg = "'docker' executable not found: " + Text(e)
9195

9296
if errmsg:
9397
if req:

cwltool/docker_uid.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import subprocess
2-
from typing import Union
2+
from typing import Text, Union
33

44

5-
def docker_vm_uid(): # type: () -> Union[int,None]
5+
def docker_vm_uid(): # type: () -> int
66
"""
77
Returns the UID of the default docker user inside the VM
88
@@ -20,7 +20,7 @@ def docker_vm_uid(): # type: () -> Union[int,None]
2020
return None
2121

2222

23-
def check_output_and_strip(cmd): # type: (List[str]) -> Union[str,None]
23+
def check_output_and_strip(cmd): # type: (List[Text]) -> Text
2424
"""
2525
Passes a command list to subprocess.check_output, returning None
2626
if an expected exception is raised
@@ -37,7 +37,7 @@ def check_output_and_strip(cmd): # type: (List[str]) -> Union[str,None]
3737
return None
3838

3939

40-
def docker_machine_name(): # type: () -> Union[str,None]
40+
def docker_machine_name(): # type: () -> Text
4141
"""
4242
Get the machine name of the active docker-machine machine
4343
:return: Name of the active machine or None if error
@@ -46,7 +46,7 @@ def docker_machine_name(): # type: () -> Union[str,None]
4646

4747

4848
def cmd_output_matches(check_cmd, expected_status):
49-
# type: (List[str], str) -> bool
49+
# type: (List[Text], Text) -> bool
5050
"""
5151
Runs a command and compares output to expected
5252
:param check_cmd: Command list to execute
@@ -76,7 +76,7 @@ def docker_machine_running(): # type: () -> bool
7676
return cmd_output_matches(['docker-machine', 'status', machine_name], 'Running')
7777

7878

79-
def cmd_output_to_int(cmd): # type: (List[str]) -> Union[int,None]
79+
def cmd_output_to_int(cmd): # type: (List[Text]) -> int
8080
"""
8181
Runs the provided command and returns the integer value of the result
8282
:param cmd: The command to run
@@ -91,15 +91,15 @@ def cmd_output_to_int(cmd): # type: (List[str]) -> Union[int,None]
9191
return None
9292

9393

94-
def boot2docker_uid(): # type: () -> Union[int,None]
94+
def boot2docker_uid(): # type: () -> int
9595
"""
9696
Gets the UID of the docker user inside a running boot2docker vm
9797
:return: the UID, or None if error (e.g. boot2docker not present or stopped)
9898
"""
9999
return cmd_output_to_int(['boot2docker', 'ssh', 'id', '-u'])
100100

101101

102-
def docker_machine_uid(): # type: () -> Union[int,None]
102+
def docker_machine_uid(): # type: () -> int
103103
"""
104104
Asks docker-machine for active machine and gets the UID of the docker user
105105
inside the vm

0 commit comments

Comments
 (0)