diff --git a/src/sophios/cli.py b/src/sophios/cli.py index efea816b..bca6c548 100644 --- a/src/sophios/cli.py +++ b/src/sophios/cli.py @@ -7,24 +7,33 @@ __version__ = _version.get_versions()['version'] parser = argparse.ArgumentParser(prog='main', description='Convert a high-level yaml workflow file to CWL.') -parser.add_argument('--yaml', type=str, required=('--generate_schemas' not in sys.argv), + +parser.add_argument('--yaml', type=str, + required=(not ('--generate_config' in sys.argv or '--generate_schemas' in sys.argv)), help='Yaml workflow file') +group_gen = parser.add_mutually_exclusive_group() +group_gen.add_argument('--generate_schemas', default=False, action="store_true", + help='Generate schemas for the files in config.json (search_paths_wic and search_paths_cwl)') +group_gen.add_argument('--generate_config', default=False, action="store_true", + help='''Generate default config in wic/global_config.json + with default search_paths_wic and search_paths_cwl''') parser.add_argument('--inputs_file', type=str, required=False, default='', help='Additional inputs Yaml file') parser.add_argument('--config_file', type=str, required=False, default=str(Path().home()/'wic'/'global_config.json'), help='User provided (JSON) config file') -# version action exits the parser Ref : https://github.com/python/cpython/blob/1f515e8a109204f7399d85b7fd806135166422d9/Lib/argparse.py#L1167 +# version action exits the parser +# Ref : https://github.com/python/cpython/blob/1f515e8a109204f7399d85b7fd806135166422d9/Lib/argparse.py#L1167 parser.add_argument('--version', action='version', version=__version__, default='==SUPPRESS==', help='Current version of the Workflow Inference Compiler') -parser.add_argument('--generate_schemas', default=False, action="store_true", - help='Generate schemas for the files in config.json (search_paths_wic and search_paths_cwl)') parser.add_argument('--homedir', type=str, required=False, default=str(Path().home()), - help='The users home directory. This is necessary because CWL clears environment variables (e.g. HOME)') + help='''The users home directory. + This is necessary because CWL clears environment variables (e.g. HOME)''') parser.add_argument('--insert_steps_automatically', default=False, action="store_true", help='''Attempt to fix inference failures by speculatively inserting workflow steps from a curated whitelist.''') parser.add_argument('--no_provenance', default=False, action="store_true", - help='Do not use the --provenance feature of CWL. (You should only disable provenance if absolutely necessary.)') + help='''Do not use the --provenance feature of CWL. + (You should only disable provenance if absolutely necessary.)''') parser.add_argument('--copy_output_files', default=False, action="store_true", help='Copies output files from the cachedir to outdir/ (automatically enabled with --run_local)') parser.add_argument('--inline_cwl_runtag', default=False, action="store_true", diff --git a/src/sophios/input_output.py b/src/sophios/input_output.py index 7c486051..a29581f5 100644 --- a/src/sophios/input_output.py +++ b/src/sophios/input_output.py @@ -186,15 +186,15 @@ def move_adapters_and_examples(config: Json) -> None: Args: config (Json): Json containing search path information """ - # if the sophios installation is through pip package - pip_dir_name = 'sophios' - if str(Path(__file__).parent).endswith(pip_dir_name): - adapters_dir = Path(__file__).parent / 'cwl_adapters' - examples_dir = Path(__file__).parent / 'examples' # when using dev/git install - else: + paren_dir = 'src' + if str(Path(__file__).parent.parent).endswith(paren_dir): adapters_dir = Path(__file__).parent.parent.parent / 'cwl_adapters' examples_dir = Path(__file__).parent.parent.parent / 'docs' / 'tutorials' + # if the sophios installation is through pip package + else: + adapters_dir = Path(__file__).parent / 'cwl_adapters' + examples_dir = Path(__file__).parent / 'examples' extlist = ['*.png', '*.md', '*.rst', '*.pyc', '__pycache__', '*.json'] # the default search paths will be the first entry in the 'global' namespace diff --git a/src/sophios/main.py b/src/sophios/main.py index 9ab1251b..3c1d4b08 100644 --- a/src/sophios/main.py +++ b/src/sophios/main.py @@ -23,6 +23,15 @@ def main() -> None: # User may specify a different homedir default_config_file = Path(args.homedir)/'wic'/'global_config.json' + if args.generate_config: + if default_config_file.exists(): + print(f'Config already exists. To overwrite delete {default_config_file.parent} directory. Exiting') + else: + basic_config = io.get_basic_config() + io.write_config_to_disk(basic_config, default_config_file) + io.move_adapters_and_examples(basic_config) + print('Finished generating config. Exiting.') + sys.exit(0) global_config: Json = io.get_config(Path(args.config_file), default_config_file) tools_cwl = plugins.get_tools_cwl(global_config, diff --git a/src/sophios/plugins.py b/src/sophios/plugins.py index 8206aa63..91a33c46 100644 --- a/src/sophios/plugins.py +++ b/src/sophios/plugins.py @@ -189,6 +189,9 @@ def cwl_update_inline_runtag(cwl: Cwl, path: Path, relative_run_path: bool) -> C yml_path = Path(runtag_orig) # Assume absolute path in the runtag with open(yml_path, mode='r', encoding='utf-8') as f: runtag_raw = yaml.safe_load(f.read()) + # local $namespace and $schema tag shouldn't be in inline cwl steps + runtag_raw.pop('$namespaces', None) + runtag_raw.pop('$schemas', None) step['run'] = runtag_raw else: pass # We only care if the runtag is a cwl filepath