Skip to content

Commit

Permalink
Merge pull request #269 from sameeul/v014
Browse files Browse the repository at this point in the history
V014
  • Loading branch information
sameeul authored Aug 27, 2024
2 parents b77ecc4 + 734135c commit fc2ba9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
21 changes: 15 additions & 6 deletions src/sophios/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/sophios/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/sophios/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/sophios/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc2ba9f

Please sign in to comment.