Skip to content

PEP-8 style fixes. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*pyc
.tox
cwltool.egg-info/
3 changes: 3 additions & 0 deletions cwltool/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import expression
import avro
import schema_salad.validate as validate
from .errors import WorkflowException

CONTENT_LIMIT = 64 * 1024


def substitute(value, replace):
if replace[0] == "^":
return substitute(value[0:value.rindex('.')], replace[1:])
else:
return value + replace


class Builder(object):

def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
Expand Down
10 changes: 5 additions & 5 deletions cwltool/cwlrdf.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import json
from rdflib import Graph, plugin
from rdflib.serializer import Serializer
from rdflib import Graph


def printrdf(workflow, wf, ctx, sr):
wf["@context"] = ctx
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)
print(g.serialize(format=sr))


def printdot(workflow, wf, ctx, sr):
wf["@context"] = ctx
g = Graph().parse(data=json.dumps(wf), format='json-ld', location=workflow)

print "digraph {"

#g.namespace_manager.qname(predicate)
# g.namespace_manager.qname(predicate)

def lastpart(uri):
uri = str(uri)
if "/" in uri:
return uri[uri.rindex("/")+1:]
return uri[uri.rindex("/") + 1:]
else:
return uri

Expand Down Expand Up @@ -76,5 +77,4 @@ def lastpart(uri):
for (inp,) in qres:
print '"%s" [shape=octagon]' % (lastpart(inp))


print "}"
18 changes: 10 additions & 8 deletions cwltool/cwltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

UNSUPPORTED_FEATURE = 33


def compare(a, b):
try:
if isinstance(a, dict):
Expand Down Expand Up @@ -47,6 +48,7 @@ def compare(a, b):
except:
return False


def run_test(args, i, t):
out = {}
outdir = None
Expand Down Expand Up @@ -92,7 +94,7 @@ def run_test(args, i, t):
_logger.error(outstr)
_logger.error("Parse error %s", str(e))

pwd = os.path.abspath(os.path.dirname(t["job"]))
os.path.abspath(os.path.dirname(t["job"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, I think this line and the comment block below it can go away entirely

# t["args"] = map(lambda x: x.replace("$PWD", pwd), t["args"])
# if "stdin" in t:
# t["stdin"] = t["stdin"].replace("$PWD", pwd)
Expand All @@ -110,9 +112,9 @@ def run_test(args, i, t):
_logger.warn(t.get("doc"))
failed = True
_logger.warn("%s expected %s\n%s got %s", key,
t.get(key),
" " * len(key),
out.get(key))
t.get(key),
" " * len(key),
out.get(key))

if outdir:
shutil.rmtree(outdir)
Expand Down Expand Up @@ -144,14 +146,14 @@ def main():

if args.n is not None:
sys.stderr.write("\rTest [%i/%i] " % (args.n, len(tests)))
rt = run_test(args, args.n-1, tests[args.n-1])
rt = run_test(args, args.n - 1, tests[args.n - 1])
if rt == 1:
failures += 1
elif rt == UNSUPPORTED_FEATURE:
unsupported += 1
else:
for i, t in enumerate(tests):
sys.stderr.write("\rTest [%i/%i] " % (i+1, len(tests)))
sys.stderr.write("\rTest [%i/%i] " % (i + 1, len(tests)))
sys.stderr.flush()
rt = run_test(args, i, t)
if rt == 1:
Expand All @@ -160,8 +162,8 @@ def main():
unsupported += 1

if failures == 0 and unsupported == 0:
_logger.info("All tests passed")
return 0
_logger.info("All tests passed")
return 0
else:
_logger.warn("%i failures, %i unsupported features", failures, unsupported)
return 1
Expand Down
1 change: 1 addition & 0 deletions cwltool/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

_logger = logging.getLogger("cwltool")


def get_image(dockerRequirement, pull_image, dry_run=False):
found = False

Expand Down
15 changes: 4 additions & 11 deletions cwltool/draft2tool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import avro.schema
import json
import copy
from flatten import flatten
Expand All @@ -7,23 +6,19 @@
from pathmapper import PathMapper, DockerPathMapper
from job import CommandLineJob
import yaml
import glob
import logging
import hashlib
import random
from process import Process, shortname
from errors import WorkflowException
import schema_salad.validate as validate
from aslist import aslist
import expression
import re
import urlparse
import tempfile
from builder import CONTENT_LIMIT, substitute
import shellescape

_logger = logging.getLogger("cwltool")


class ExpressionTool(Process):
def __init__(self, toolpath_object, **kwargs):
super(ExpressionTool, self).__init__(toolpath_object, **kwargs)
Expand Down Expand Up @@ -106,12 +101,11 @@ def job(self, joborder, input_basedir, output_callback, **kwargs):
j.hints = self.hints

_logger.debug("[job %s] initializing from %s%s",
id(j),
self.tool.get("id", ""),
" as part of %s" % kwargs["part_of"] if "part_of" in kwargs else "")
id(j),
self.tool.get("id", ""),
" as part of %s" % kwargs["part_of"] if "part_of" in kwargs else "")
_logger.debug("[job %s] %s", id(j), json.dumps(joborder, indent=4))


builder.pathmapper = None

if self.tool.get("stdin"):
Expand Down Expand Up @@ -246,7 +240,6 @@ def collect_output(self, schema, builder, outdir):
if not builder.fs_access.exists(sf["path"]):
raise WorkflowException("Missing secondary file of '%s' of primary file '%s'" % (sf["path"], r["path"]))


if not r and schema["type"] == "record":
r = {}
for f in schema["fields"]:
Expand Down
17 changes: 8 additions & 9 deletions cwltool/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
import json
from aslist import aslist
import logging
import os
from errors import WorkflowException
import process
import yaml
import schema_salad.validate as validate
import schema_salad.ref_resolver

_logger = logging.getLogger("cwltool")


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

for r in reversed(requirements):
if r["class"] == "ExpressionEngineRequirement" and r["id"] == ex["engine"]:
Expand Down Expand Up @@ -56,13 +54,13 @@ class DR(object):

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

sp = subprocess.Popen(runtime + aslist(r["engineCommand"]),
shell=False,
close_fds=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
shell=False,
close_fds=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)

(stdoutdata, stderrdata) = sp.communicate(json.dumps(inp) + "\n\n")
if sp.returncode != 0:
Expand All @@ -72,6 +70,7 @@ class DR(object):

raise WorkflowException("Unknown expression engine '%s'" % ex["engine"])


def do_eval(ex, jobinput, requirements, outdir, tmpdir, context=None, pull_image=True):
if isinstance(ex, dict) and "engine" in ex and "script" in ex:
return exeval(ex, jobinput, requirements, outdir, tmpdir, context, pull_image)
Expand Down
10 changes: 4 additions & 6 deletions cwltool/job.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import subprocess
import os
import tempfile
import glob
import json
import yaml
import logging
import sys
import requests
import docker
from process import get_feature, empty_subtree
from errors import WorkflowException
Expand All @@ -20,6 +16,7 @@

needs_shell_quoting = re.compile(r"""(^$|[\s|&;()<>\'"$@])""").search


def deref_links(outputs):
if isinstance(outputs, dict):
if outputs.get("class") == "File":
Expand All @@ -33,12 +30,13 @@ def deref_links(outputs):
for v in outputs:
deref_links(v)


class CommandLineJob(object):
def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True, move_outputs=True, **kwargs):
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)

#with open(os.path.join(outdir, "cwl.input.json"), "w") as fp:
# with open(os.path.join(outdir, "cwl.input.json"), "w") as fp:
# json.dump(self.joborder, fp)

runtime = []
Expand Down Expand Up @@ -74,7 +72,7 @@ def run(self, dry_run=False, pull_image=True, rm_container=True, rm_tmpdir=True,

runtime.append("--env=TMPDIR=/tmp/job_tmp")

for t,v in self.environment.items():
for t, v in self.environment.items():
runtime.append("--env=%s=%s" % (t, v))

runtime.append(img_id)
Expand Down
Loading