The module provides multiprocessing facilities for flink modules.
A simple wrapper around multiprocessing.Pool.
ncpu is the maximum number of workers that can run at the same time.
The pool is automatically bypassed if ncpu is 1.
Submit a new job to the pool.
func is the function that the worker will run, and kwargs is dictonary of keyword arguments for func.
Display formatted log messages.
Messages are actually printed or not depending on the value of the configuration property flink.config.logging_verbosity.
API to access/modify the value of configiration properties defined in the configuration file flink.config.
Return a dictionary of the configuration properties defined in flink.config.
Set the value of a configuration property.
The property must be already defined in the global configuration module.
In case of success, returns a tuple (old,new) with the old and the new value of the property.
Raises NoSuchProperty if the required property is not set, IncompatiblePropertyValue if the value provided does not match the type of the property to be overwritten.
Return the value of the configuration property name.
Raise NoSuchProperty if a configuration property of the given name does not exist.
Dict-like dense representation for vectors.
Dictionary entries are in the form int: float and are meant to represent components and their values. A missing key is regarded as a component whose value is 0.
initial is a dictionary that can be used to initialize the value of some components of the vector.
A simple wrapper around pickle for object persistency.
This module provides facilities for handling trees.
It allows to parse strings representing trees in parenthesized notation and to manipulate the resulting data structures.
A class to handle rooted ordered trees.
Each node in a tree is a tree itself.
label is the label of the node, and parent a reference to the parent node. If parent is None, then the node is the root of a tree.
Public fields:
A wrapper around optparse.OptionParser to easily build command line parsers.
The module provides a higher level interface for command line parsing, implementing mandatory options and making easier to create groups of command line options.
The user invokes the cliparse() function, passing as arguments a variable number of cliopt objects in the order in which they should appear in the help message.
On success (all the required arguments and options were present) the function returns the same (options, args) pair as optparse:OptionParser.
A set of high-level factory functions (str_option(), int_option(), float_option(), flag(), list_option(), config_properties_option()) are used to ease the creation of typed options.
A special class, group, is used to easily create option groups. All the options added after creating a group are automatically included in that group. When a new group is added, all subsequent options will be added to the last group.
As an example, the following instructions:
from flink.utils.cli import cliparse, int_option, \
float_option, group, str_option
options,args = cliparse(
group("First group"),
int_option("a", "option_a",
help = "This option requires an integer argument",
default = 1),
float_option("b", "option_b",
help = "This non-mandatory option requires a float argument",
mandatory = False),
group("Second group"),
str_option("c", "option_c",
help = "A mandatory string option for my parser"),
cli_num_args = 2, # there must be exactly 2 positional arguments
usage = "%prog [options] <1st required arg> <2nd required arg>")
would produce the following help message:
Usage: test.py [options] <1st required arg> <2nd required arg>
Options:
-h, --help show this help message and exit
First group:
-a OPTION_A, --option_a=OPTION_A
This option requires an integer argument [default:1]
-b OPTION_B, --option_b=OPTION_B
This non-mandatory option requires a float argument
Second group:
-c OPTION_C, --option_c=OPTION_C
A mandatory string option for my parser (*)
Options marked with (*) are mandatory.
See also
The command line parsers in flink.linearize.ksl and flink.linearize.binary for richer examples.
Parse command line arguments.
options is a variable number of positional arguments, each of them being either an instance of cliopt or an instance of group.
Every instance of cliopt is added to the last added group. This behavior makes extremely easy to design the command line in a visual way, as exemplified above.
After the sequence of command line options, the programmer can also specify the °cli_num_args* keyword argument to set the number of positional arguments that the user is supposed to provide when running the program.
cli_num_args can be either an integer or a string representing and integer value. In this case, the command line parser will require the user to provide exactly the given number of positional arguments when invoking the program.
If cli_num_args is a string in the form <num>+ (<num> being a valid integer number), then the parser will require the user to provide at least <num> positional arguments.
Finally, if cli_num_args is a string in the form <num>- (<num> being a valid integer number), then the parser will require the user to provide at most <num> positional arguments.
optparser_options is a dictionary of keyword arguments that are forwarded to the constructor of optparse.OptionParser.
If the arguments are successfully parsed (after applying all the checks for mandatory options and required arguments), the function returns the return value of optparse.OptionParser.parse_args(), i.e. a pair (options, args) in which options is an object with the values of command line options and args is the list of user provided positional arguments.
A wrapper class around optparse.Option to build command line options.
short is a one-character string to be used as short flag for the option.
Note
Unlike optparse.OptionParser, the trailing - must not be included!
dest is the name of the attribute where the option value will be stored to, and is also used for the long name of the command line flag.
If mandatory is True, then the user of the program will be required to provide a value for the option, unless a default is provided by the programmer (via option_args["default"]).
If group is not None, then the option is added to the group titled group.
option_args is a set of keyword arguments that will be forwarded to the constructor of optparse.Option.
Note
Users should not use cliopt directly, instead they should use one of the higher level facilities like str_option(), int_option(), depending on the kind of option they want to create.
Add an option to override the values of configuration properties.
See also
The arguments short and dest are the same as for cliopt.
Adding this option to the command line parser, allows the user of a program to override the values of one or more configuration properties by using a syntax like:
-D first_prop_name=value1 -D second_prop_name=value2
(assuming that D was used as short flag for the option).
When parsing the command line, the parser will also check the consistency of the user’s assignments, verifying that the required properties exist and that the values they are given are compatible with each property’s type.
Create an option for which users can specify multiple values, using a syntax like:
-x first_value -x second_value
assuming that short is set to x.
The arguments short and dest are the same as for cliopt.
Creating a command line option to store an integer parameter.
The arguments short and dest are the same as for cliopt.
Create a command line option to store a floating point parameter.
The arguments short and dest are the same as for cliopt.
Create a command line option to store a string valued parameter.
The arguments short and dest are the same as for cliopt.