Skip to content

Commit eac895b

Browse files
author
Peter Amstutz
committed
Use unicode strings instead of ASCII strings.
1 parent 1058750 commit eac895b

File tree

12 files changed

+140
-140
lines changed

12 files changed

+140
-140
lines changed

cwltool/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
5454
schema = copy.deepcopy(schema)
5555
schema["type"] = t
5656
return self.bind_input(schema, datum, lead_pos=lead_pos, tail_pos=tail_pos)
57-
raise validate.ValidationException("'%s' is not a valid union %s" % (datum, schema["type"]))
57+
raise validate.ValidationException(u"'%s' is not a valid union %s" % (datum, schema["type"]))
5858
elif isinstance(schema["type"], dict):
5959
st = copy.deepcopy(schema["type"])
6060
if binding and "inputBinding" not in st and "itemSeparator" not in binding and st["type"] in ("array", "map"):
@@ -129,7 +129,7 @@ def _capture_files(f):
129129
def tostr(self, value):
130130
if isinstance(value, dict) and value.get("class") == "File":
131131
if "path" not in value:
132-
raise WorkflowException("File object must have \"path\": %s" % (value))
132+
raise WorkflowException(u"File object must have \"path\": %s" % (value))
133133
return value["path"]
134134
else:
135135
return str(value)

cwltool/cwlrdf.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def makerdf(workflow, wf, ctx):
1111
doc_url, frg = urlparse.urldefrag(v)
1212
if "/" in frg:
1313
p, _ = frg.split("/")
14-
prefixes[p] = "%s#%s/" % (doc_url, p)
14+
prefixes[p] = u"%s#%s/" % (doc_url, p)
1515

1616
wf["@context"] = ctx
1717
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)
@@ -45,7 +45,7 @@ def dot_with_parameters(g, stdout):
4545
}""")
4646

4747
for step, run, runtype in qres:
48-
stdout.write('"%s" [label="%s"]\n' % (lastpart(step), "%s (%s)" % (lastpart(step), lastpart(run))))
48+
stdout.write(u'"%s" [label="%s"]\n' % (lastpart(step), "%s (%s)" % (lastpart(step), lastpart(run))))
4949

5050
qres = g.query(
5151
"""SELECT ?step ?inp ?source
@@ -56,9 +56,9 @@ def dot_with_parameters(g, stdout):
5656
}""")
5757

5858
for step, inp, source in qres:
59-
stdout.write('"%s" [shape=box]\n' % (lastpart(inp)))
60-
stdout.write('"%s" -> "%s" [label="%s"]\n' % (lastpart(source), lastpart(inp), ""))
61-
stdout.write('"%s" -> "%s" [label="%s"]\n' % (lastpart(inp), lastpart(step), ""))
59+
stdout.write(u'"%s" [shape=box]\n' % (lastpart(inp)))
60+
stdout.write(u'"%s" -> "%s" [label="%s"]\n' % (lastpart(source), lastpart(inp), ""))
61+
stdout.write(u'"%s" -> "%s" [label="%s"]\n' % (lastpart(inp), lastpart(step), ""))
6262

6363
qres = g.query(
6464
"""SELECT ?step ?out
@@ -68,8 +68,8 @@ def dot_with_parameters(g, stdout):
6868
}""")
6969

7070
for step, out in qres:
71-
stdout.write('"%s" [shape=box]\n' % (lastpart(out)))
72-
stdout.write('"%s" -> "%s" [label="%s"]\n' % (lastpart(step), lastpart(out), ""))
71+
stdout.write(u'"%s" [shape=box]\n' % (lastpart(out)))
72+
stdout.write(u'"%s" -> "%s" [label="%s"]\n' % (lastpart(step), lastpart(out), ""))
7373

7474
qres = g.query(
7575
"""SELECT ?out ?source
@@ -79,8 +79,8 @@ def dot_with_parameters(g, stdout):
7979
}""")
8080

8181
for out, source in qres:
82-
stdout.write('"%s" [shape=octagon]\n' % (lastpart(out)))
83-
stdout.write('"%s" -> "%s" [label="%s"]\n' % (lastpart(source), lastpart(out), ""))
82+
stdout.write(u'"%s" [shape=octagon]\n' % (lastpart(out)))
83+
stdout.write(u'"%s" -> "%s" [label="%s"]\n' % (lastpart(source), lastpart(out), ""))
8484

8585
qres = g.query(
8686
"""SELECT ?inp
@@ -90,7 +90,7 @@ def dot_with_parameters(g, stdout):
9090
}""")
9191

9292
for (inp,) in qres:
93-
stdout.write('"%s" [shape=octagon]\n' % (lastpart(inp)))
93+
stdout.write(u'"%s" [shape=octagon]\n' % (lastpart(inp)))
9494

9595
def dot_without_parameters(g, stdout):
9696
dotname = {}
@@ -130,14 +130,14 @@ def dot_without_parameters(g, stdout):
130130
if wf in subworkflows:
131131
if wf not in dotname:
132132
dotname[wf] = "cluster_" + lastpart(wf)
133-
stdout.write('subgraph "%s" { label="%s"\n' % (dotname[wf], lastpart(wf)))
133+
stdout.write(u'subgraph "%s" { label="%s"\n' % (dotname[wf], lastpart(wf)))
134134
currentwf = wf
135135
clusternode[wf] = step
136136
else:
137137
currentwf = None
138138

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

142142
if currentwf is not None:
143143
stdout.write("}\n")
@@ -157,12 +157,12 @@ def dot_without_parameters(g, stdout):
157157
for src, sink, srcrun, sinkrun in qres:
158158
attr = ""
159159
if srcrun in clusternode:
160-
attr += 'ltail="%s"' % dotname[srcrun]
160+
attr += u'ltail="%s"' % dotname[srcrun]
161161
src = clusternode[srcrun]
162162
if sinkrun in clusternode:
163-
attr += ' lhead="%s"' % dotname[sinkrun]
163+
attr += u' lhead="%s"' % dotname[sinkrun]
164164
sink = clusternode[sinkrun]
165-
stdout.write('"%s" -> "%s" [%s]\n' % (dotname[src], dotname[sink], attr))
165+
stdout.write(u'"%s" -> "%s" [%s]\n' % (dotname[src], dotname[sink], attr))
166166

167167

168168
def printdot(workflow, wf, ctx, stdout, include_parameters=False):

cwltool/cwltest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ def compare(a, b):
2626
if isinstance(a, dict):
2727
if a.get("class") == "File":
2828
if not (b["path"].endswith("/" + a["path"]) or ("/" not in b["path"] and a["path"] == b["path"])):
29-
raise CompareFail("%s does not end with %s" %(b["path"], a["path"]))
29+
raise CompareFail(u"%s does not end with %s" %(b["path"], a["path"]))
3030
# ignore empty collections
3131
b = {k: v for k, v in b.iteritems()
3232
if not isinstance(v, (list, dict)) or len(v) > 0}
3333
if len(a) != len(b):
34-
raise CompareFail("expected %s\ngot %s" % (json.dumps(a, indent=4, sort_keys=True), json.dumps(b, indent=4, sort_keys=True)))
34+
raise CompareFail(u"expected %s\ngot %s" % (json.dumps(a, indent=4, sort_keys=True), json.dumps(b, indent=4, sort_keys=True)))
3535
for c in a:
3636
if a.get("class") != "File" or c != "path":
3737
if c not in b:
38-
raise CompareFail("%s not in %s" % (c, b))
38+
raise CompareFail(u"%s not in %s" % (c, b))
3939
if not compare(a[c], b[c]):
4040
return False
4141
return True
4242
elif isinstance(a, list):
4343
if len(a) != len(b):
44-
raise CompareFail("expected %s\ngot %s" % (json.dumps(a, indent=4, sort_keys=True), json.dumps(b, indent=4, sort_keys=True)))
44+
raise CompareFail(u"expected %s\ngot %s" % (json.dumps(a, indent=4, sort_keys=True), json.dumps(b, indent=4, sort_keys=True)))
4545
for c in xrange(0, len(a)):
4646
if not compare(a[c], b[c]):
4747
return False
4848
return True
4949
else:
5050
if a != b:
51-
raise CompareFail("%s != %s" % (a, b))
51+
raise CompareFail(u"%s != %s" % (a, b))
5252
else:
5353
return True
5454
except Exception as e:
@@ -90,14 +90,14 @@ def run_test(args, i, t):
9090
if err.returncode == UNSUPPORTED_FEATURE:
9191
return UNSUPPORTED_FEATURE
9292
else:
93-
_logger.error("""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
93+
_logger.error(u"""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
9494
_logger.error(t.get("doc"))
9595
_logger.error("Returned non-zero")
9696
return 1
9797
except yaml.scanner.ScannerError as e:
98-
_logger.error("""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
98+
_logger.error(u"""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
9999
_logger.error(outstr)
100-
_logger.error("Parse error %s", str(e))
100+
_logger.error(u"Parse error %s", str(e))
101101

102102
pwd = os.path.abspath(os.path.dirname(t["job"]))
103103
# t["args"] = map(lambda x: x.replace("$PWD", pwd), t["args"])
@@ -114,12 +114,12 @@ def run_test(args, i, t):
114114
try:
115115
compare(t.get(key), out.get(key))
116116
except CompareFail as ex:
117-
_logger.warn("""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
117+
_logger.warn(u"""Test failed: %s""", " ".join([pipes.quote(tc) for tc in test_command]))
118118
_logger.warn(t.get("doc"))
119-
_logger.warn("%s expected %s\n got %s", key,
119+
_logger.warn(u"%s expected %s\n got %s", key,
120120
json.dumps(t.get(key), indent=4, sort_keys=True),
121121
json.dumps(out.get(key), indent=4, sort_keys=True))
122-
_logger.warn("Compare failure %s", ex)
122+
_logger.warn(u"Compare failure %s", ex)
123123
failed = True
124124

125125
if outdir:
@@ -164,7 +164,7 @@ def main():
164164

165165
if args.l:
166166
for i, t in enumerate(tests):
167-
print "[%i] %s" % (i+1, t["doc"].strip())
167+
print u"[%i] %s" % (i+1, t["doc"].strip())
168168
return 0
169169

170170
if args.n is not None:

cwltool/docker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
4949
_logger.info(str(cmd))
5050
if not dry_run:
5151
if os.path.exists(dockerRequirement["dockerLoad"]):
52-
_logger.info("Loading docker image from %s", dockerRequirement["dockerLoad"])
52+
_logger.info(u"Loading docker image from %s", dockerRequirement["dockerLoad"])
5353
with open(dockerRequirement["dockerLoad"], "rb") as f:
5454
loadproc = subprocess.Popen(cmd, stdin=f, stdout=sys.stderr)
5555
else:
5656
loadproc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=sys.stderr)
57-
_logger.info("Sending GET request to %s", dockerRequirement["dockerLoad"])
57+
_logger.info(u"Sending GET request to %s", dockerRequirement["dockerLoad"])
5858
req = requests.get(dockerRequirement["dockerLoad"], stream=True)
5959
n = 0
6060
for chunk in req.iter_content(1024*1024):
@@ -96,6 +96,6 @@ def get_from_requirements(r, req, pull_image, dry_run=False):
9696
return r["dockerImageId"]
9797
else:
9898
if req:
99-
raise process.WorkflowException("Docker image %s not found" % r["dockerImageId"])
99+
raise process.WorkflowException(u"Docker image %s not found" % r["dockerImageId"])
100100

101101
return None

cwltool/draft2tool.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def run(self, **kwargs):
3434
try:
3535
self.output_callback(self.builder.do_eval(self.script), "success")
3636
except Exception as e:
37-
_logger.warn("Failed to evaluate expression:\n%s", e, exc_info=(e if kwargs.get('debug') else False))
37+
_logger.warn(u"Failed to evaluate expression:\n%s", e, exc_info=(e if kwargs.get('debug') else False))
3838
self.output_callback({}, "permanentFail")
3939

4040
def job(self, joborder, input_basedir, output_callback, **kwargs):
@@ -75,7 +75,7 @@ def revmap_file(builder, outdir, f):
7575
f["hostfs"] = True
7676
return f
7777
else:
78-
raise WorkflowException("Output file path %s must be within designated output directory (%s) or an input file pass through." % (f["path"], builder.outdir))
78+
raise WorkflowException(u"Output file path %s must be within designated output directory (%s) or an input file pass through." % (f["path"], builder.outdir))
7979

8080

8181
class CommandLineTool(Process):
@@ -94,7 +94,7 @@ def makePathMapper(self, reffiles, input_basedir, **kwargs):
9494
return PathMapper(reffiles, input_basedir)
9595
except OSError as e:
9696
if e.errno == errno.ENOENT:
97-
raise WorkflowException("Missing input file %s" % e)
97+
raise WorkflowException(u"Missing input file %s" % e)
9898

9999
def job(self, joborder, input_basedir, output_callback, **kwargs):
100100
builder = self._init_job(joborder, input_basedir, **kwargs)
@@ -139,11 +139,11 @@ def job(self, joborder, input_basedir, output_callback, **kwargs):
139139
j.hints = self.hints
140140
j.name = uniquename(kwargs.get("name", str(id(j))))
141141

142-
_logger.debug("[job %s] initializing from %s%s",
142+
_logger.debug(u"[job %s] initializing from %s%s",
143143
j.name,
144144
self.tool.get("id", ""),
145-
" as part of %s" % kwargs["part_of"] if "part_of" in kwargs else "")
146-
_logger.debug("[job %s] %s", j.name, json.dumps(joborder, indent=4))
145+
u" as part of %s" % kwargs["part_of"] if "part_of" in kwargs else "")
146+
_logger.debug(u"[job %s] %s", j.name, json.dumps(joborder, indent=4))
147147

148148

149149
builder.pathmapper = None
@@ -170,12 +170,12 @@ def _check_adjust(f):
170170
f["containerfs"] = True
171171
return f
172172

173-
_logger.debug("[job %s] path mappings is %s", j.name, json.dumps({p: builder.pathmapper.mapper(p) for p in builder.pathmapper.files()}, indent=4))
173+
_logger.debug(u"[job %s] path mappings is %s", j.name, json.dumps({p: builder.pathmapper.mapper(p) for p in builder.pathmapper.files()}, indent=4))
174174

175175
adjustFileObjs(builder.files, _check_adjust)
176176
adjustFileObjs(builder.bindings, _check_adjust)
177177

178-
_logger.debug("[job %s] command line bindings is %s", j.name, json.dumps(builder.bindings, indent=4))
178+
_logger.debug(u"[job %s] command line bindings is %s", j.name, json.dumps(builder.bindings, indent=4))
179179

180180
dockerReq, _ = self.get_requirement("DockerRequirement")
181181
if dockerReq and kwargs.get("use_container"):
@@ -224,7 +224,7 @@ def collect_output_ports(self, ports, builder, outdir):
224224
if builder.fs_access.exists(custom_output):
225225
with builder.fs_access.open(custom_output, "r") as f:
226226
ret = yaml.load(f)
227-
_logger.debug("Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
227+
_logger.debug(u"Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
228228
adjustFileObjs(ret, remove_hostfs)
229229
adjustFileObjs(ret, functools.partial(revmap_file, builder, outdir))
230230
adjustFileObjs(ret, remove_hostfs)
@@ -236,7 +236,7 @@ def collect_output_ports(self, ports, builder, outdir):
236236
try:
237237
ret[fragment] = self.collect_output(port, builder, outdir)
238238
except Exception as e:
239-
raise WorkflowException("Error collecting output for parameter '%s': %s" % (shortname(port["id"]), e))
239+
raise WorkflowException(u"Error collecting output for parameter '%s': %s" % (shortname(port["id"]), e))
240240
if ret:
241241
adjustFileObjs(ret, remove_hostfs)
242242
validate.validate_ex(self.names.get_name("outputs_record_schema", ""), ret)
@@ -303,7 +303,7 @@ def collect_output(self, schema, builder, outdir):
303303
if optional and r is None:
304304
pass
305305
elif (r is None or len(r) != 1 or not isinstance(r[0], dict) or "path" not in r[0]):
306-
raise WorkflowException("Expression must return a file object for %s." % schema["id"])
306+
raise WorkflowException(u"Expression must return a file object for %s." % schema["id"])
307307

308308
if singlefile:
309309
if not r and not optional:

cwltool/expression.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
_logger = logging.getLogger("cwltool")
1616

1717
def jshead(engineConfig, rootvars):
18-
return "\n".join(engineConfig + ["var %s = %s;" % (k, json.dumps(v, indent=4)) for k, v in rootvars.items()])
18+
return "\n".join(engineConfig + [u"var %s = %s;" % (k, json.dumps(v, indent=4)) for k, v in rootvars.items()])
1919

2020
def exeval(ex, jobinput, requirements, outdir, tmpdir, context, pull_image):
2121
if ex["engine"] == "https://w3id.org/cwl/cwl#JsonPointer":
2222
try:
2323
obj = {"job": jobinput, "context": context, "outdir": outdir, "tmpdir": tmpdir}
2424
return schema_salad.ref_resolver.resolve_json_pointer(obj, ex["script"])
2525
except ValueError as v:
26-
raise WorkflowException("%s in %s" % (v, obj))
26+
raise WorkflowException(u"%s in %s" % (v, obj))
2727

2828
if ex["engine"] == "https://w3id.org/cwl/cwl#JavascriptEngine":
2929
engineConfig = []
@@ -59,7 +59,7 @@ class DR(object):
5959
"tmpdir": tmpdir,
6060
}
6161

62-
_logger.debug("Invoking expression engine %s with %s",
62+
_logger.debug(u"Invoking expression engine %s with %s",
6363
runtime + aslist(r["engineCommand"]),
6464
json.dumps(inp, indent=4))
6565

@@ -71,11 +71,11 @@ class DR(object):
7171

7272
(stdoutdata, stderrdata) = sp.communicate(json.dumps(inp) + "\n\n")
7373
if sp.returncode != 0:
74-
raise WorkflowException("Expression engine returned non-zero exit code on evaluation of\n%s" % json.dumps(inp, indent=4))
74+
raise WorkflowException(u"Expression engine returned non-zero exit code on evaluation of\n%s" % json.dumps(inp, indent=4))
7575

7676
return json.loads(stdoutdata)
7777

78-
raise WorkflowException("Unknown expression engine '%s'" % ex["engine"])
78+
raise WorkflowException(u"Unknown expression engine '%s'" % ex["engine"])
7979

8080
seg_symbol = r"""\w+"""
8181
seg_single = r"""\['([^']|\\')+'\]"""
@@ -112,7 +112,7 @@ def param_interpolate(ex, obj, strip=True):
112112
return ex[0:m.start(0)] + leaf + param_interpolate(ex[m.end(0):], obj, False)
113113
else:
114114
if "$(" in ex or "${" in ex:
115-
_logger.warn("Warning possible workflow bug: found '$(' or '${' in '%s' but did not match valid parameter reference and InlineJavascriptRequirement not specified.", ex)
115+
_logger.warn(u"Warning possible workflow bug: found '$(' or '${' in '%s' but did not match valid parameter reference and InlineJavascriptRequirement not specified.", ex)
116116
return ex
117117

118118

0 commit comments

Comments
 (0)