当前位置: 首页>>代码示例>>Python>>正文


Python flags.declare_key_flag方法代码示例

本文整理汇总了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 
开发者ID:IntelAI,项目名称:models,代码行数:21,代码来源:core.py

示例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) 
开发者ID:snuspl,项目名称:parallax,代码行数:17,代码来源:benchmark_cnn.py

示例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) 
开发者ID:abseil,项目名称:abseil-py,代码行数:6,代码来源:module_foo.py

示例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) 
开发者ID:abseil,项目名称:abseil-py,代码行数:14,代码来源:argparse_flags_test.py

示例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) 
开发者ID:abseil,项目名称:abseil-py,代码行数:60,代码来源:flags_test.py


注:本文中的absl.flags.declare_key_flag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。