[ARVADOS] updated: b2ad7e34cf7c99768a06db2ef9f4c6ce62a49253

Git user git at public.curoverse.com
Mon Apr 25 16:56:48 EDT 2016


Summary of changes:
 sdk/cwl/arvados_cwl/__init__.py            |  91 ++++++++++++++-------
 sdk/cwl/tests/order/inputs_test_order.json |   8 +-
 sdk/cwl/tests/test_submit.py               | 126 ++++++++++++++---------------
 sdk/cwl/tests/wf/inputs_test.cwl           |   4 +
 4 files changed, 130 insertions(+), 99 deletions(-)

  discards  5771118026ed8906350f416ac1e482bf810978fa (commit)
  discards  82f2fc3b04aaa31a254e6f97da7bb2befb5cad83 (commit)
       via  b2ad7e34cf7c99768a06db2ef9f4c6ce62a49253 (commit)
       via  9f0c1ef69a99fd5f1497942e9fc73ee70bd91a91 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (5771118026ed8906350f416ac1e482bf810978fa)
            \
             N -- N -- N (b2ad7e34cf7c99768a06db2ef9f4c6ce62a49253)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b2ad7e34cf7c99768a06db2ef9f4c6ce62a49253
Author: Tom Clegg <tom at curoverse.com>
Date:   Mon Apr 25 16:47:50 2016 -0400

    8653: Translate pipeline parameter specs from CWL to Arvados.

diff --git a/sdk/cwl/arvados_cwl/__init__.py b/sdk/cwl/arvados_cwl/__init__.py
index d714a69..3f210f5 100644
--- a/sdk/cwl/arvados_cwl/__init__.py
+++ b/sdk/cwl/arvados_cwl/__init__.py
@@ -4,26 +4,27 @@
 
 import argparse
 import arvados
-import arvados.events
+import arvados.collection
 import arvados.commands.keepdocker
 import arvados.commands.run
-import arvados.collection
+import arvados.events
 import arvados.util
+import copy
+import cwltool.docker
 import cwltool.draft2tool
-import cwltool.workflow
+from cwltool.errors import WorkflowException
 import cwltool.main
 from cwltool.process import shortname
-from cwltool.errors import WorkflowException
-import threading
-import cwltool.docker
+import cwltool.workflow
 import fnmatch
-import logging
-import re
-import os
-import sys
 import functools
 import json
+import logging
+import os
 import pkg_resources  # part of setuptools
+import re
+import sys
+import threading
 
 from cwltool.process import get_feature, adjustFiles, scandeps
 from arvados.api import OrderedJsonModel
@@ -418,16 +419,81 @@ class RunnerJob(object):
 class RunnerTemplate(object):
     """An Arvados pipeline template that invokes a CWL workflow."""
 
+    type_to_dataclass = {
+        'boolean': 'boolean',
+        'File': 'File',
+        'float': 'number',
+        'int': 'number',
+        'string': 'text',
+    }
+
     def __init__(self, runner, tool, job_order, enable_reuse):
         self.runner = runner
+        self.tool = tool
         self.job = RunnerJob(
             runner=runner,
             tool=tool,
             job_order=job_order,
             enable_reuse=enable_reuse)
 
+    def pipeline_component_spec(self):
+        """Return a component that Workbench and a-r-p-i will understand.
+
+        Specifically, translate CWL input specs to Arvados pipeline
+        format, like {"dataclass":"File","value":"xyz"}.
+        """
+        spec = self.job.arvados_job_spec()
+        job_params = spec['script_parameters']
+        spec['script_parameters'] = {}
+
+        for param in self.tool.tool["inputs"]:
+            param = copy.deepcopy(param)
+
+            # Data type and "required" flag...
+            types = param['type']
+            if not isinstance(types, list):
+                types = [types]
+            param['required'] = "null" not in types
+            non_null_types = set(types) - set(["null"])
+            if len(non_null_types) == 1:
+                the_type = [c for c in non_null_types][0]
+                dataclass = self.type_to_dataclass.get(the_type)
+                if dataclass:
+                    param['dataclass'] = dataclass
+            # Note: If we didn't figure out a single appropriate
+            # dataclass, we just left that attribute out.  We leave
+            # the "type" attribute there in any case, which might help
+            # downstream.
+
+            # Title and description...
+            descr = param.get('description', '').rstrip('\n')
+            if descr:
+                if '\n' in descr:
+                    (param['title'],
+                     param['description']) = descr.split('\n', 1)
+                else:
+                    param['title'] = param['description']
+                    del param['description']
+
+            # Fill in the value from the current job order, if any.
+            param_id = param['id']
+            if '#' in param_id:
+                param_id = param_id.split('#', 1)[1]
+            value = job_params.get(param_id)
+            if value is None:
+                pass
+            elif not isinstance(value, dict):
+                param['value'] = value
+            elif param.get('dataclass') == 'File' and value.get('path'):
+                param['value'] = value['path']
+
+            del param['id']
+            spec['script_parameters'][param_id] = param
+        spec['script_parameters']['cwl:tool'] = job_params['cwl:tool']
+        return spec
+
     def save(self):
-        job_spec = self.job.arvados_job_spec()
+        job_spec = self.pipeline_component_spec()
         response = self.runner.api.pipeline_templates().create(body={
             "components": {
                 self.job.name: job_spec,
diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py
index 3a5c38f..021394c 100644
--- a/sdk/cwl/tests/test_submit.py
+++ b/sdk/cwl/tests/test_submit.py
@@ -141,7 +141,13 @@ class TestCreateTemplate(unittest.TestCase):
         stubs.api.pipeline_instances().create.refute_called()
         stubs.api.jobs().create.refute_called()
 
-        expect_component = stubs.expect_job_spec
+        expect_component = copy.deepcopy(stubs.expect_job_spec)
+        expect_component['script_parameters']['x'] = {
+            'dataclass': 'File',
+            'required': True,
+            'type': 'File',
+            'value': '99999999999999999999999999999992+99/blorp.txt',
+        }
         expect_template = {
             "components": {
                 "submit_wf.cwl": expect_component,
@@ -150,11 +156,57 @@ class TestCreateTemplate(unittest.TestCase):
             "owner_uuid": project_uuid,
         }
         stubs.api.pipeline_templates().create.assert_called_with(
-            body=expect_template)
+            body=JsonDiffMatcher(expect_template))
 
         self.assertEqual(capture_stdout.getvalue(),
                          json.dumps(stubs.expect_pipeline_template_uuid))
 
+
+class TestTemplateInputs(unittest.TestCase):
+    expect_template = {
+        "components": {
+            "inputs_test.cwl": {
+                'runtime_constraints': {
+                    'docker_image': 'arvados/jobs',
+                },
+                'script_parameters': {
+                    'cwl:tool':
+                    '99999999999999999999999999999991+99/'
+                    'wf/inputs_test.cwl',
+                    'optionalFloatInput': None,
+                    'fileInput': {
+                        'type': 'File',
+                        'dataclass': 'File',
+                        'required': True,
+                        'title': "It's a file; we expect to find some characters in it.",
+                        'description': 'If there were anything further to say, it would be said here,\nor here.'
+                    },
+                    'floatInput': {
+                        'type': 'float',
+                        'dataclass': 'number',
+                        'required': True,
+                        'title': 'Floats like a duck',
+                    },
+                    'optionalFloatInput': {
+                        'type': ['null', 'float'],
+                        'dataclass': 'number',
+                        'required': False,
+                    },
+                    'boolInput': {
+                        'type': 'boolean',
+                        'dataclass': 'boolean',
+                        'required': True,
+                        'title': 'True or false?',
+                    },
+                },
+                'repository': 'arvados',
+                'script_version': 'master',
+                'script': 'cwl-runner',
+            },
+        },
+        "name": "inputs_test.cwl",
+    }
+
     @stubs
     def test_inputs_empty(self, stubs):
         exited = arvados_cwl.main(
@@ -163,42 +215,9 @@ class TestCreateTemplate(unittest.TestCase):
             cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
         self.assertEqual(exited, 0)
 
-        expect_template = {
-            "owner_uuid": stubs.fake_user_uuid,
-            "components": {
-                "inputs_test.cwl": {
-                    'runtime_constraints': {
-                        'docker_image': 'arvados/jobs',
-                    },
-                    'script_parameters': {
-                        'cwl:tool':
-                        '99999999999999999999999999999991+99/'
-                        'wf/inputs_test.cwl',
-                        '#optionalFloatInput': None,
-                        '#fileInput': {
-                            'dataclass': 'File',
-                            'required': True,
-                        },
-                        '#floatInput': {
-                            'dataclass': 'number',
-                            'required': True,
-                        },
-                        '#optionalFloatInput': {
-                            'dataclass': 'number',
-                            'required': False,
-                        },
-                        '#boolInput': {
-                            'dataclass': 'Boolean',
-                            'required': True,
-                        },
-                    },
-                    'repository': 'arvados',
-                    'script_version': 'master',
-                    'script': 'cwl-runner',
-                },
-            },
-            "name": "inputs_test.cwl",
-        }
+        expect_template = copy.deepcopy(self.expect_template)
+        expect_template["owner_uuid"] = stubs.fake_user_uuid
+
         stubs.api.pipeline_templates().create.assert_called_with(
             body=JsonDiffMatcher(expect_template))
 
@@ -210,32 +229,15 @@ class TestCreateTemplate(unittest.TestCase):
             cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
         self.assertEqual(exited, 0)
 
-        expect_template = {
-            "owner_uuid": stubs.fake_user_uuid,
-            "components": {
-                "inputs_test.cwl": {
-                    'runtime_constraints': {
-                        'docker_image': 'arvados/jobs',
-                    },
-                    'script_parameters': {
-                        'cwl:tool':
-                        '99999999999999999999999999999991+99/'
-                        'wf/inputs_test.cwl',
-                        '#optionalFloatInput': None,
-                        '#fileInput': {
-                            'path':
-                            '99999999999999999999999999999992+99/blorp.txt',
-                            'class': 'File',
-                        },
-                        '#floatInput': 1.234,
-                        '#boolInput': True,
-                    },
-                    'repository': 'arvados',
-                    'script_version': 'master',
-                    'script': 'cwl-runner',
-                },
-            },
-            "name": "inputs_test.cwl",
-        }
+        self.expect_template["owner_uuid"] = stubs.fake_user_uuid
+
+        expect_template = copy.deepcopy(self.expect_template)
+        expect_template["owner_uuid"] = stubs.fake_user_uuid
+        params = expect_template[
+            "components"]["inputs_test.cwl"]["script_parameters"]
+        params["fileInput"]["value"] = '99999999999999999999999999999992+99/blorp.txt'
+        params["floatInput"]["value"] = 1.234
+        params["boolInput"]["value"] = True
+
         stubs.api.pipeline_templates().create.assert_called_with(
             body=JsonDiffMatcher(expect_template))
diff --git a/sdk/cwl/tests/wf/inputs_test.cwl b/sdk/cwl/tests/wf/inputs_test.cwl
index 03d924c..61cb1c4 100644
--- a/sdk/cwl/tests/wf/inputs_test.cwl
+++ b/sdk/cwl/tests/wf/inputs_test.cwl
@@ -7,10 +7,14 @@ inputs:
     type: File
     description: |
       It's a file; we expect to find some characters in it.
+      If there were anything further to say, it would be said here,
+      or here.
   - id: "#boolInput"
     type: boolean
+    description: True or false?
   - id: "#floatInput"
     type: float
+    description: Floats like a duck
   - id: "#optionalFloatInput"
     type: ["null", float]
 outputs: []

commit 9f0c1ef69a99fd5f1497942e9fc73ee70bd91a91
Author: Tom Clegg <tom at curoverse.com>
Date:   Sun Apr 24 16:06:37 2016 -0400

    8653: Add test cases for input types.

diff --git a/sdk/cwl/tests/matcher.py b/sdk/cwl/tests/matcher.py
new file mode 100644
index 0000000..d3c9316
--- /dev/null
+++ b/sdk/cwl/tests/matcher.py
@@ -0,0 +1,23 @@
+import difflib
+import json
+
+
+class JsonDiffMatcher(object):
+    """Raise AssertionError with a readable JSON diff when not __eq__().
+
+    Used with assert_called_with() so it's possible for a human to see
+    the differences between expected and actual call arguments that
+    include non-trivial data structures.
+    """
+    def __init__(self, expected):
+        self.expected = expected
+
+    def __eq__(self, actual):
+        expected_json = json.dumps(self.expected, sort_keys=True, indent=2)
+        actual_json = json.dumps(actual, sort_keys=True, indent=2)
+        if expected_json != actual_json:
+            raise AssertionError("".join(difflib.context_diff(
+                expected_json.splitlines(1),
+                actual_json.splitlines(1),
+                fromfile="Expected", tofile="Actual")))
+        return True
diff --git a/sdk/cwl/tests/order/empty_order.json b/sdk/cwl/tests/order/empty_order.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/sdk/cwl/tests/order/empty_order.json
@@ -0,0 +1 @@
+{}
diff --git a/sdk/cwl/tests/order/inputs_test_order.json b/sdk/cwl/tests/order/inputs_test_order.json
new file mode 100644
index 0000000..8830523
--- /dev/null
+++ b/sdk/cwl/tests/order/inputs_test_order.json
@@ -0,0 +1,9 @@
+{
+    "fileInput": {
+        "class": "File",
+        "path": "../input/blorp.txt"
+    },
+    "boolInput": true,
+    "floatInput": 1.234,
+    "optionalFloatInput": null
+}
diff --git a/sdk/cwl/tests/test_submit.py b/sdk/cwl/tests/test_submit.py
index 750eeae..3a5c38f 100644
--- a/sdk/cwl/tests/test_submit.py
+++ b/sdk/cwl/tests/test_submit.py
@@ -11,6 +11,8 @@ import mock
 import sys
 import unittest
 
+from .matcher import JsonDiffMatcher
+
 
 def stubs(func):
     @functools.wraps(func)
@@ -124,7 +126,7 @@ class TestSubmit(unittest.TestCase):
 
 class TestCreateTemplate(unittest.TestCase):
     @stubs
-    def test_create_pipeline_template(self, stubs):
+    def test_create(self, stubs):
         project_uuid = 'zzzzz-j7d0g-zzzzzzzzzzzzzzz'
 
         capture_stdout = cStringIO.StringIO()
@@ -152,3 +154,88 @@ class TestCreateTemplate(unittest.TestCase):
 
         self.assertEqual(capture_stdout.getvalue(),
                          json.dumps(stubs.expect_pipeline_template_uuid))
+
+    @stubs
+    def test_inputs_empty(self, stubs):
+        exited = arvados_cwl.main(
+            ["--create-template", "--no-wait",
+             "tests/wf/inputs_test.cwl", "tests/order/empty_order.json"],
+            cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
+        self.assertEqual(exited, 0)
+
+        expect_template = {
+            "owner_uuid": stubs.fake_user_uuid,
+            "components": {
+                "inputs_test.cwl": {
+                    'runtime_constraints': {
+                        'docker_image': 'arvados/jobs',
+                    },
+                    'script_parameters': {
+                        'cwl:tool':
+                        '99999999999999999999999999999991+99/'
+                        'wf/inputs_test.cwl',
+                        '#optionalFloatInput': None,
+                        '#fileInput': {
+                            'dataclass': 'File',
+                            'required': True,
+                        },
+                        '#floatInput': {
+                            'dataclass': 'number',
+                            'required': True,
+                        },
+                        '#optionalFloatInput': {
+                            'dataclass': 'number',
+                            'required': False,
+                        },
+                        '#boolInput': {
+                            'dataclass': 'Boolean',
+                            'required': True,
+                        },
+                    },
+                    'repository': 'arvados',
+                    'script_version': 'master',
+                    'script': 'cwl-runner',
+                },
+            },
+            "name": "inputs_test.cwl",
+        }
+        stubs.api.pipeline_templates().create.assert_called_with(
+            body=JsonDiffMatcher(expect_template))
+
+    @stubs
+    def test_inputs(self, stubs):
+        exited = arvados_cwl.main(
+            ["--create-template", "--no-wait",
+             "tests/wf/inputs_test.cwl", "tests/order/inputs_test_order.json"],
+            cStringIO.StringIO(), sys.stderr, api_client=stubs.api)
+        self.assertEqual(exited, 0)
+
+        expect_template = {
+            "owner_uuid": stubs.fake_user_uuid,
+            "components": {
+                "inputs_test.cwl": {
+                    'runtime_constraints': {
+                        'docker_image': 'arvados/jobs',
+                    },
+                    'script_parameters': {
+                        'cwl:tool':
+                        '99999999999999999999999999999991+99/'
+                        'wf/inputs_test.cwl',
+                        '#optionalFloatInput': None,
+                        '#fileInput': {
+                            'path':
+                            '99999999999999999999999999999992+99/blorp.txt',
+                            'class': 'File',
+                        },
+                        '#floatInput': 1.234,
+                        '#boolInput': True,
+                    },
+                    'repository': 'arvados',
+                    'script_version': 'master',
+                    'script': 'cwl-runner',
+                },
+            },
+            "name": "inputs_test.cwl",
+        }
+        stubs.api.pipeline_templates().create.assert_called_with(
+            body=JsonDiffMatcher(expect_template))
diff --git a/sdk/cwl/tests/wf/inputs_test.cwl b/sdk/cwl/tests/wf/inputs_test.cwl
new file mode 100644
index 0000000..03d924c
--- /dev/null
+++ b/sdk/cwl/tests/wf/inputs_test.cwl
@@ -0,0 +1,22 @@
+# Test case for arvados-cwl-runner. Used to test propagation of
+# various input types as script_parameters in pipeline templates.
+
+class: Workflow
+inputs:
+  - id: "#fileInput"
+    type: File
+    description: |
+      It's a file; we expect to find some characters in it.
+  - id: "#boolInput"
+    type: boolean
+  - id: "#floatInput"
+    type: float
+  - id: "#optionalFloatInput"
+    type: ["null", float]
+outputs: []
+steps:
+  - id: step1
+    inputs:
+      - { id: x, source: "#x" }
+    outputs: []
+    run: ../tool/submit_tool.cwl

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list