Package: argparse2tool
This project aims to provide a drop-in replacement for argparse which allows
generating Galaxy XML and CWL Tools.It is quite literally a drop-in replacement. You (or the upstream tool
author) can use argparse completely as normalimportargparseWhen this package is installed and PYTHONPATH=$(argparse2tool) is set the
dropin replacement of argparse is used ahead of the
system argparse,argparse2toolwill capture all argparse function
calls, and process them specially.This information captured in this process is used to produceGalaxy
Tool XMLwhen it’s requested
with the--generate_galaxy_xmlflag, orCWL
Toolswhen
requested with the--generate_cwl_toolflag.For ourexample python scriptyou can see
the generatedGalaxy XMLandCWL
Tools.RunningTo generate XML or CWL, run your tool with the appropriate command line
flag$PYTHONPATH=$(argparse2tool)<toolcommand>--generate_galaxy_xml<otheroptions>>tool.xml$PYTHONPATH=$(argparse2tool)<toolcommand>--generate_cwl_tool<otheroptions>>tool.cwlThe project includes a sampleexample.pyfile which uses as many
argparse features as possible. CWL and Galaxy XML support different
portions feature sets which will be visible in the generated outputs.$PYTHONPATH=$(argparse2tool)pythonexample.py--generate_galaxy_xml$PYTHONPATH=$(argparse2tool)pythonexample.py--generate_cwl_toolCWL Specific FunctionalityExample forCNVkittoolkit$cnvkit.pybatch--generate_cwl_tool-d~/cnvkit-tools/--generate_outputsIf there are subcommands in the provided command, all possible tools
will be generated, for instance, for CNVkit$cnvkit.py--generate_cwl_toolwill produce CWL tool descriptions forcnvkit.py batch,cnvkit.py access,cnvkit.py export bed,cnvkit.py export cdtand all other subcommands.Other options (which work only with--generate_cwl_toolprovided,
except for help message) are:-oFILENAME,--output_sectionFILENAME: File with manually
filled output section which is put to a formed CWL tool.argparse2toolis not very good at generating outputs, it
recognizes output files only if they have typeargparse.FileType('w'), so output section is often blank and
should be filled manually.-go,--generate_outputs: flag for generating outputs not only
from arguments that are instances ofargparse.FileType('w'), but
also from every argument which containsoutputkeyword in its
name. For instance, argument--output-filewith no type will also
be placed to output section. However, ‘–output-directory’ argument
will also be treated like File, so generated tools must be checked
carefully if when this option is selected.-b,basecommand: command which appears inbasecommandfield in a resulting tool. It is handy to use this option when you
run tool with shebang, but wantpythonto be inbasecommandfield and the file amidst arguments. Example:$ .search.py--generate_cwl_tool-bpython.Basecommand of the formed tool will be['python'], andsearchwill be a positional argument on position 0.-d,--directory: directory for storing tool descriptions.--help_arg2cwl: prints this help message.How it worksInternally,argparse2tool, masquerading asargparseattempts to
find and import therealargparse. It then stores a reference to the
code module for the system argparse, and presents the user with all of
the functions that stdlib’s argparse provides. Every function call is
passed through the system argparse. However, argparse2tool captures the
details of those calls and when Tool XML or CWL is requested, it builds
up the tool definition and prints it out to standard output.ExamplesYou can see theexample.pyfile for an example with numerous types
of arguments and options that you might see in real tools. Accordingly
there is anexample.xmlfile with the output.It doesn’t work!!If you are not able to use the--generate_galaxy_xml/--generate_cwl_toolflags after
installing, it is probably because of module load order.argparse2toolmust precedeargparsein the path.To easily correct this, run the toolargparse2toolwhich
is installed as part of this package. Correctly functioning paths will
produce the following:$argparse2toolPATH_TO_THE_DROPINSwhile incorrectly ordered paths will produce a helpful error message:$argparse2toolno dropins dir...This is intended to be used inline:user@host:$ PYTHONPATH=$(argparse2tool)pythonmy_script.py--generate_galaxy_xmlLimitationsThis code doesn’t cover the entirety of theargparseAPI yet, and
there are some bugs to work out on the XML generation side:argparsegroups not supported (in galaxy, everything should still work in
argparse)some features like templating of the version string (please submit
bugs)galaxyxmlbugs in conditionals/whens (probably)argparse2tool Galaxy XML Outputsupport declaring output files in anargparse-esque mannerargparse2tool CWL OutputSome of argparse features can not be ported to CWL.nargs=N. Number of arguments can not be specified in CWL
(yet).constargument ofadd_argument(). All constants must be
specified in job files.Custom types and custom actions are not supported.Argument groups don’t work in CWL as arguments are sorted with
aspecial
algorithmMutual exclusion is not supported.LicenseApache License, v2