Wrap your Python functions with a command line interface, so that they can be run directly from the command line, just like any shell command. This is achieved by simply adding a decorator in front of the function. The commandline interface is powered by the optparse module, and data can be loaded from and saved to HDF5 files, corresponding to the function arguments or return values.
Simple example:
>>> # file "my_module.py"
>>> from frog import Frog
>>> @Frog(inmap=dict(x='$@/dset'), preproc=dict(x=list_of(float)))
>>> def mean(x):
>>> return sum(x)/len(x)
Now, you can create a small executable script with the following content:
>>> import sys, my_module
>>> sys.exit(my_module._mean())
The way the frog is configured in this example, it expects you to specify a bunch of HDF5 data files, where each file has a dataset called dset, and the function will be called with the list [x1, x2, x3, ...] (its length corresponds to the number of files). By default, the result of the function goes to STDOUT (displayed on the screen). However, the behavior can be configured in various ways.
For further explanation, please refer to the manual (TO DO).
Implement the Frog decorator.
Instances of this class are callables which turn a given iterable into a list of items with the specified data type.
Instances of this class are callables which turn a given iterable into a tuple of items with the specified data type.
Instances of this class are callables which apply a list of functions to the given object.
Instances of this class are callables which get a certain item of each element of a given iterable, and returns all items in form of a new iterable. If item does not exist and a default value is given, return that value.
Instances of this class are callables which evaluate a certain expression for each element of a given iterable, and returns the results as in form of a new iterable. In the expression, “x” indicates the respective item.
List all frogs defined in a certain module. The module can be a string (module path) or the module object itself.
Create a small executable script that calls the specified frog wrapper. Expect either the function object of the frog wrapper itself, or a string containing the full module path to that frog wrapper.
The executable script is created in the directory “dir”. Default is the current working directory. The script will be named according to “name”, otherwise it will be based on the name of the function object of the frog wrapper.
An attempt to make the script executable is made, using “chmod +x”.
Check if the given function object possesses at least one frog wrapper.
Background: As soon as a frog decorator is applied to a function, it leaves a trace by adding an attribute called __frog__ to the function.
Convert all items of the iterable to strings and join them with space characters in between. Return the newly formed string.
Evaluate given expression only if string is given, otherwise, leave the given object unchanged.