Skip to content

Commit 4d1395a

Browse files
committed
cleanup
* Remove unused imports * Fix indentation / remove tabs * Fix various pep8 errors and warnings * Resolve various static code analysis warnings
1 parent 1038c24 commit 4d1395a

32 files changed

+733
-629
lines changed

cwltool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import sys
9+
910
from cwltool import main
1011

1112
if __name__ == "__main__":

cwltool/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from . import main
21
import sys
32

3+
from . import main
4+
45
sys.exit(main.main())

cwltool/builder.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import copy
2-
from .utils import aslist
3-
from . import expression
2+
43
import avro
54
import schema_salad.validate as validate
65
from schema_salad.sourceline import SourceLine
76
from typing import Any, Callable, Text, Type, Union
7+
8+
from . import expression
89
from .errors import WorkflowException
10+
from .pathmapper import PathMapper, adjustFileObjs, normalizeFilesDirs
911
from .stdfsaccess import StdFsAccess
10-
from .pathmapper import PathMapper, adjustFileObjs, adjustDirObjs, normalizeFilesDirs
12+
from .utils import aslist
1113

1214
CONTENT_LIMIT = 64 * 1024
1315

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

21-
class Builder(object):
2223

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

42-
def bind_input(self, schema, datum, lead_pos=[], tail_pos=[]):
44+
def bind_input(self, schema, datum, lead_pos=None, tail_pos=None):
4345
# type: (Dict[Text, Any], Any, Union[int, List[int]], List[int]) -> List[Dict[Text, Any]]
46+
if tail_pos is None:
47+
tail_pos = []
48+
if lead_pos is None:
49+
lead_pos = []
4450
bindings = [] # type: List[Dict[Text,Text]]
4551
binding = None # type: Dict[Text,Any]
4652
if "inputBinding" in schema and isinstance(schema["inputBinding"], dict):
@@ -137,7 +143,6 @@ def _capture_files(f):
137143
if schema["type"] == "Directory":
138144
self.files.append(datum)
139145

140-
141146
# Position to front of the sort key
142147
if binding:
143148
for bi in bindings:
@@ -198,7 +203,7 @@ def do_eval(self, ex, context=None, pull_image=True, recursive=False):
198203
# type: (Union[Dict[Text, Text], Text], Any, bool, bool) -> Any
199204
if recursive:
200205
if isinstance(ex, dict):
201-
return {k: self.do_eval(v, context, pull_image, recursive) for k,v in ex.iteritems()}
206+
return {k: self.do_eval(v, context, pull_image, recursive) for k, v in ex.iteritems()}
202207
if isinstance(ex, list):
203208
return [self.do_eval(v, context, pull_image, recursive) for v in ex]
204209

cwltool/cwlrdf.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import json
21
import urlparse
3-
from .process import Process
4-
from schema_salad.ref_resolver import Loader, ContextType
2+
3+
from rdflib import Graph
54
from schema_salad.jsonld_context import makerdf
6-
from rdflib import Graph, plugin, URIRef
7-
from rdflib.serializer import Serializer
8-
from typing import Any, Dict, IO, Text, Union
5+
from schema_salad.ref_resolver import ContextType
6+
from typing import Any, Dict, IO, Text
7+
8+
from .process import Process
9+
910

1011
def gather(tool, ctx): # type: (Process, ContextType) -> Graph
1112
g = Graph()
@@ -16,14 +17,16 @@ def visitor(t):
1617
tool.visit(visitor)
1718
return g
1819

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

25+
2326
def lastpart(uri): # type: (Any) -> Text
2427
uri = Text(uri)
2528
if "/" in uri:
26-
return uri[uri.rindex("/")+1:]
29+
return uri[uri.rindex("/") + 1:]
2730
else:
2831
return uri
2932

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

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

164168
stdout.write("digraph {")
165169

166-
#g.namespace_manager.qname(predicate)
170+
# g.namespace_manager.qname(predicate)
167171

168172
if include_parameters:
169173
dot_with_parameters(g, stdout)

cwltool/docker.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import subprocess
21
import logging
3-
import sys
4-
import requests
52
import os
6-
from .errors import WorkflowException
73
import re
4+
import subprocess
5+
import sys
86
import tempfile
9-
from typing import Any, Text, Union
7+
8+
import requests
9+
from typing import Text
10+
11+
from .errors import WorkflowException
1012

1113
_logger = logging.getLogger("cwltool")
1214

15+
1316
def get_image(dockerRequirement, pull_image, dry_run=False):
1417
# type: (Dict[Text, Text], bool, bool) -> bool
1518
found = False
@@ -44,7 +47,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
4447
with open(os.path.join(dockerfile_dir, "Dockerfile"), "w") as df:
4548
df.write(dockerRequirement["dockerFile"])
4649
cmd = ["docker", "build", "--tag=%s" %
47-
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
50+
str(dockerRequirement["dockerImageId"]), dockerfile_dir]
4851
_logger.info(Text(cmd))
4952
if not dry_run:
5053
subprocess.check_call(cmd, stdout=sys.stderr)
@@ -62,7 +65,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
6265
_logger.info(u"Sending GET request to %s", dockerRequirement["dockerLoad"])
6366
req = requests.get(dockerRequirement["dockerLoad"], stream=True)
6467
n = 0
65-
for chunk in req.iter_content(1024*1024):
68+
for chunk in req.iter_content(1024 * 1024):
6669
n += len(chunk)
6770
_logger.info("\r%i bytes" % (n))
6871
loadproc.stdin.write(chunk)
@@ -73,7 +76,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
7376
found = True
7477
elif "dockerImport" in dockerRequirement:
7578
cmd = ["docker", "import", str(dockerRequirement["dockerImport"]),
76-
str(dockerRequirement["dockerImageId"])]
79+
str(dockerRequirement["dockerImageId"])]
7780
_logger.info(Text(cmd))
7881
if not dry_run:
7982
subprocess.check_call(cmd, stdout=sys.stderr)

cwltool/docker_uid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import subprocess
2-
from typing import Text, Union
2+
3+
from typing import Text
34

45

56
def docker_vm_uid(): # type: () -> int

0 commit comments

Comments
 (0)