Skip to content

Commit

Permalink
cli: accept workflow file location
Browse files Browse the repository at this point in the history
* If there is no workflow specification provided to the workflow
  engine, a new parameter can be passed. This is the relative
  path to the workflow file. This is needed for the case of running
  a workflow triggered by a Git provider, i.e. on commit to master,
  so we expect the analysis code to be present in the workflow
  workspace and, hence, we can load it (closes reanahub/reana#235).
  • Loading branch information
Diego Rodriguez authored and mvidalgarcia committed Jan 28, 2020
1 parent 8bc4414 commit d7b2703
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions reana_workflow_engine_yadage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os

import click
import yadageschemas
from reana_commons.config import (REANA_LOG_FORMAT, REANA_LOG_LEVEL,
REANA_WORKFLOW_UMASK)
from reana_commons.utils import check_connection_to_job_controller
Expand Down Expand Up @@ -45,13 +46,17 @@ def load_json(ctx, param, value):
@click.option('--workflow-json',
help='JSON representation of workflow object to be run.',
callback=load_json)
@click.option('--workflow-file',
help='Path to the workflow file. This field is used when'
' no workflow JSON has been passed.')
@click.option('--workflow-parameters',
help='JSON representation of workflow_parameters received by'
' the workflow.',
callback=load_json)
def run_yadage_workflow(workflow_uuid,
workflow_workspace,
workflow_json=None,
workflow_file=None,
workflow_parameters=None):
"""Run a ``yadage`` workflow."""
log.info('getting socket..')
Expand All @@ -73,6 +78,28 @@ def run_yadage_workflow(workflow_uuid,
# When `yadage` resolves the workflow file from a remote repository:
# i.e. github:reanahub/reana-demo-root6-roofit/workflow.yaml
workflow_kwargs = dict(workflow=workflow, toplevel=toplevel)
elif workflow_file:
workflow_file_abs_path = os.path.join(
workflow_workspace, workflow_file)
if os.path.exists(workflow_file_abs_path):
schema_name = 'yadage/workflow-schema'
schemadir = None

specopts = {
'toplevel': workflow_workspace,
'schema_name': schema_name,
'schemadir': schemadir,
'load_as_ref': False,
}

validopts = {
'schema_name': schema_name,
'schemadir': schemadir,
}
workflow_json = yadageschemas.load(
spec=workflow_file, specopts=specopts, validopts=validopts,
validate=True)
workflow_kwargs = dict(workflow_json=workflow_json)

dataopts = {'initdir': workflow_workspace}

Expand Down

0 comments on commit d7b2703

Please sign in to comment.