本文整理汇总了Python中absl.flags.DEFINE_list方法的典型用法代码示例。如果您正苦于以下问题:Python flags.DEFINE_list方法的具体用法?Python flags.DEFINE_list怎么用?Python flags.DEFINE_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类absl.flags
的用法示例。
在下文中一共展示了flags.DEFINE_list方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def define_flags(specs=None):
"""Define a command line flag for each ParamSpec in flags.param_specs."""
specs = specs or param_specs
define_flag = {
'boolean': absl_flags.DEFINE_boolean,
'float': absl_flags.DEFINE_float,
'integer': absl_flags.DEFINE_integer,
'string': absl_flags.DEFINE_string,
'enum': absl_flags.DEFINE_enum,
'list': absl_flags.DEFINE_list
}
for name, param_spec in six.iteritems(specs):
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,
help=param_spec.description,
**param_spec.kwargs)
示例2: test_list_flag_format
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def test_list_flag_format(self):
"""Tests for correctly-formatted list flags."""
flags.DEFINE_list('listflag', '', 'A list of arguments')
def _check_parsing(listval):
"""Parse a particular value for our test flag, --listflag."""
argv = FLAGS(['./program', '--listflag=' + listval, 'plain-arg'])
self.assertEqual(['./program', 'plain-arg'], argv)
return FLAGS.listflag
# Basic success case
self.assertEqual(_check_parsing('foo,bar'), ['foo', 'bar'])
# Success case: newline in argument is quoted.
self.assertEqual(_check_parsing('"foo","bar\nbar"'), ['foo', 'bar\nbar'])
# Failure case: newline in argument is unquoted.
self.assertRaises(
flags.IllegalFlagValueError, _check_parsing, '"foo",bar\nbar')
# Failure case: unmatched ".
self.assertRaises(
flags.IllegalFlagValueError, _check_parsing, '"foo,barbar')
示例3: define_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def define_flags():
"""Define a command line flag for each ParamSpec in flags.param_specs."""
define_flag = {
'boolean': absl_flags.DEFINE_boolean,
'float': absl_flags.DEFINE_float,
'integer': absl_flags.DEFINE_integer,
'string': absl_flags.DEFINE_string,
'enum': absl_flags.DEFINE_enum,
'list': absl_flags.DEFINE_list
}
for name, param_spec in six.iteritems(param_specs):
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,
help=param_spec.description,
**param_spec.kwargs)
示例4: DEFINE_list
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def DEFINE_list(
name: str,
default: Optional[List[Any]],
help: str,
required: bool = False,
validator: Callable[[List[Any]], bool] = None,
):
"""Registers a flag whose value must be a list."""
absl_flags.DEFINE_list(
name, default, help, module_name=get_calling_module_name(),
)
if required:
absl_flags.mark_flag_as_required(name)
if validator:
RegisterFlagValidator(name, validator)
# My custom flag types.
示例5: DEFINE_list
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def DEFINE_list(name, default, help): # pylint: disable=invalid-name,redefined-builtin
param_specs[name] = ParamSpec('list', default, help, {})
示例6: test_unicode_in_list
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def test_unicode_in_list(self):
flags.DEFINE_list('unicode_list', ['abc', b'\xC3\x80'.decode('utf-8'),
b'\xC3\xBD'.decode('utf-8')],
b'help:\xC3\xAB'.decode('utf-8'))
argv = ('./program',)
FLAGS(argv) # should not raise any exceptions
argv = ('./program', '--unicode_list=hello,there')
FLAGS(argv) # should not raise any exceptions
示例7: test_xmloutput
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def test_xmloutput(self):
flags.DEFINE_string('unicode1', b'\xC3\x80\xC3\xBD'.decode('utf-8'),
b'help:\xC3\xAC'.decode('utf-8'))
flags.DEFINE_list('unicode2', ['abc', b'\xC3\x80'.decode('utf-8'),
b'\xC3\xBD'.decode('utf-8')],
b'help:\xC3\xAD'.decode('utf-8'))
flags.DEFINE_list('non_unicode', ['abc', 'def', 'ghi'],
b'help:\xC3\xAD'.decode('utf-8'))
outfile = io.StringIO() if six.PY3 else io.BytesIO()
FLAGS.write_help_in_xml_format(outfile)
actual_output = outfile.getvalue()
if six.PY2:
actual_output = actual_output.decode('utf-8')
# The xml output is large, so we just check parts of it.
self.assertIn(b'<name>unicode1</name>\n'
b' <meaning>help:\xc3\xac</meaning>\n'
b' <default>\xc3\x80\xc3\xbd</default>\n'
b' <current>\xc3\x80\xc3\xbd</current>'.decode('utf-8'),
actual_output)
if six.PY2:
self.assertIn(b'<name>unicode2</name>\n'
b' <meaning>help:\xc3\xad</meaning>\n'
b' <default>abc,\xc3\x80,\xc3\xbd</default>\n'
b" <current>['abc', u'\\xc0', u'\\xfd']"
b'</current>'.decode('utf-8'),
actual_output)
else:
self.assertIn(b'<name>unicode2</name>\n'
b' <meaning>help:\xc3\xad</meaning>\n'
b' <default>abc,\xc3\x80,\xc3\xbd</default>\n'
b" <current>['abc', '\xc3\x80', '\xc3\xbd']"
b'</current>'.decode('utf-8'),
actual_output)
self.assertIn(b'<name>non_unicode</name>\n'
b' <meaning>help:\xc3\xad</meaning>\n'
b' <default>abc,def,ghi</default>\n'
b" <current>['abc', 'def', 'ghi']"
b'</current>'.decode('utf-8'),
actual_output)
示例8: setUp
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def setUp(self):
self.flag_values = flags.FlagValues()
flags.DEFINE_string('unittest_message1', 'Foo!', 'You Add Here.',
flag_values=self.flag_values)
flags.DEFINE_string('unittest_message2', 'Bar!', 'Hello, Sailor!',
flag_values=self.flag_values)
flags.DEFINE_boolean('unittest_boolflag', 0, 'Some Boolean thing',
flag_values=self.flag_values)
flags.DEFINE_integer('unittest_number', 12345, 'Some integer',
lower_bound=0, flag_values=self.flag_values)
flags.DEFINE_list('UnitTestList', '1,2,3', 'Some list',
flag_values=self.flag_values)
self.tmp_path = None
self.flag_values.mark_as_parsed()
示例9: test_flag_help_in_xml_comma_separated_list
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def test_flag_help_in_xml_comma_separated_list(self):
flags.DEFINE_list('files', 'a.cc,a.h,archive/old.zip',
'Files to process.', flag_values=self.fv)
expected_output = (
'<flag>\n'
' <file>tool</file>\n'
' <name>files</name>\n'
' <meaning>Files to process.</meaning>\n'
' <default>a.cc,a.h,archive/old.zip</default>\n'
' <current>[\'a.cc\', \'a.h\', \'archive/old.zip\']</current>\n'
' <type>comma separated list of strings</type>\n'
' <list_separator>\',\'</list_separator>\n'
'</flag>\n')
self._check_flag_help_in_xml('files', 'tool', expected_output)
示例10: test_none_as_default_arguments_comma_separated_list
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def test_none_as_default_arguments_comma_separated_list(self):
flags.DEFINE_list('allow_users', None,
'Users with access.', flag_values=self.fv)
expected_output = (
'<flag>\n'
' <file>tool</file>\n'
' <name>allow_users</name>\n'
' <meaning>Users with access.</meaning>\n'
' <default></default>\n'
' <current>None</current>\n'
' <type>comma separated list of strings</type>\n'
' <list_separator>\',\'</list_separator>\n'
'</flag>\n')
self._check_flag_help_in_xml('allow_users', 'tool', expected_output)
示例11: define_keras_benchmark_flags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def define_keras_benchmark_flags():
"""Add flags for keras built-in application models."""
flags_core.define_base(hooks=False)
flags_core.define_performance()
flags_core.define_image()
flags_core.define_benchmark()
flags.adopt_module_key_flags(flags_core)
flags_core.set_defaults(
data_format="channels_last",
use_synthetic_data=True,
batch_size=32,
train_epochs=2)
flags.DEFINE_enum(
name="model", default=None,
enum_values=MODELS.keys(), case_sensitive=False,
help=flags_core.help_wrap(
"Model to be benchmarked."))
flags.DEFINE_integer(
name="num_train_images", default=1000,
help=flags_core.help_wrap(
"The number of synthetic images for training. The default value is "
"1000."))
flags.DEFINE_integer(
name="num_eval_images", default=50,
help=flags_core.help_wrap(
"The number of synthetic images for evaluation. The default value is "
"50."))
flags.DEFINE_boolean(
name="eager", default=False, help=flags_core.help_wrap(
"To enable eager execution. Note that if eager execution is enabled, "
"only one GPU is utilized even if multiple GPUs are provided and "
"multi_gpu_model is used."))
flags.DEFINE_boolean(
name="dist_strat", default=False, help=flags_core.help_wrap(
"To enable distribution strategy for model training and evaluation. "
"Number of GPUs used for distribution strategy can be set by the "
"argument --num_gpus."))
flags.DEFINE_list(
name="callbacks",
default=["ExamplesPerSecondCallback", "LoggingMetricCallback"],
help=flags_core.help_wrap(
"A list of (case insensitive) strings to specify the names of "
"callbacks. For example: `--callbacks ExamplesPerSecondCallback,"
"LoggingMetricCallback`"))
@flags.multi_flags_validator(
["eager", "dist_strat"],
message="Both --eager and --dist_strat were set. Only one can be "
"defined, as DistributionStrategy is not supported in Eager "
"execution currently.")
# pylint: disable=unused-variable
def _check_eager_dist_strat(flag_dict):
return not(flag_dict["eager"] and flag_dict["dist_strat"])
示例12: SetupFlags
# 需要导入模块: from absl import flags [as 别名]
# 或者: from absl.flags import DEFINE_list [as 别名]
def SetupFlags():
flags.DEFINE_string(
'base_directory',
'./policies',
'The base directory to look for acls; '
'typically where you\'d find ./corp and ./prod')
flags.DEFINE_string(
'definitions_directory',
'./def',
'Directory where the definitions can be found.')
flags.DEFINE_string(
'policy_file',
None,
'Individual policy file to generate.')
flags.DEFINE_string(
'output_directory',
'./',
'Directory to output the rendered acls.')
flags.DEFINE_boolean(
'optimize',
False,
'Turn on optimization.',
short_name='o')
flags.DEFINE_boolean(
'recursive',
True,
'Descend recursively from the base directory rendering acls')
flags.DEFINE_boolean(
'debug',
False,
'Debug messages')
flags.DEFINE_boolean(
'verbose',
False,
'Verbose messages')
flags.DEFINE_list(
'ignore_directories',
'DEPRECATED, def',
'Don\'t descend into directories that look like this string')
flags.DEFINE_integer(
'max_renderers',
10,
'Max number of rendering processes to use.')
flags.DEFINE_boolean(
'shade_check',
False,
'Raise an error when a term is completely shaded by a prior term.')
flags.DEFINE_integer(
'exp_info',
2,
'Print a info message when a term is set to expire in that many weeks.')