Beispiel #1
0
def DEFINE_multi_float(name,
                       default,
                       help=None,
                       lower_bound=None,
                       upper_bound=None,
                       flag_values=_flagvalues.FLAGS,
                       **args):
    """Registers a flag whose value can be a list of arbitrary floats.

    Use the flag on the command line multiple times to place multiple
    float values into the list.  The 'default' may be a single float
    (which will be converted into a single-element list) or a list of
    floats.

    Args:
      name: str, the flag name.
      default: Union[Iterable[float], Text, None], the default value of the flag;
          see `DEFINE_multi`.
      help: str, the help message.
      lower_bound: float, min values of the flag.
      upper_bound: float, max values of the flag.
      flag_values: FlagValues, the FlagValues instance with which the flag will
          be registered. This should almost never need to be overridden.
      **args: Dictionary with extra keyword args that are passed to the
          Flag __init__.
    """
    parser = _argument_parser.FloatParser(lower_bound, upper_bound)
    serializer = _argument_parser.ArgumentSerializer()
    DEFINE_multi(parser, serializer, name, default, help, flag_values, **args)
Beispiel #2
0
def DEFINE_float(name,
                 default,
                 help=None,
                 lower_bound=None,
                 upper_bound=None,
                 flag_values=_flagvalues.FLAGS,
                 **args):  # pylint: disable=invalid-name
    """Registers a flag whose value must be a float.

    If lower_bound or upper_bound are set, then this flag must be
    within the given range.

    Args:
      name: str, the flag name.
      default: float|str|None, the default value of the flag.
      help: str, the help message.
      lower_bound: float, min value of the flag.
      upper_bound: float, max value of the flag.
      flag_values: FlagValues, the FlagValues instance with which the flag will
          be registered. This should almost never need to be overridden.
      **args: dict, the extra keyword args that are passed to DEFINE.
    """
    parser = _argument_parser.FloatParser(lower_bound, upper_bound)
    serializer = _argument_parser.ArgumentSerializer()
    DEFINE(parser, name, default, help, flag_values, serializer, **args)
    _register_bounds_validator_if_needed(parser, name, flag_values=flag_values)
def DEFINE_float(  # pylint: disable=invalid-name,redefined-builtin
        name,
        default,
        help,
        lower_bound=None,
        upper_bound=None,
        flag_values=_flagvalues.FLAGS,
        required=False,
        **args):
    """Registers a flag whose value must be a float.

  If lower_bound or upper_bound are set, then this flag must be
  within the given range.

  Args:
    name: str, the flag name.
    default: float|str|None, the default value of the flag.
    help: str, the help message.
    lower_bound: float, min value of the flag.
    upper_bound: float, max value of the flag.
    flag_values: FlagValues, the FlagValues instance with which the flag will be
      registered. This should almost never need to be overridden.
    required: bool, is this a required flag. This must be used as a keyword
      argument.
    **args: dict, the extra keyword args that are passed to DEFINE.

  Returns:
    a handle to defined flag.
  """
    parser = _argument_parser.FloatParser(lower_bound, upper_bound)
    serializer = _argument_parser.ArgumentSerializer()
    result = DEFINE(parser,
                    name,
                    default,
                    help,
                    flag_values,
                    serializer,
                    required=required,
                    **args)
    _register_bounds_validator_if_needed(parser, name, flag_values=flag_values)
    return result
Beispiel #4
0
 def setUp(self):
     self.parser = _argument_parser.FloatParser()
Beispiel #5
0
 def test_instance_cache(self):
     parser1 = _argument_parser.FloatParser()
     parser2 = _argument_parser.FloatParser()
     self.assertIs(parser1, parser2)