本文整理汇总了Python中pants.option.option_value_container.OptionValueContainer.update方法的典型用法代码示例。如果您正苦于以下问题:Python OptionValueContainer.update方法的具体用法?Python OptionValueContainer.update怎么用?Python OptionValueContainer.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.option.option_value_container.OptionValueContainer
的用法示例。
在下文中一共展示了OptionValueContainer.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: for_scope
# 需要导入模块: from pants.option.option_value_container import OptionValueContainer [as 别名]
# 或者: from pants.option.option_value_container.OptionValueContainer import update [as 别名]
def for_scope(self, scope):
"""Return the option values for the given scope.
Values are attributes of the returned object, e.g., options.foo.
Computed lazily per scope.
"""
# Short-circuit, if already computed.
if scope in self._values_by_scope:
return self._values_by_scope[scope]
# First get enclosing scope's option values, if any.
if scope == GLOBAL_SCOPE:
values = OptionValueContainer()
if self._legacy_values:
values.update(vars(self._legacy_values)) # Proxy any legacy option values.
else:
values = copy.copy(self.for_scope(scope.rpartition('.')[0]))
# Now add our values.
try:
flags_in_scope = self._scope_to_flags.get(scope, [])
self._parser_hierarchy.get_parser_by_scope(scope).parse_args(flags_in_scope, values)
self._values_by_scope[scope] = values
return values
except ParseError as e:
self.print_help(str(e))
sys.exit(1)
示例2: for_scope
# 需要导入模块: from pants.option.option_value_container import OptionValueContainer [as 别名]
# 或者: from pants.option.option_value_container.OptionValueContainer import update [as 别名]
def for_scope(self, scope, inherit_from_enclosing_scope=True):
"""Return the option values for the given scope.
Values are attributes of the returned object, e.g., options.foo.
Computed lazily per scope.
:API: public
"""
# Short-circuit, if already computed.
if scope in self._values_by_scope:
return self._values_by_scope[scope]
# First get enclosing scope's option values, if any.
if scope == GLOBAL_SCOPE or not inherit_from_enclosing_scope:
values = OptionValueContainer()
else:
values = copy.copy(self.for_scope(enclosing_scope(scope)))
# Now add our values.
flags_in_scope = self._scope_to_flags.get(scope, [])
self._parser_hierarchy.get_parser_by_scope(scope).parse_args(flags_in_scope, values)
# If we're the new name of a deprecated scope, also get values from that scope.
deprecated_scope = self.known_scope_to_info[scope].deprecated_scope
# Note that deprecated_scope and scope share the same Optionable class, so deprecated_scope's
# Optionable has a deprecated_options_scope equal to deprecated_scope. Therefore we must
# check that scope != deprecated_scope to prevent infinite recursion.
if deprecated_scope is not None and scope != deprecated_scope:
# Do the deprecation check only on keys that were explicitly set on the deprecated scope
# (and not on its enclosing scopes).
explicit_keys = self.for_scope(deprecated_scope,
inherit_from_enclosing_scope=False).get_explicit_keys()
if explicit_keys:
warn_or_error(self.known_scope_to_info[scope].deprecated_scope_removal_version,
'scope {}'.format(deprecated_scope),
'Use scope {} instead (options: {})'.format(scope, ', '.join(explicit_keys)))
# Update our values with those of the deprecated scope (now including values inherited
# from its enclosing scope).
# Note that a deprecated val will take precedence over a val of equal rank.
# This makes the code a bit neater.
values.update(self.for_scope(deprecated_scope))
# Record the value derivation.
for option in values:
self._option_tracker.record_option(scope=scope, option=option, value=values[option],
rank=values.get_rank(option))
# Cache the values.
self._values_by_scope[scope] = values
return values