Skip to content

Commit 90ae2af

Browse files
authored
Merge pull request #750 from common-workflow-language/dynresreq_sizes
Fill in sizes for files inside directories only if needed
2 parents 33c2358 + 8cf9fde commit 90ae2af

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

appveyor.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ environment:
2525
PYTHON_ARCH: "64"
2626

2727
install:
28-
- "%PYTHON%\\python.exe -m pip install -U wheel pytest pytest-xdist mock"
28+
- "%PYTHON%\\python.exe -m pip install -U wheel pytest mock"
29+
#- "%PYTHON%\\python.exe -m pip install -U wheel pytest pytest-xdist mock"
2930

3031
build_script:
3132
- "%PYTHON%\\python.exe -m pip install ."
3233

3334
test_script:
34-
- "%PYTHON%\\python.exe -m pytest --verbose -p no:cacheprovider --junit-xml=tests.xml -n2"
35+
- "%PYTHON%\\python.exe -m pytest --verbose -p no:cacheprovider --junit-xml=tests.xml"
36+
#- "%PYTHON%\\python.exe -m pytest --verbose -p no:cacheprovider --junit-xml=tests.xml -n2"
3537

3638
on_finish:
3739
- ps: |

cwltool/expression.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ def interpolate(scan, rootvars,
222222
parts.append(scan)
223223
return ''.join(parts)
224224

225+
def needs_parsing(snippet): # type: (Any) -> bool
226+
return isinstance(snippet, (str, Text)) \
227+
and ("$(" in snippet or "${" in snippet)
225228

226229
def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
227230
context=None, pull_image=True, timeout=None, force_docker_pull=False,
@@ -237,7 +240,8 @@ def do_eval(ex, jobinput, requirements, outdir, tmpdir, resources,
237240
u"self": context,
238241
u"runtime": runtime}
239242

240-
if isinstance(ex, (str, Text)) and ("$(" in ex or "${" in ex):
243+
if needs_parsing(ex):
244+
assert isinstance(ex, (str, Text))
241245
fullJS = False
242246
jslib = u""
243247
for r in reversed(requirements):

cwltool/main.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
get_container_from_software_requirements)
4343
from .stdfsaccess import StdFsAccess
4444
from .update import ALLUPDATES, UPDATES
45-
from .utils import onWindows, windows_default_container_id
45+
from .utils import onWindows, windows_default_container_id, add_sizes
4646

4747
_logger = logging.getLogger("cwltool")
4848

@@ -227,17 +227,7 @@ def pathToLoc(p):
227227
p["location"] = p["path"]
228228
del p["path"]
229229

230-
def addSizes(p):
231-
if 'location' in p:
232-
try:
233-
p["size"] = os.stat(p["location"][7:]).st_size # strip off file://
234-
except OSError:
235-
pass
236-
elif 'contents' in p:
237-
p["size"] = len(p['contents'])
238-
else:
239-
return # best effort
240-
230+
241231
ns = {} # type: Dict[Text, Union[Dict[Any, Any], Text, Iterable[Text]]]
242232
ns.update(t.metadata.get("$namespaces", {}))
243233
ld = Loader(ns)
@@ -247,7 +237,7 @@ def expand_formats(p):
247237
p["format"] = ld.expand_url(p["format"], "")
248238

249239
visit_class(job_order_object, ("File", "Directory"), pathToLoc)
250-
visit_class(job_order_object, ("File",), addSizes)
240+
visit_class(job_order_object, ("File",), add_sizes)
251241
visit_class(job_order_object, ("File",), expand_formats)
252242
adjustDirObjs(job_order_object, trim_listing)
253243
normalizeFilesDirs(job_order_object)

cwltool/process.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from six.moves import urllib
3232
from six import iteritems, itervalues, string_types
3333

34+
from . import expression
3435
from .validate_js import validate_js_expressions
3536
from .utils import cmp_like_py2
3637
from .builder import Builder
@@ -40,7 +41,8 @@
4041
ensure_writable)
4142
from .secrets import SecretStore
4243
from .stdfsaccess import StdFsAccess
43-
from .utils import aslist, get_feature, copytree_with_merge, onWindows
44+
from .utils import (aslist, get_feature, copytree_with_merge, onWindows,
45+
add_sizes)
4446

4547

4648
class LogAsDebugFilter(logging.Filter):
@@ -415,6 +417,12 @@ def var_spool_cwl_detector(obj, # type: Union[Dict, List, Text]
415417
r = var_spool_cwl_detector(value, obj, key) or r
416418
return r
417419

420+
def eval_resource(builder, resource_req): # type: (Builder, Text) -> Any
421+
if expression.needs_parsing(resource_req):
422+
visit_class(builder.job, ("File",), add_sizes)
423+
return builder.do_eval(resource_req)
424+
return resource_req
425+
418426

419427
class Process(six.with_metaclass(abc.ABCMeta, object)):
420428
def __init__(self, toolpath_object, **kwargs):
@@ -698,9 +706,9 @@ def evalResources(self, builder, kwargs):
698706
mn = None
699707
mx = None
700708
if resourceReq.get(a + "Min"):
701-
mn = builder.do_eval(resourceReq[a + "Min"])
709+
mn = eval_resource(builder, resourceReq[a + "Min"])
702710
if resourceReq.get(a + "Max"):
703-
mx = builder.do_eval(resourceReq[a + "Max"])
711+
mx = eval_resource(builder, resourceReq[a + "Max"])
704712
if mn is None:
705713
mn = mx
706714
elif mx is None:

cwltool/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,15 @@ def bytes2str_in_dicts(a):
185185

186186
# simply return elements itself
187187
return a
188+
189+
def add_sizes(obj): # type: (Dict[Text, Any]) -> None
190+
if 'location' in obj:
191+
try:
192+
obj["size"] = os.stat(obj["location"][7:]).st_size # strip off file://
193+
except OSError:
194+
pass
195+
elif 'contents' in obj:
196+
obj["size"] = len(obj['contents'])
197+
else:
198+
return # best effort
199+

0 commit comments

Comments
 (0)