B @`Rn@s>dZddlmZddlmZddlmZddlZddlZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z ydd lmZmZmZWnek rYnXy ddlZWnek rYnXe jeejed dZe jddfddZe jdfddZe jdfddZe jfddZe jfddZddZ e jfddZ!e jdfddZ"dde jfdd Z#dde jfd!d"Z$e jdfd#d$Z%e jdd%fd&d'Z&e jfd(d)Z'd%e jfd*d+Z(e jdfd,d-Z)e jfd.d/Z*dde jfd0d1Z+dde jfd2d3Z,e jd4fd5d6Z-e jdd%fd7d8Z.e jdfd9d:Z/dS);zThis modules contains flags DEFINE functions. Do NOT import this module directly. Import the flags package and use the aliases defined at the package level instead. )absolute_import)division)print_functionN)_argument_parser) _exceptions)_flag) _flagvalues)_helpers) _validators)TextListAnycs4jdk sjdk r0fdd}tj|||ddS)zEnforces lower and upper bounds for numeric flags. Args: parser: NumericParser (either FloatParser or IntegerParser), provides lower and upper bounds, and help text to display. name: str, name of the flag flag_values: FlagValues. Ncs.|dk r*|r*d|jf}t|dS)Nz %s is not %sT)Zis_outside_boundsZsyntactic_helprZValidationError)valuemessage)parser7/tmp/pip-unpacked-wheel-01biqzia/absl/flags/_defines.pychecker<s z5_register_bounds_validator_if_needed..checker) flag_values) lower_bound upper_boundr Zregister_validator)rnamerrr)rr$_register_bounds_validator_if_needed1s  rcKsttj|||||f|||S)aRegisters a generic Flag object. NOTE: in the docstrings of all DEFINE* functions, "registers" is short for "creates a new flag and registers it". Auxiliary function: clients should use the specialized DEFINE_ function instead. Args: parser: ArgumentParser, used to parse the flag arguments. name: str, the flag name. default: The default value of the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. serializer: ArgumentSerializer, the flag serializer instance. module_name: str, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. **args: dict, the extra keyword args that are passed to Flag __init__. Returns: a handle to defined flag. ) DEFINE_flagrFlag)rrdefaulthelpr serializer module_nameargsrrrDEFINEEs r cCs^|}|||j<|r tj|}n t\}}||||t||t j |||j dk dS)aRegisters a 'Flag' object with a 'FlagValues' object. By default, the global FLAGS 'FlagValue' object is used. Typical users will use one of the more specialized DEFINE_xxx functions, such as DEFINE_string or DEFINE_integer. But developers who need to create Flag objects themselves should use this function to register their flags. Args: flag: Flag, a flag that is key to the module. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: str, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. Returns: a handle to defined flag. N)Zensure_non_none_value) rsysmodulesgetr Z"get_calling_module_object_and_nameZregister_flag_by_moduleZregister_flag_by_module_ididrZ FlagHolderr)flagrrZfvmodulerrrrjs   rcCs6|p|}t}x |D]}||}|||qWdS)aQDeclares a flag as key for the calling module. Internal function. User code should call declare_key_flag or adopt_module_key_flags instead. Args: flag_names: [str], a list of strings that are names of already-registered Flag objects. flag_values: FlagValues, the FlagValues instance with which the flags listed in flag_names have registered (the value of the flag_values argument from the DEFINE_* calls that defined those flags). This should almost never need to be overridden. key_flag_values: FlagValues, the FlagValues instance that (among possibly many other things) keeps track of the key flags for each module. Default None means "same as flag_values". This should almost never need to be overridden. Raises: UnrecognizedFlagError: Raised when the flag is not defined. N)r Zget_calling_moduleZregister_key_flag_for_module)Z flag_namesrkey_flag_valuesr& flag_namer%rrr_internal_declare_key_flagss  r)cCsX|tjkr t|gtj|ddSyt|g|dWn tk rRtd|YnXdS)a1Declares one flag as key to the current module. Key flags are flags that are deemed really important for a module. They are important when listing help messages; e.g., if the --helpshort command-line flag is used, then only the key flags of the main module are listed (instead of all flags, as in the case of --helpfull). Sample usage: flags.declare_key_flag('flag_1') Args: flag_name: str, the name of an already declared flag. (Redeclaring flags as key, including flags implicitly key because they were declared in this module, is a no-op.) flag_values: FlagValues, the FlagValues instance in which the flag will be declared as a key flag. This should almost never need to be overridden. Raises: ValueError: Raised if flag_name not defined as a Python flag. )rr'N)rzNFlag --%s is undefined. To set a flag as a key flag first define it in Python.)r SPECIAL_FLAGSr)KeyError ValueError)r(rrrrdeclare_key_flags r-cCsdt|tjstd|ftdd||jD|d|tj kr`tddtj Dtj |ddS)aDeclares that all flags key to a module are key to the current module. Args: module: module, the module object from which all key flags will be declared as key flags to the current module. flag_values: FlagValues, the FlagValues instance in which the flags will be declared as key flags. This should almost never need to be overridden. Raises: Error: Raised when given an argument that is a module name (a string), instead of a module object. z!Expected a module object, not %r.cSsg|] }|jqSr)r).0frrr sz*adopt_module_key_flags..)rcSsg|]}tj|jqSr)r r*r)r.rrrrr0s)rr'N) isinstancetypes ModuleTyperErrorr)Zget_key_flags_for_module__name__r Z FLAGS_MODULEr*)r&rrrradopt_module_key_flagss  r6cCs.tdj}t|\}}tjt|dS)aDeclares that the current module will not define any more key flags. Normally, the module that calls the DEFINE_xxx functions claims the flag to be its key flag. This is undesirable for modules that define additional DEFINE_yyy functions with its own flag parsers and serializers, since that module will accidentally claim flags defined by DEFINE_yyy as its key flags. After calling this function, the module disclaims flag definitions thereafter, so the key flags will be correctly attributed to the caller of DEFINE_yyy. After calling this function, the module will not be able to define any more flags. This function will affect all FlagValues objects. N)r! _getframe f_globalsr Zget_module_object_and_namedisclaim_module_idsaddr$)Zglobals_for_callerr&_rrrdisclaim_key_flagss r=cKs&t}t}t||||||f|S)z/Registers a flag whose value can be any string.)rArgumentParserArgumentSerializerr )rrrrrrrrrr DEFINE_stringsr@cKsttj|||f|||S)aRegisters a boolean flag. Such a boolean flag does not take an argument. If a user wants to specify a false value explicitly, the long option beginning with 'no' must be used: i.e. --noflag This flag will have a value of None, True or False. None is possible if default=None and the user does not specify the flag on the command line. Args: name: str, the flag name. default: bool|str|None, the default value of the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: str, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. **args: dict, the extra keyword args that are passed to Flag __init__. Returns: a handle to defined flag. )rrZ BooleanFlag)rrrrrrrrrDEFINE_booleansrAc Ks<t||}t}t||||||f|} t|||d| S)anRegisters 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. Returns: a handle to defined flag. )r)r FloatParserr?r r) rrrrrrrrrresultrrr DEFINE_float3s  rDc Ks<t||}t}t||||||f|} t|||d| S)alRegisters a flag whose value must be an integer. If lower_bound, or upper_bound are set, then this flag must be within the given range. Args: name: str, the flag name. default: int|str|None, the default value of the flag. help: str, the help message. lower_bound: int, min value of the flag. upper_bound: int, 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. Returns: a handle to defined flag. )r)r IntegerParserr?r r) rrrrrrrrrrCrrrDEFINE_integerTs  rFcKsttj||||f|||S)a4Registers a flag whose value can be any string from enum_values. Instead of a string enum, prefer `DEFINE_enum_class`, which allows defining enums from an `enum.Enum` class. Args: name: str, the flag name. default: str|None, the default value of the flag. enum_values: [str], a non-empty list of strings with the possible values for the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: str, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. **args: dict, the extra keyword args that are passed to Flag __init__. Returns: a handle to defined flag. )rrZEnumFlag)rr enum_valuesrrrrrrr DEFINE_enumusrHFcKs$ttj||||fd|i|||S)a"Registers a flag whose value can be the name of enum members. Args: name: str, the flag name. default: Enum|str|None, the default value of the flag. enum_class: class, the Enum class with all the possible values for the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: str, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. case_sensitive: bool, whether to map strings to members of the enum_class without considering case. **args: dict, the extra keyword args that are passed to Flag __init__. Returns: a handle to defined flag. case_sensitive)rrZ EnumClassFlag)rr enum_classrrrrIrrrrDEFINE_enum_classsrKcKs(t}td}t||||||f|S)aRegisters a flag whose value is a comma-separated list of strings. The flag value is parsed with a CSV parser. Args: name: str, the flag name. default: list|str|None, the default value of the flag. help: str, the help message. 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__. Returns: a handle to defined flag. ,)rZ ListParserZCsvListSerializerr )rrrrrrrrrr DEFINE_lists rMcKs,tj|d}td}t||||||f|S)aRegisters a flag whose value is a whitespace-separated list of strings. Any whitespace can be used as a separator. Args: name: str, the flag name. default: list|str|None, the default value of the flag. help: str, the help message. comma_compat: bool - Whether to support comma as an additional separator. If false then only whitespace is supported. This is intended only for backwards compatibility with flags that used to be comma-separated. 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__. Returns: a handle to defined flag. ) comma_compat )rZWhitespaceSeparatedListParserZListSerializerr )rrrrNrrrrrrrDEFINE_spaceseplists rPcKsttj|||||f|||S)aRegisters a generic MultiFlag that parses its args with a given parser. Auxiliary function. Normal users should NOT use it directly. Developers who need to create their own 'Parser' classes for options which can appear multiple times can call this module function to register their flags. Args: parser: ArgumentParser, used to parse the flag arguments. serializer: ArgumentSerializer, the flag serializer instance. name: str, the flag name. default: Union[Iterable[T], Text, None], the default value of the flag. If the value is text, it will be parsed as if it was provided from the command line. If the value is a non-string iterable, it will be iterated over to create a shallow copy of the values. If it is None, it is left as-is. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: A string, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. **args: Dictionary with extra keyword args that are passed to the Flag __init__. Returns: a handle to defined flag. )rrZ MultiFlag)rrrrrrrrrrr DEFINE_multis%rQcKs&t}t}t||||||f|S)aRegisters a flag whose value can be a list of any strings. Use the flag on the command line multiple times to place multiple string values into the list. The 'default' may be a single string (which will be converted into a single-element list) or a list of strings. Args: name: str, the flag name. default: Union[Iterable[Text], Text, None], the default value of the flag; see `DEFINE_multi`. help: str, the help message. 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__. Returns: a handle to defined flag. )rr>r?rQ)rrrrrrrrrrDEFINE_multi_string srRc Ks*t||}t}t||||||f|S)aDRegisters a flag whose value can be a list of arbitrary integers. Use the flag on the command line multiple times to place multiple integer values into the list. The 'default' may be a single integer (which will be converted into a single-element list) or a list of integers. Args: name: str, the flag name. default: Union[Iterable[int], Text, None], the default value of the flag; see `DEFINE_multi`. help: str, the help message. lower_bound: int, min values of the flag. upper_bound: int, 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__. Returns: a handle to defined flag. )rrEr?rQ) rrrrrrrrrrrrDEFINE_multi_integerAs rSc Ks*t||}t}t||||||f|S)aBRegisters 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__. Returns: a handle to defined flag. )rrBr?rQ) rrrrrrrrrrrrDEFINE_multi_floates rTTc Ks*t||}t}t||||||f|S)aRegisters a flag whose value can be a list strings from enum_values. Use the flag on the command line multiple times to place multiple enum values into the list. The 'default' may be a single string (which will be converted into a single-element list) or a list of strings. Args: name: str, the flag name. default: Union[Iterable[Text], Text, None], the default value of the flag; see `DEFINE_multi`. enum_values: [str], a non-empty list of strings with the possible values for the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. case_sensitive: Whether or not the enum is to be case-sensitive. **args: Dictionary with extra keyword args that are passed to the Flag __init__. Returns: a handle to defined flag. )rZ EnumParserr?rQ) rrrGrrrIrrrrrrDEFINE_multi_enums rUcKs ttj|||||d||f|S)aRegisters a flag whose value can be a list of enum members. Use the flag on the command line multiple times to place multiple enum values into the list. Args: name: str, the flag name. default: Union[Iterable[Enum], Iterable[Text], Enum, Text, None], the default value of the flag; see `DEFINE_multi`; only differences are documented here. If the value is a single Enum, it is treated as a single-item list of that Enum value. If it is an iterable, text values within the iterable will be converted to the equivalent Enum objects. enum_class: class, the Enum class with all the possible values for the flag. help: str, the help message. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: A string, the name of the Python module declaring this flag. If not provided, it will be computed using the stack trace of this call. case_sensitive: bool, whether to map strings to members of the enum_class without considering case. **args: Dictionary with extra keyword args that are passed to the Flag __init__. Returns: a handle to defined flag. )rI)rrZMultiEnumClassFlag)rrrJrrrrIrrrrDEFINE_multi_enum_classs#rVc s^||krt|||Gfdddtj}dj}t|jj|j|j d||S)a?Defines an alias flag for an existing one. Args: name: str, the flag name. original_name: str, the original flag name. flag_values: FlagValues, the FlagValues instance with which the flag will be registered. This should almost never need to be overridden. module_name: A string, the name of the module that defines this flag. Returns: a handle to defined flag. Raises: flags.FlagError: UnrecognizedFlagError: if the referenced flag doesn't exist. DuplicateFlagError: if the alias name has been used by some existing flag. csFeZdZdZfddZddZefddZejfddZd S) z DEFINE_alias.._FlagAliaszCOverrides Flag class so alias value is copy of original flag value.cs||jd7_dS)Nr7)parseZpresent)selfargument)r%rrrWs z&DEFINE_alias.._FlagAlias.parsecSs|S)Nr)rXrrrr_parse_from_defaultsz4DEFINE_alias.._FlagAlias._parse_from_defaultcsjS)N)r)rX)r%rrrsz&DEFINE_alias.._FlagAlias.valuecs |_dS)N)r)rXr)r%rrrsN) r5 __module__ __qualname____doc__rWrZpropertyrsetterr)r%rr _FlagAliass  r`zAlias for --%s.)boolean) rZUnrecognizedFlagErrorrrrrrrrra)r original_namerrr`Zhelp_msgr)r%r DEFINE_aliass  rc)0r] __future__rrrr!r2Z absl.flagsrrrrr r typingr r r ImportErrorenumr:r;r$r"r5rFLAGSr rr)r-r6r=r@rArDrFrHrKrMrPrQrRrSrTrUrVrcrrrrs~           # '  !   "! '!"# $ %