def DEFINE_linspace(name, default, help_string, nonempty=False, increasing=False, flag_values=gflags.FLAGS, **kwargs): # pylint: disable=invalid-name """Defines a 'linspace' flag. The flag value should be specified as <lower>,<upper>,<count>. The components are used as arguments to numpy.linspace, so they must be parsable as float, float, and int, respectively. The parsed flag value will be a 1-dimensional numpy.ndarray. Args: name: Name of the flag. default: Default value (as unparsed string), or None if flag is unset by default. help_string: Helpful description of the flag. nonempty: Indicates whether the flag value is required to be nonempty. If True, None is still an allowable default. Use gflags.MarkFlagAsRequired to disallow None. increasing: Indicates whether the flag value should be an increasing array. This is only enforced if the parsed value has >=2 elements. flag_values: The gflags.FlagValues object in which to define the flag. **kwargs: See gflags.DEFINE. """ gflags.DEFINE(_LinspaceParser(), name, default, help_string, flag_values=flag_values, **kwargs) if nonempty: # numpy.array can't be implicitly converted to a boolean. # pylint: disable=g-explicit-length-test gflags.RegisterValidator(name, lambda v: len(v) > 0, '--%s must specify a nonempty range.' % name, flag_values=flag_values) if increasing: gflags.RegisterValidator(name, lambda v: len(v) < 2 or v[-1] > v[0], '--%s must specify an increasing range.', flag_values=flag_values)
intarg = int(arg) # Look up the name for this level (DEBUG, INFO, etc) if it exists try: level = logging._levelNames.get(intarg, intarg) except AttributeError: # This was renamed somewhere b/w 2.7 and 3.4 level = logging._levelToName.get(intarg, intarg) except ValueError: level = arg setLevel(level) return level flags.DEFINE( parser=VerbosityParser(), serializer=flags.ArgumentSerializer(), name="verbosity", default=logging.INFO, help="Logging verbosity", ) init(global_logger) # Define functions emulating C++ glog check-macros # https://htmlpreview.github.io/?https://github.com/google/glog/master/doc/glog.html#check def format_stacktrace(stack): """Print a stack trace that is easier to read. * Reduce paths to basename component * Truncates the part of the stack after the check failure