Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
 * Remove unused imports
 * Fix indentation / remove tabs
 * Fix various pep8 errors and warnings
 * Resolve various static code analysis warnings
  • Loading branch information
gijzelaerr committed Feb 8, 2017
1 parent 1038c24 commit 4d1395a
Show file tree
Hide file tree
Showing 32 changed files with 733 additions and 629 deletions.
1 change: 1 addition & 0 deletions cwltool.py
Expand Up @@ -6,6 +6,7 @@
"""

import sys

from cwltool import main

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion cwltool/__main__.py
@@ -1,4 +1,5 @@
from . import main
import sys

from . import main

sys.exit(main.main())
19 changes: 12 additions & 7 deletions cwltool/builder.py
@@ -1,13 +1,15 @@
import copy
from .utils import aslist
from . import expression

import avro
import schema_salad.validate as validate
from schema_salad.sourceline import SourceLine
from typing import Any, Callable, Text, Type, Union

from . import expression
from .errors import WorkflowException
from .pathmapper import PathMapper, adjustFileObjs, normalizeFilesDirs
from .stdfsaccess import StdFsAccess
from .pathmapper import PathMapper, adjustFileObjs, adjustDirObjs, normalizeFilesDirs
from .utils import aslist

CONTENT_LIMIT = 64 * 1024

Expand All @@ -18,8 +20,8 @@ def substitute(value, replace): # type: (Text, Text) -> Text
else:
return value + replace

class Builder(object):

class Builder(object):
def __init__(self): # type: () -> None
self.names = None # type: avro.schema.Names
self.schemaDefs = None # type: Dict[Text, Dict[Text, Any]]
Expand All @@ -39,8 +41,12 @@ def __init__(self): # type: () -> None
self.build_job_script = None # type: Callable[[List[str]], Text]
self.debug = False # type: bool

def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
def bind_input(self, schema, datum, lead_pos=None, tail_pos=None):
# type: (Dict[Text, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[Text, Any]]
if tail_pos is None:
tail_pos = []
if lead_pos is None:
lead_pos = []
bindings = [] # type: List[Dict[Text,Text]]
binding = None # type: Dict[Text,Any]
if "inputBinding" in schema and isinstance(schema["inputBinding"], dict):
Expand Down Expand Up @@ -137,7 +143,6 @@ def _capture_files(f):
if schema["type"] == "Directory":
self.files.append(datum)


# Position to front of the sort key
if binding:
for bi in bindings:
Expand Down Expand Up @@ -198,7 +203,7 @@ def do_eval(self, ex, context=None, pull_image=True, recursive=False):
# type: (Union[Dict[Text, Text], Text], Any, bool, bool) -> Any
if recursive:
if isinstance(ex, dict):
return {k: self.do_eval(v, context, pull_image, recursive) for k,v in ex.iteritems()}
return {k: self.do_eval(v, context, pull_image, recursive) for k, v in ex.iteritems()}
if isinstance(ex, list):
return [self.do_eval(v, context, pull_image, recursive) for v in ex]

Expand Down
20 changes: 12 additions & 8 deletions cwltool/cwlrdf.py
@@ -1,11 +1,12 @@
import json
import urlparse
from .process import Process
from schema_salad.ref_resolver import Loader, ContextType

from rdflib import Graph
from schema_salad.jsonld_context import makerdf
from rdflib import Graph, plugin, URIRef
from rdflib.serializer import Serializer
from typing import Any, Dict, IO, Text, Union
from schema_salad.ref_resolver import ContextType
from typing import Any, Dict, IO, Text

from .process import Process


def gather(tool, ctx): # type: (Process, ContextType) -> Graph
g = Graph()
Expand All @@ -16,14 +17,16 @@ def visitor(t):
tool.visit(visitor)
return g


def printrdf(wf, ctx, sr, stdout):
# type: (Process, ContextType, Text, IO[Any]) -> None
stdout.write(gather(wf, ctx).serialize(format=sr))


def lastpart(uri): # type: (Any) -> Text
uri = Text(uri)
if "/" in uri:
return uri[uri.rindex("/")+1:]
return uri[uri.rindex("/") + 1:]
else:
return uri

Expand Down Expand Up @@ -84,6 +87,7 @@ def dot_with_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
for (inp,) in qres:
stdout.write(u'"%s" [shape=octagon]\n' % (lastpart(inp)))


def dot_without_parameters(g, stdout): # type: (Graph, IO[Any]) -> None
dotname = {} # type: Dict[Text,Text]
clusternode = {}
Expand Down Expand Up @@ -163,7 +167,7 @@ def printdot(wf, ctx, stdout, include_parameters=False):

stdout.write("digraph {")

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

if include_parameters:
dot_with_parameters(g, stdout)
Expand Down
19 changes: 11 additions & 8 deletions cwltool/docker.py
@@ -1,15 +1,18 @@
import subprocess
import logging
import sys
import requests
import os
from .errors import WorkflowException
import re
import subprocess
import sys
import tempfile
from typing import Any, Text, Union

import requests
from typing import Text

from .errors import WorkflowException

_logger = logging.getLogger("cwltool")


def get_image(dockerRequirement, pull_image, dry_run=False):
# type: (Dict[Text, Text], bool, bool) -> bool
found = False
Expand Down Expand Up @@ -44,7 +47,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
with open(os.path.join(dockerfile_dir, "Dockerfile"), "w") as df:
df.write(dockerRequirement["dockerFile"])
cmd = ["docker", "build", "--tag=%s" %
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
_logger.info(Text(cmd))
if not dry_run:
subprocess.check_call(cmd, stdout=sys.stderr)
Expand All @@ -62,7 +65,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
_logger.info(u"Sending GET request to %s", dockerRequirement["dockerLoad"])
req = requests.get(dockerRequirement["dockerLoad"], stream=True)
n = 0
for chunk in req.iter_content(1024*1024):
for chunk in req.iter_content(1024 * 1024):
n += len(chunk)
_logger.info("\r%i bytes" % (n))
loadproc.stdin.write(chunk)
Expand All @@ -73,7 +76,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
found = True
elif "dockerImport" in dockerRequirement:
cmd = ["docker", "import", str(dockerRequirement["dockerImport"]),
str(dockerRequirement["dockerImageId"])]
str(dockerRequirement["dockerImageId"])]
_logger.info(Text(cmd))
if not dry_run:
subprocess.check_call(cmd, stdout=sys.stderr)
Expand Down
3 changes: 2 additions & 1 deletion cwltool/docker_uid.py
@@ -1,5 +1,6 @@
import subprocess
from typing import Text, Union

from typing import Text


def docker_vm_uid(): # type: () -> int
Expand Down

0 comments on commit 4d1395a

Please sign in to comment.