Exemple #1
0
def cli(ctx, path, job_path, **kwds):
    """Planemo command for running tools and jobs.

    ::

        % planemo run cat1-tool.cwl cat-job.json
    """
    kwds["cwl"] = path.endswith(".cwl")
    conformance_test = kwds.get("conformance_test", False)

    with conditionally_captured_io(conformance_test):
        with engine_context(ctx, **kwds) as engine:
            run_result = engine.run(path, job_path)

    if not run_result.was_successful:
        warn("Run failed [%s]" % str(run_result))
        ctx.exit(1)

    if conformance_test:
        if hasattr(run_result, "cwl_command_state"):
            command_state = run_result.cwl_command_state
            dumped_json = json.dumps(command_state)
            if hasattr(run_result, "galaxy_paths"):
                for (local_path, galaxy_path) in run_result.galaxy_paths:
                    dumped_json = dumped_json.replace(galaxy_path, local_path)
            print(dumped_json)
    else:
        outputs_dict = run_result.outputs_dict
        print(outputs_dict)
        output_json = kwds.get("output_json", None)
        if output_json:
            with open(output_json, "w") as f:
                json.dump(outputs_dict, f)

    return 0
Exemple #2
0
def cli(ctx, path, job_path, **kwds):
    """Planemo command for running tools and jobs.

    ::

        % planemo run cat1-tool.cwl cat-job.json
    """
    kwds["cwl"] = path.endswith(".cwl")
    conformance_test = kwds.get("conformance_test", False)

    with conditionally_captured_io(conformance_test):
        with engine_context(ctx, **kwds) as engine:
            run_result = engine.run(path, job_path)

    if not run_result.was_successful:
        warn("Run failed [%s]" % str(run_result))
        ctx.exit(1)

    if conformance_test:
        if hasattr(run_result, "cwl_command_state"):
            command_state = run_result.cwl_command_state
            dumped_json = json.dumps(command_state)
            if hasattr(run_result, "galaxy_paths"):
                for (local_path, galaxy_path) in run_result.galaxy_paths:
                    dumped_json = dumped_json.replace(galaxy_path, local_path)
            print(dumped_json)
    else:
        outputs_dict = run_result.outputs_dict
        print(outputs_dict)
        output_json = kwds.get("output_json", None)
        if output_json:
            with open(output_json, "w") as f:
                json.dump(outputs_dict, f)

    return 0
Exemple #3
0
def test_io_capture():
    """Test :func:`planemo.io.conditionally_captured_io`."""
    with io.conditionally_captured_io(True, tee=False) as capture:
        io.warn("Problem...")
    assert_equal(capture[0]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.shell("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.communicate("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(False, tee=False) as capture:
        io.communicate("echo 'Test...'")

    assert capture is None
Exemple #4
0
def test_io_capture():
    """Test :func:`planemo.io.conditionally_captured_io`."""
    with io.conditionally_captured_io(True, tee=False) as capture:
        io.warn("Problem...")
    assert_equal(capture[0]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.shell("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.communicate("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(False, tee=False) as capture:
        io.communicate("echo 'Test...'")

    assert capture is None
Exemple #5
0
def run_galaxy(ctx, path, job_path, **kwds):
    kwds["cwl"] = True
    conformance_test = kwds.get("conformance_test", False)
    with conditionally_captured_io(conformance_test):
        with serve_daemon(ctx, [path], **kwds) as config:
            try:
                cwl_run = run_cwl_tool(path, job_path, config, **kwds)
            except Exception:
                io.warn("Problem running cwl tool...")
                print(config.log_contents)
                raise

    print(cwl_run.cwl_command_state)
    return 0