def conformance_test(context, app, job_dict, basedir): job_dict['@type'] = 'Job' job_dict['@id'] = basedir job_dict['app'] = app if not app.outputs: app.outputs = rabix.schema.JsonSchema(context, { 'type': 'object', 'properties': {} }) inputs = rebase_paths(app, job_dict['inputs'], basedir) inputs = get_inputs(app, inputs) dot_update_dict(job_dict['inputs'], inputs) job = context.from_dict(job_dict) adapter = CLIJob(job) print(json.dumps({ 'args': adapter.make_arg_list(), 'stdin': adapter.stdin, 'stdout': adapter.stdout, }))
def conformance_test(context, app, job_dict, basedir): job_dict['class'] = 'Job' job_dict['id'] = basedir job_dict['app'] = app if not app.outputs: app.outputs = [] job_dict['inputs'] = get_inputs(job_dict, app.inputs, basedir) job = Job.from_dict(context, job_dict) adapter = CLIJob(job) result = { 'args': adapter.make_arg_list(), 'stdin': adapter.stdin, 'stdout': adapter.stdout, } cfr = app.get_requirement(CreateFileRequirement) e = ValueResolver(job) if cfr: result['createfiles'] = { name: content for name, content in cfr.resolve_file_defs(e) } print(json.dumps(result))
def conformance_test(context, app, job_dict, basedir): job_dict['class'] = 'Job' job_dict['id'] = basedir job_dict['app'] = app if not app.outputs: app.outputs = [] job_dict['inputs'] = get_inputs(job_dict, app.inputs, basedir) job = Job.from_dict(context, job_dict) adapter = CLIJob(job) print(json.dumps({ 'args': adapter.make_arg_list(), 'stdin': adapter.stdin, 'stdout': adapter.stdout, }))
def conformance_test(context, app, job_dict, basedir): job_dict['class'] = 'Job' job_dict['id'] = basedir job_dict['app'] = app if not app.outputs: app.outputs = [] job_dict['inputs'] = get_inputs(job_dict, app.inputs, basedir) job = Job.from_dict(context, job_dict) adapter = CLIJob(job) print( json.dumps({ 'args': adapter.make_arg_list(), 'stdin': adapter.stdin, 'stdout': adapter.stdout, }))
def conformance_test(context, app, job_dict, basedir): job_dict['@type'] = 'Job' job_dict['@id'] = basedir job_dict['app'] = app if not app.outputs: app.outputs = rabix.schema.JsonSchema(context, { 'type': 'object', 'properties': {} }) job_dict['inputs'] = get_inputs(app, job_dict['inputs'], basedir) job = context.from_dict(job_dict) adapter = CLIJob(job) print(json.dumps({ 'args': adapter.make_arg_list(), 'stdin': adapter.stdin, 'stdout': adapter.stdout, }))
def main(): logging.basicConfig(level=logging.WARN) if len(sys.argv) == 1: print(USAGE) return usage = USAGE.format(resources=make_resources_usage_string(), inputs='<inputs>') app_usage = usage if len(sys.argv) == 2 and \ (sys.argv[1] == '--help' or sys.argv[1] == '-h'): print(USAGE) return dry_run_args = dry_run_parse() if not dry_run_args: print(USAGE) return if not (dry_run_args['<tool>']): print('You have to specify a tool, with --tool option') print(usage) return tool = get_tool(dry_run_args) if not tool: print("Couldn't find tool.") return fix_types(tool, dry_run_args.get('--type', 'CommandLine')) context = init_context() app = context.from_dict(tool) job = None if isinstance(app, Job): job = app app = job.app if dry_run_args['--install']: app.install() print("Install successful.") return if dry_run_args['--conformance-test']: job_dict = from_url(dry_run_args['<job>']) conformance_test(context, app, job_dict, dry_run_args.get('--basedir')) return try: args = docopt.docopt(usage, version=version, help=False) job_dict = TEMPLATE_JOB logging.root.setLevel(log_level(dry_run_args['--verbose'])) if args['--inp-file']: basedir = os.path.dirname(args.get('--inp-file')) input_file = from_url(args.get('--inp-file')) rebased = rebase_paths(app, input_file, basedir) dot_update_dict( job_dict['inputs'], get_inputs(app, rebased) ) input_usage = job_dict['inputs'] if job: basedir = os.path.dirname(args.get('<tool>')) rebased = rebase_paths(app, job.inputs, basedir) dot_update_dict(job.inputs, rebased) job.inputs.update(get_inputs(app, job.inputs)) input_usage.update(job.inputs) app_inputs_usage = make_app_usage_string( app, template=TOOL_TEMPLATE, inp=input_usage) app_usage = make_app_usage_string(app, USAGE, job_dict['inputs']) try: app_inputs = docopt.docopt(app_inputs_usage, args['<inputs>']) except docopt.DocoptExit: if not job: raise for inp in job.app.inputs: if inp.required and inp.id not in job.inputs: raise app_inputs = {} if args['--help']: print(app_usage) return inp = get_inputs(app, app_inputs) if not job: job_dict['inputs'].update(inp) job_dict['@id'] = args.get('--dir') job_dict['app'] = app job = Job.from_dict(context, job_dict) else: job.inputs.update(inp) if args['--print-cli']: if not isinstance(app, CliApp): print(dry_run_args['<tool>'] + " is not a command line app") return print(CLIJob(job).cmd_line()) return if not job.inputs and not args['--']: print(app_usage) return try: context.executor.execute(job, lambda _, result: print(result)) except RabixError as err: print(err.message) sys.exit(1) except docopt.DocoptExit: print(app_usage) sys.exit(1)
def main(): disable_warnings() logging.basicConfig(level=logging.WARN) if len(sys.argv) == 1: print(USAGE) return usage = USAGE.format(resources=make_resources_usage_string(), inputs='<inputs>') app_usage = usage if len(sys.argv) == 2 and \ (sys.argv[1] == '--help' or sys.argv[1] == '-h'): print(USAGE) return dry_run_args = dry_run_parse() if not dry_run_args: print(USAGE) return if not (dry_run_args['<tool>']): print('You have to specify a tool, with --tool option') print(usage) return tool = get_tool(dry_run_args) if not tool: fail("Couldn't find tool.") if isinstance(tool, list): tool = loader.index.get('#main') if 'class' not in tool: fail("Document must have a 'class' field") if 'id' not in tool: tool['id'] = dry_run_args['<tool>'] context = init_context(tool) app = process_builder(context, tool) job = None if isinstance(app, Job): job = app app = job.app rabix.expressions.update_engines(app) if dry_run_args['--install']: app.install() print("Install successful.") return if dry_run_args['--conformance-test']: job_dict = from_url(dry_run_args['<job>']) conformance_test(context, app, job_dict, dry_run_args.get('--basedir')) return try: args = docopt.docopt(usage, version=version, help=False) job_dict = copy.deepcopy(TEMPLATE_JOB) logging.root.setLevel(log_level(dry_run_args['--verbose'])) input_file_path = args.get('<inp>') or args.get('--inp-file') if input_file_path: basedir = os.path.dirname(os.path.abspath(input_file_path)) input_file = from_url(input_file_path) inputs = get_inputs(input_file, app.inputs, basedir) job_dict['inputs'].update(inputs) input_usage = job_dict['inputs'] if job: basedir = os.path.dirname(args.get('<tool>')) job.inputs = get_inputs(job.inputs, app.inputs, basedir) input_usage.update(job.inputs) app_inputs_usage = make_app_usage_string(app, template=TOOL_TEMPLATE, inp=input_usage) app_usage = make_app_usage_string(app, USAGE, job_dict['inputs']) try: app_inputs = docopt.docopt(app_inputs_usage, args['<inputs>']) except docopt.DocoptExit: if not job: raise for inp in job.app.inputs: if inp.required and inp.id not in job.inputs: raise app_inputs = {} if args['--help']: print(app_usage) return # trim leading --, and ignore empty arays app_inputs = { k[2:]: v for k, v in six.iteritems(app_inputs) if v != [] } inp = get_inputs(app_inputs, app.inputs) if not job: job_dict['id'] = args.get('--outdir') or args.get('--dir') job_dict['app'] = app job = Job.from_dict(context, job_dict) job.inputs.update(inp) if args['--print-cli']: if not isinstance(app, CommandLineTool): fail(dry_run_args['<tool>'] + " is not a command line app") print(CLIJob(job).cmd_line()) return if args['--pretty-print']: fmt = partial(result_str, job.id) else: fmt = lambda result: json.dumps(context.to_primitive(result)) if not job.inputs and not args['--'] and not args['--quiet']: print(app_usage) return try: context.executor.execute(job, lambda _, result: print(fmt(result))) except RabixError as err: fail(err.message) except docopt.DocoptExit: fail(app_usage)