本文整理匯總了Python中absl.flags.declare_key_flag方法的典型用法代碼示例。如果您正苦於以下問題:Python flags.declare_key_flag方法的具體用法?Python flags.declare_key_flag怎麽用?Python flags.declare_key_flag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類absl.flags
的用法示例。
在下文中一共展示了flags.declare_key_flag方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register_key_flags_in_core
# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import declare_key_flag [as 別名]
def register_key_flags_in_core(f):
"""Defines a function in core.py, and registers its key flags.
absl uses the location of a flags.declare_key_flag() to determine the context
in which a flag is key. By making all declares in core, this allows model
main functions to call flags.adopt_module_key_flags() on core and correctly
chain key flags.
Args:
f: The function to be wrapped
Returns:
The "core-defined" version of the input function.
"""
def core_fn(*args, **kwargs):
key_flags = f(*args, **kwargs)
[flags.declare_key_flag(fl) for fl in key_flags] # pylint: disable=expression-not-assigned
return core_fn
示例2: define_flags
# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import declare_key_flag [as 別名]
def define_flags():
"""Define a command line flag for each ParamSpec in _DEFAULT_PARAMS."""
define_flag = {
'boolean': flags.DEFINE_boolean,
'float': flags.DEFINE_float,
'integer': flags.DEFINE_integer,
'string': flags.DEFINE_string,
}
for name, param_spec in six.iteritems(_DEFAULT_PARAMS):
if param_spec.flag_type not in define_flag:
raise ValueError('Unknown flag_type %s' % param_spec.flag_type)
else:
define_flag[param_spec.flag_type](name, param_spec.default_value,
param_spec.description)
flags.declare_key_flag(name)
示例3: declare_key_flags
# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import declare_key_flag [as 別名]
def declare_key_flags(flag_values=FLAGS):
"""Declares a few key flags."""
for flag_name in DECLARED_KEY_FLAGS:
flags.declare_key_flag(flag_name, flag_values=flag_values)
示例4: test_help_non_main_module_key_flags
# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import declare_key_flag [as 別名]
def test_help_non_main_module_key_flags(self):
flags.DEFINE_string(
'non_main_module_flag', 'default', 'help',
module_name='other.module', flag_values=self._absl_flags)
flags.declare_key_flag('non_main_module_flag', flag_values=self._absl_flags)
parser = argparse_flags.ArgumentParser(
inherited_absl_flags=self._absl_flags)
help_message = parser.format_help()
# Main module key fags are printed in the help message, even if the flag
# is defined in another module.
self.assertIn('non_main_module_flag', help_message)
示例5: test_key_flags
# 需要導入模塊: from absl import flags [as 別名]
# 或者: from absl.flags import declare_key_flag [as 別名]
def test_key_flags(self):
flag_values = flags.FlagValues()
# Before starting any testing, make sure no flags are already
# defined for module_foo and module_bar.
self.assertListEqual(self._get_names_of_key_flags(module_foo, flag_values),
[])
self.assertListEqual(self._get_names_of_key_flags(module_bar, flag_values),
[])
self.assertListEqual(self._get_names_of_defined_flags(module_foo,
flag_values),
[])
self.assertListEqual(self._get_names_of_defined_flags(module_bar,
flag_values),
[])
# Defines a few flags in module_foo and module_bar.
module_foo.define_flags(flag_values=flag_values)
try:
# Part 1. Check that all flags defined by module_foo are key for
# that module, and similarly for module_bar.
for module in [module_foo, module_bar]:
self._assert_lists_have_same_elements(
flag_values._get_flags_defined_by_module(module),
flag_values.get_key_flags_for_module(module))
# Also check that each module defined the expected flags.
self._assert_lists_have_same_elements(
self._get_names_of_defined_flags(module, flag_values),
module.names_of_defined_flags())
# Part 2. Check that flags.declare_key_flag works fine.
# Declare that some flags from module_bar are key for
# module_foo.
module_foo.declare_key_flags(flag_values=flag_values)
# Check that module_foo has the expected list of defined flags.
self._assert_lists_have_same_elements(
self._get_names_of_defined_flags(module_foo, flag_values),
module_foo.names_of_defined_flags())
# Check that module_foo has the expected list of key flags.
self._assert_lists_have_same_elements(
self._get_names_of_key_flags(module_foo, flag_values),
module_foo.names_of_declared_key_flags())
# Part 3. Check that flags.adopt_module_key_flags works fine.
# Trigger a call to flags.adopt_module_key_flags(module_bar)
# inside module_foo. This should declare a few more key
# flags in module_foo.
module_foo.declare_extra_key_flags(flag_values=flag_values)
# Check that module_foo has the expected list of key flags.
self._assert_lists_have_same_elements(
self._get_names_of_key_flags(module_foo, flag_values),
module_foo.names_of_declared_key_flags() +
module_foo.names_of_declared_extra_key_flags())
finally:
module_foo.remove_flags(flag_values=flag_values)