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


Python OptionsBootstrapper.update方法代码示例

本文整理汇总了Python中pants.option.options_bootstrapper.OptionsBootstrapper.update方法的典型用法代码示例。如果您正苦于以下问题:Python OptionsBootstrapper.update方法的具体用法?Python OptionsBootstrapper.update怎么用?Python OptionsBootstrapper.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pants.option.options_bootstrapper.OptionsBootstrapper的用法示例。


在下文中一共展示了OptionsBootstrapper.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseTest

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import update [as 别名]

#.........这里部分代码省略.........

  def setUp(self):
    super(BaseTest, self).setUp()
    Goal.clear()
    self.real_build_root = BuildRoot().path
    self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
    self.pants_workdir = os.path.join(self.build_root, '.pants.d')
    safe_mkdir(self.pants_workdir)
    self.options = defaultdict(dict)  # scope -> key-value mapping.
    self.options[''] = {
      'pants_workdir': self.pants_workdir,
      'pants_supportdir': os.path.join(self.build_root, 'build-support'),
      'pants_distdir': os.path.join(self.build_root, 'dist'),
      'pants_configdir': os.path.join(self.build_root, 'config'),
      'cache_key_gen_version': '0-test',
    }
    BuildRoot().path = self.build_root
    Subsystem.reset()

    self.create_file('pants.ini')
    build_configuration = BuildConfiguration()
    build_configuration.register_aliases(self.alias_groups)
    self.build_file_parser = BuildFileParser(build_configuration, self.build_root)
    self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
    self.build_graph = BuildGraph(address_mapper=self.address_mapper)
    self.bootstrap_option_values = OptionsBootstrapper().get_bootstrap_options().for_global_scope()

  def reset_build_graph(self):
    """Start over with a fresh build graph with no targets in it."""
    self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
    self.build_graph = BuildGraph(address_mapper=self.address_mapper)

  def set_options_for_scope(self, scope, **kwargs):
    self.options[scope].update(kwargs)

  def context(self, for_task_types=None, options=None, target_roots=None,
              console_outstream=None, workspace=None):
    for_task_types = for_task_types or []
    options = options or {}

    option_values = defaultdict(dict)
    registered_global_subsystems = set()

    # Get default values for all options registered by the tasks in for_task_types.
    # TODO: This is clunky and somewhat repetitive of the real registration code.
    for task_type in for_task_types:
      scope = task_type.options_scope
      if scope is None:
        raise TaskError('You must set a scope on your task type before using it in tests.')

      # We provide our own test-only registration implementation, bypassing argparse.
      # When testing we set option values directly, so we don't care about cmd-line flags, config,
      # env vars etc. In fact, for test isolation we explicitly don't want to look at those.
      def register_func(on_scope):
        def register(*rargs, **rkwargs):
          scoped_options = option_values[on_scope]
          default = rkwargs.get('default')
          if default is None and rkwargs.get('action') == 'append':
            default = []
          for flag_name in rargs:
            option_name = flag_name.lstrip('-').replace('-', '_')
            scoped_options[option_name] = default
        register.bootstrap = self.bootstrap_option_values
        register.scope = on_scope
        return register
      register_bootstrap_options(register_func(Options.GLOBAL_SCOPE), self.build_root)
开发者ID:pombreda,项目名称:pants,代码行数:70,代码来源:base_test.py


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