Giter VIP home page Giter VIP logo

gxargparse's Introduction

gxargparse

Galaxy argparse aims to be a drop-in replacement for argparse, quite literally. You can write use your normal import

import argparse

and continue writing code. All functions are passed straight through to argparse, but gxargparse captures them and copies some information along the way. This information captured is used to produce Galaxy Tool XML when it's requested with the --generate_galaxy_xml flag.

How it works

Internally, gxargparse, masquerading as argparse attempts to find and import the real argparse. 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, gxargparse captures the details of those calls and when Tool XML is requested, it builds up the tool definition according to IUC tool standards.

Examples

You can see the example.py file for an example with numerous types of arguments and options that you might see in real tools. Accordingly there is an example.xml file with the output.

It doesn't work!!

If you are not able to use the --generate_galaxy_xml flag after installing, it is probably because of module load order. gxargparse must precede argparse in the path. Certain cases seem to work correctly (python setup.py install in a virtualenv) while other cases do not (pip install gxargparse).

To easily correct this, run the tool gxargparse_check_path which is installed as part of this package. Correctly functioning paths will produce the following:

$ gxargparse_check_path
Ready to go!

while incorrectly ordered paths will produce a helpful error message:

$ gxargparse_check_path
Incorrect ordering, please set

    PYTHONPATH=/home/users/esr/Projects/test/.venv/local/lib/python2.7/site-packages

This can even be used inline:

user@host:$ PYTHONPATH=$(gxargparse_check_path -q) python my_script.py --generate_galaxy_xml

TODO

This code doesn't cover the entirety of the argparse API yet, and there are some bugs to work out on the XML generation side:

  • argparse
    • groups not supported (in galaxy, everything should still work in argparse)
    • some features like templating of the version string (please submit bugs)
  • galaxyxml
    • bugs in conditionals/whens (probably)
    • bugs, bugs, bugs!
  • gxargparse
    • support help text
    • support declaring output files in an argparse-esque manner

License

  • Apache License, v2

gxargparse's People

Contributors

mr-c avatar hexylena avatar bgruening avatar

Watchers

James Cloos avatar Anton Khodak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.