[ARVADOS] created: 53deed9cb00b94a69a3be1f959cbfda342646718

Git user git at public.curoverse.com
Wed May 18 16:40:57 EDT 2016


        at  53deed9cb00b94a69a3be1f959cbfda342646718 (commit)


commit 53deed9cb00b94a69a3be1f959cbfda342646718
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Wed May 18 16:40:48 2016 -0400

    8653: Update cwl-runner to match changes in sdk/arvados-cwl-runner

diff --git a/crunch_scripts/cwl-runner b/crunch_scripts/cwl-runner
index 7c73493..e011177 100755
--- a/crunch_scripts/cwl-runner
+++ b/crunch_scripts/cwl-runner
@@ -32,6 +32,8 @@ try:
     def keeppath(v):
         if arvados.util.keep_locator_pattern.match(v):
             return "file://%s/%s" % (os.environ['TASK_KEEPMOUNT'], v)
+        else:
+            return v
 
     job_order_object["cwl:tool"] = keeppath(job_order_object["cwl:tool"])
 
@@ -55,7 +57,8 @@ try:
     args.debug = True
     args.quiet = False
     args.ignore_docker_for_reuse = False
-    outputObj = runner.arvExecutor(t, job_order_object, "", args, cwl_runner_job={"uuid": arvados.current_job()["uuid"], "state": arvados.current_job()["state"]})
+    args.cwl_runner_job={"uuid": arvados.current_job()["uuid"], "state": arvados.current_job()["state"]}
+    outputObj = runner.arvExecutor(t, job_order_object, **vars(args))
 
     files = {}
     def capture(path):

commit c8d9a898cde654b53200bda0b0ef8b406dd71739
Author: Peter Amstutz <peter.amstutz at curoverse.com>
Date:   Wed May 18 16:33:57 2016 -0400

    8653: cwl-runner crunch script rewrites keep file paths into CWL File objects.
    Clean up argument handling in arvados-cwl-runner so that --create-template
    doesn't require a job object, and that --help doesn't present options that are
    irrelevant or don't work.

diff --git a/crunch_scripts/cwl-runner b/crunch_scripts/cwl-runner
index 8a4de24..7c73493 100755
--- a/crunch_scripts/cwl-runner
+++ b/crunch_scripts/cwl-runner
@@ -35,6 +35,13 @@ try:
 
     job_order_object["cwl:tool"] = keeppath(job_order_object["cwl:tool"])
 
+    for k,v in job_order_object.items():
+        if arvados.util.keep_locator_pattern.match(v):
+            job_order_object[k] = {
+                "class": "File",
+                "path": keeppath(v)
+            }
+
     adjustFiles(job_order_object, keeppath)
 
     runner = arvados_cwl.ArvCwlRunner(api_client=arvados.api('v1', model=OrderedJsonModel()))
diff --git a/sdk/cwl/arvados_cwl/__init__.py b/sdk/cwl/arvados_cwl/__init__.py
index 8341624..61fa07e 100644
--- a/sdk/cwl/arvados_cwl/__init__.py
+++ b/sdk/cwl/arvados_cwl/__init__.py
@@ -11,13 +11,12 @@ import arvados.events
 import arvados.util
 import copy
 import cwltool.docker
-import cwltool.draft2tool
+from cwltool.draft2tool import revmap_file, remove_hostfs, CommandLineTool
 from cwltool.errors import WorkflowException
 import cwltool.main
-from cwltool.process import shortname
 import cwltool.workflow
 import fnmatch
-import functools
+from functools import partial
 import json
 import logging
 import os
@@ -25,8 +24,10 @@ import pkg_resources  # part of setuptools
 import re
 import sys
 import threading
+from schema_salad.ref_resolver import Loader
+from cwltool.builder import Builder
 
-from cwltool.process import get_feature, adjustFiles, scandeps
+from cwltool.process import shortname, get_feature, adjustFiles, adjustFileObjs, scandeps
 from arvados.api import OrderedJsonModel
 
 logger = logging.getLogger('arvados.cwl-runner')
@@ -315,7 +316,7 @@ class RunnerJob(object):
         pass
 
     def upload_docker(self, tool):
-        if isinstance(tool, cwltool.draft2tool.CommandLineTool):
+        if isinstance(tool, CommandLineTool):
             (docker_req, docker_is_req) = get_feature(tool, "DockerRequirement")
             if docker_req:
                 arv_docker_get_image(self.arvrunner.api, docker_req, True, self.arvrunner.project_uuid)
@@ -342,7 +343,7 @@ class RunnerJob(object):
             files.add(path)
             return path
 
-        document_loader, _, _ = cwltool.process.get_schema()
+        document_loader = Loader({"cwl": "https://w3id.org/cwl/cwl#", "id": "@id"})
         def loadref(b, u):
             return document_loader.resolve_ref(u, base_url=b)[0]
 
@@ -350,8 +351,8 @@ class RunnerJob(object):
                       set(("$import", "run")),
                       set(("$include", "$schemas", "path")),
                       loadref)
-        adjustFiles(sc, functools.partial(visitFiles, workflowfiles))
-        adjustFiles(self.job_order, functools.partial(visitFiles, jobfiles))
+        adjustFiles(sc, partial(visitFiles, workflowfiles))
+        adjustFiles(self.job_order, partial(visitFiles, jobfiles))
 
         workflowmapper = ArvPathMapper(self.arvrunner, workflowfiles, "",
                                        "%s",
@@ -410,6 +411,10 @@ class RunnerJob(object):
                 outc = arvados.collection.Collection(record["output"])
                 with outc.open("cwl.output.json") as f:
                     outputs = json.load(f)
+                def keepify(path):
+                    if not path.startswith("keep:"):
+                        return "keep:%s/%s" % (record["output"], path)
+                adjustFiles(outputs, keepify)
             except Exception as e:
                 logger.error("While getting final output object: %s", e)
             self.arvrunner.output_callback(outputs, processStatus)
@@ -504,7 +509,7 @@ class RunnerTemplate(object):
             },
             "name": self.job.name,
             "owner_uuid": self.runner.project_uuid,
-        }).execute(num_retries=self.runner.num_retries)
+        }, ensure_unique_name=True).execute(num_retries=self.runner.num_retries)
         self.uuid = response["uuid"]
         logger.info("Created template %s", self.uuid)
 
@@ -512,7 +517,7 @@ class RunnerTemplate(object):
 class ArvPathMapper(cwltool.pathmapper.PathMapper):
     """Convert container-local paths to and from Keep collection ids."""
 
-    def __init__(self, arvrunner, referenced_files, basedir,
+    def __init__(self, arvrunner, referenced_files, input_basedir,
                  collection_pattern, file_pattern, name=None, **kwargs):
         self._pathmap = arvrunner.get_uploaded()
         uploadfiles = set()
@@ -525,7 +530,7 @@ class ArvPathMapper(cwltool.pathmapper.PathMapper):
             if "#" in src:
                 src = src[:src.index("#")]
             if src not in self._pathmap:
-                ab = cwltool.pathmapper.abspath(src, basedir)
+                ab = cwltool.pathmapper.abspath(src, input_basedir)
                 st = arvados.commands.run.statfile("", ab, fnPattern=file_pattern)
                 if kwargs.get("conformance_test"):
                     self._pathmap[src] = (src, ab)
@@ -560,7 +565,7 @@ class ArvPathMapper(cwltool.pathmapper.PathMapper):
             return super(ArvPathMapper, self).reversemap(target)
 
 
-class ArvadosCommandTool(cwltool.draft2tool.CommandLineTool):
+class ArvadosCommandTool(CommandLineTool):
     """Wrap cwltool CommandLineTool to override selected methods."""
 
     def __init__(self, arvrunner, toolpath_object, **kwargs):
@@ -637,45 +642,45 @@ class ArvCwlRunner(object):
     def add_uploaded(self, src, pair):
         self.uploaded[src] = pair
 
-    def arvExecutor(self, tool, job_order, input_basedir, args, **kwargs):
-        self.debug = args.debug
+    def arvExecutor(self, tool, job_order, **kwargs):
+        self.debug = kwargs.get("debug")
 
-        if args.quiet:
+        if kwargs.get("quiet"):
             logger.setLevel(logging.WARN)
             logging.getLogger('arvados.arv-run').setLevel(logging.WARN)
 
         useruuid = self.api.users().current().execute()["uuid"]
-        self.project_uuid = args.project_uuid if args.project_uuid else useruuid
+        self.project_uuid = kwargs.get("project_uuid") if kwargs.get("project_uuid") else useruuid
         self.pipeline = None
 
-        if args.create_template:
-            tmpl = RunnerTemplate(self, tool, job_order, args.enable_reuse)
+        if kwargs.get("create_template"):
+            tmpl = RunnerTemplate(self, tool, job_order, kwargs.get("enable_reuse"))
             tmpl.save()
             # cwltool.main will write our return value to stdout.
             return tmpl.uuid
 
-        if args.submit:
-            runnerjob = RunnerJob(self, tool, job_order, args.enable_reuse)
-            if not args.wait:
+        if kwargs.get("submit"):
+            runnerjob = RunnerJob(self, tool, job_order, kwargs.get("enable_reuse"))
+            if not kwargs.get("wait"):
                 runnerjob.run()
                 return runnerjob.uuid
 
         events = arvados.events.subscribe(arvados.api('v1'), [["object_uuid", "is_a", "arvados#job"]], self.on_message)
 
-        self.debug = args.debug
-        self.ignore_docker_for_reuse = args.ignore_docker_for_reuse
-        self.fs_access = CollectionFsAccess(input_basedir)
+        self.debug = kwargs.get("debug")
+        self.ignore_docker_for_reuse = kwargs.get("ignore_docker_for_reuse")
+        self.fs_access = CollectionFsAccess(kwargs["basedir"])
 
         kwargs["fs_access"] = self.fs_access
-        kwargs["enable_reuse"] = args.enable_reuse
+        kwargs["enable_reuse"] = kwargs.get("enable_reuse")
 
         kwargs["outdir"] = "$(task.outdir)"
         kwargs["tmpdir"] = "$(task.tmpdir)"
 
         if kwargs.get("conformance_test"):
-            return cwltool.main.single_job_executor(tool, job_order, input_basedir, args, **kwargs)
+            return cwltool.main.single_job_executor(tool, job_order, **kwargs)
         else:
-            if args.submit:
+            if kwargs.get("submit"):
                 jobiter = iter((runnerjob,))
             else:
                 components = {}
@@ -692,7 +697,6 @@ class ArvCwlRunner(object):
                 logger.info("Pipeline instance %s", self.pipeline["uuid"])
 
                 jobiter = tool.job(job_order,
-                                   input_basedir,
                                    self.output_callback,
                                    docker_outdir="$(task.outdir)",
                                    **kwargs)
@@ -717,11 +721,6 @@ class ArvCwlRunner(object):
                     self.cond.wait(1)
 
                 events.close()
-
-                if self.final_output is None:
-                    raise cwltool.workflow.WorkflowException("Workflow did not return a result.")
-
-                # create final output collection
             except:
                 if sys.exc_info()[0] is KeyboardInterrupt:
                     logger.error("Interrupted, marking pipeline as failed")
@@ -733,6 +732,9 @@ class ArvCwlRunner(object):
             finally:
                 self.cond.release()
 
+            if self.final_output is None:
+                raise cwltool.workflow.WorkflowException("Workflow did not return a result.")
+
             return self.final_output
 
 def versionstring():
@@ -746,9 +748,25 @@ def versionstring():
                                     "arvados-python-client", arvpkg[0].version,
                                     "cwltool", cwlpkg[0].version)
 
-def main(args, stdout, stderr, api_client=None):
-    args.insert(0, "--leave-outputs")
-    parser = cwltool.main.arg_parser()
+def arg_parser():  # type: () -> argparse.ArgumentParser
+    parser = argparse.ArgumentParser(description='Arvados executor for Common Workflow Language')
+
+    parser.add_argument("--conformance-test", action="store_true")
+    parser.add_argument("--basedir", type=str)
+    parser.add_argument("--outdir", type=str, default=os.path.abspath('.'),
+                        help="Output directory, default current directory")
+
+    parser.add_argument("--eval-timeout",
+                        help="Time to wait for a Javascript expression to evaluate before giving an error.",
+                        type=float)
+    parser.add_argument("--version", action="store_true", help="Print version and exit")
+
+    exgroup = parser.add_mutually_exclusive_group()
+    exgroup.add_argument("--verbose", action="store_true", help="Default logging")
+    exgroup.add_argument("--quiet", action="store_true", help="Only print warnings and errors.")
+    exgroup.add_argument("--debug", action="store_true", help="Print even more logging")
+
+    parser.add_argument("--tool-help", action="store_true", help="Print command line help for tool")
 
     exgroup = parser.add_mutually_exclusive_group()
     exgroup.add_argument("--enable-reuse", action="store_true",
@@ -776,6 +794,19 @@ def main(args, stdout, stderr, api_client=None):
     exgroup.add_argument("--no-wait", action="store_false", help="Submit workflow runner job and exit.",
                         default=True, dest="wait")
 
+    parser.add_argument("workflow", type=str, nargs="?", default=None)
+    parser.add_argument("job_order", nargs=argparse.REMAINDER)
+
+    return parser
+
+def main(args, stdout, stderr, api_client=None):
+    parser = arg_parser()
+
+    job_order_object = None
+    arvargs = parser.parse_args(args)
+    if arvargs.create_template:
+        job_order_object = ({}, "")
+
     try:
         if api_client is None:
             api_client=arvados.api('v1', model=OrderedJsonModel())
@@ -784,10 +815,10 @@ def main(args, stdout, stderr, api_client=None):
         logger.error(e)
         return 1
 
-    return cwltool.main.main(args,
+    return cwltool.main.main(args=arvargs,
                              stdout=stdout,
                              stderr=stderr,
                              executor=runner.arvExecutor,
                              makeTool=runner.arvMakeTool,
-                             parser=parser,
-                             versionfunc=versionstring)
+                             versionfunc=versionstring,
+                             job_order_object=job_order_object)
diff --git a/sdk/cwl/setup.py b/sdk/cwl/setup.py
index c665a00..c069843 100644
--- a/sdk/cwl/setup.py
+++ b/sdk/cwl/setup.py
@@ -30,7 +30,7 @@ setup(name='arvados-cwl-runner',
           'bin/arvados-cwl-runner'
       ],
       install_requires=[
-          'cwltool==1.0.20160427142240',
+          'cwltool==1.0.20160518201549',
           'arvados-python-client>=0.1.20160322001610'
       ],
       test_suite='tests',

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list