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


Python OptionsBootstrapper.create方法代码示例

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


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

示例1: select

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
def select(argv):
  # Parse positional arguments to the script.
  args = _create_bootstrap_binary_arg_parser().parse_args(argv[1:])
  # Resolve bootstrap options with a fake empty command line.
  options_bootstrapper = OptionsBootstrapper.create(args=[argv[0]])
  subsystems = (GlobalOptionsRegistrar, BinaryUtil.Factory)
  known_scope_infos = reduce(set.union, (ss.known_scope_infos() for ss in subsystems), set())
  options = options_bootstrapper.get_full_options(known_scope_infos)
  # Initialize Subsystems.
  Subsystem.set_options(options)

  # If the filename provided ends in a known archive extension (such as ".tar.gz"), then we get the
  # appropriate Archiver to pass to BinaryUtil.
  archiver_for_current_binary = None
  filename = args.filename or args.util_name
  try:
    archiver_for_current_binary = archiver_for_path(filename)
    # BinaryRequest requires the `name` field to be provided without an extension, as it appends the
    # archiver's extension if one is provided, so we have to remove it here.
    filename = filename[:-(len(archiver_for_current_binary.extension) + 1)]
  except ValueError:
    pass

  binary_util = BinaryUtil.Factory.create()
  binary_request = BinaryRequest(
    supportdir='bin/{}'.format(args.util_name),
    version=args.version,
    name=filename,
    platform_dependent=True,
    external_url_generator=None,
    archiver=archiver_for_current_binary)

  return binary_util.select(binary_request)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:35,代码来源:binary_util.py

示例2: execute

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def execute(self):
   try:
     pantsd = PantsDaemon.Factory.create(OptionsBootstrapper.create(), full_init=False)
     with pantsd.lifecycle_lock:
       pantsd.terminate()
   except ProcessManager.NonResponsiveProcess as e:
     raise TaskError('failure while terminating pantsd: {}'.format(e))
开发者ID:cosmicexplorer,项目名称:pants,代码行数:9,代码来源:pantsd_kill.py

示例3: test_create_bootstrapped_options

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def test_create_bootstrapped_options(self):
    # Check that we can set a bootstrap option from a cmd-line flag and have that interpolate
    # correctly into regular config.
    with temporary_file(binary_mode=False) as fp:
      fp.write(dedent("""
      [foo]
      bar: %(pants_workdir)s/baz

      [fruit]
      apple: %(pants_supportdir)s/banana
      """))
      fp.close()
      args = ['--pants-workdir=/qux'] + self._config_path(fp.name)
      bootstrapper = OptionsBootstrapper.create(env={
                                           'PANTS_SUPPORTDIR': '/pear'
                                         },
                                         args=args)
      opts = bootstrapper.get_full_options(known_scope_infos=[
        ScopeInfo('', ScopeInfo.GLOBAL),
        ScopeInfo('foo', ScopeInfo.TASK),
        ScopeInfo('fruit', ScopeInfo.TASK)
      ])
      # So we don't choke on these on the cmd line.
      opts.register('', '--pants-workdir')
      opts.register('', '--pants-config-files')

      opts.register('foo', '--bar')
      opts.register('fruit', '--apple')
    self.assertEqual('/qux/baz', opts.for_scope('foo').bar)
    self.assertEqual('/pear/banana', opts.for_scope('fruit').apple)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:32,代码来源:test_options_bootstrapper.py

示例4: test_global_options_validation

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def test_global_options_validation(self):
   # Specify an invalid combination of options.
   ob = OptionsBootstrapper.create(args=['--loop', '--v1'])
   build_config = BuildConfigInitializer.get(ob)
   with self.assertRaises(OptionsError) as exc:
     OptionsInitializer.create(ob, build_config)
   self.assertIn('loop option only works with', str(exc.exception))
开发者ID:cosmicexplorer,项目名称:pants,代码行数:9,代码来源:test_options_initializer.py

示例5: parse_options

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def parse_options(args, env, setup_logging=False, options_bootstrapper=None):
   options_bootstrapper = options_bootstrapper or OptionsBootstrapper.create(args=args, env=env)
   bootstrap_options = options_bootstrapper.get_bootstrap_options().for_global_scope()
   if setup_logging:
     # Bootstrap logging and then fully initialize options.
     setup_logging_from_options(bootstrap_options)
   build_config = BuildConfigInitializer.get(options_bootstrapper)
   options = OptionsInitializer.create(options_bootstrapper, build_config)
   return options, build_config, options_bootstrapper
开发者ID:cosmicexplorer,项目名称:pants,代码行数:11,代码来源:local_pants_runner.py

示例6: _ob

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def _ob(self, args=tuple(), env=tuple()):
   self.create_file('pants.ini')
   options_bootstrap = OptionsBootstrapper.create(
     args=tuple(args),
     env=dict(env),
   )
   # NB: BuildConfigInitializer has sideeffects on first-run: in actual usage, these
   # sideeffects will happen during setup. We force them here.
   BuildConfigInitializer.get(options_bootstrap)
   return options_bootstrap
开发者ID:cosmicexplorer,项目名称:pants,代码行数:12,代码来源:test_options_parsing.py

示例7: test_bootstrapped_options_ignore_irrelevant_env

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def test_bootstrapped_options_ignore_irrelevant_env(self):
   included = 'PANTS_SUPPORTDIR'
   excluded = 'NON_PANTS_ENV'
   bootstrapper = OptionsBootstrapper.create(
       env={
         excluded: 'pear',
         included: 'banana',
       }
     )
   self.assertIn(included, bootstrapper.env)
   self.assertNotIn(excluded, bootstrapper.env)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:13,代码来源:test_options_bootstrapper.py

示例8: test_setting_pants_config_in_config

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def test_setting_pants_config_in_config(self):
    # Test that setting pants_config in the config file has no effect.
    with temporary_dir() as tmpdir:
      config1 = os.path.join(tmpdir, 'config1')
      config2 = os.path.join(tmpdir, 'config2')
      with open(config1, 'w') as out1:
        out1.write("[DEFAULT]\npants_config_files: ['{}']\nlogdir: logdir1\n".format(config2))
      with open(config2, 'w') as out2:
        out2.write('[DEFAULT]\nlogdir: logdir2\n')

      ob = OptionsBootstrapper.create(env={}, args=["--pants-config-files=['{}']".format(config1)])
      logdir = ob.get_bootstrap_options().for_global_scope().logdir
      self.assertEqual('logdir1', logdir)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:15,代码来源:test_options_bootstrapper.py

示例9: _test_bootstrap_options

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def _test_bootstrap_options(self, config, env, args, **expected_entries):
    with temporary_file(binary_mode=False) as fp:
      fp.write('[DEFAULT]\n')
      if config:
        for k, v in config.items():
          fp.write('{0}: {1}\n'.format(k, v))
      fp.close()

      args = args + self._config_path(fp.name)
      bootstrapper = OptionsBootstrapper.create(env=env, args=args)
      vals = bootstrapper.get_bootstrap_options().for_global_scope()

      vals_dict = {k: getattr(vals, k) for k in expected_entries}
      self.assertEqual(expected_entries, vals_dict)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:16,代码来源:test_options_bootstrapper.py

示例10: test_full_options_caching

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def test_full_options_caching(self):
    with temporary_file_path() as config:
      args = self._config_path(config)
      bootstrapper = OptionsBootstrapper.create(env={}, args=args)

      opts1 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL),
                                                               ScopeInfo('foo', ScopeInfo.TASK)])
      opts2 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('foo', ScopeInfo.TASK),
                                                               ScopeInfo('', ScopeInfo.GLOBAL)])
      self.assertIs(opts1, opts2)

      opts3 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL),
                                                               ScopeInfo('foo', ScopeInfo.TASK),
                                                               ScopeInfo('', ScopeInfo.GLOBAL)])
      self.assertIs(opts1, opts3)

      opts4 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)])
      self.assertIsNot(opts1, opts4)

      opts5 = bootstrapper.get_full_options(known_scope_infos=[ScopeInfo('', ScopeInfo.GLOBAL)])
      self.assertIs(opts4, opts5)
      self.assertIsNot(opts1, opts5)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:24,代码来源:test_options_bootstrapper.py

示例11: plugin_resolution

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def plugin_resolution(self, chroot=None, plugins=None, packager_cls=None):
    @contextmanager
    def provide_chroot(existing):
      if existing:
        yield existing, False
      else:
        with temporary_dir() as new_chroot:
          yield new_chroot, True

    with provide_chroot(chroot) as (root_dir, create_artifacts):
      env = {'PANTS_BOOTSTRAPDIR': root_dir}
      repo_dir = None
      if plugins:
        repo_dir = os.path.join(root_dir, 'repo')
        env.update(PANTS_PYTHON_REPOS_REPOS='[{!r}]'.format(repo_dir),
                   PANTS_PYTHON_REPOS_INDEXES='[]',
                   PANTS_PYTHON_SETUP_RESOLVER_CACHE_TTL='1')
        plugin_list = []
        for plugin in plugins:
          version = None
          if isinstance(plugin, tuple):
            plugin, version = plugin
          plugin_list.append('{}=={}'.format(plugin, version) if version else plugin)
          if create_artifacts:
            self.create_plugin(repo_dir, plugin, version, packager_cls=packager_cls)
        env['PANTS_PLUGINS'] = '[{}]'.format(','.join(map(repr, plugin_list)))

      configpath = os.path.join(root_dir, 'pants.ini')
      if create_artifacts:
        touch(configpath)
      args = ["--pants-config-files=['{}']".format(configpath)]

      options_bootstrapper = OptionsBootstrapper.create(env=env, args=args)
      plugin_resolver = PluginResolver(options_bootstrapper)
      cache_dir = plugin_resolver.plugin_cache_dir
      yield plugin_resolver.resolve(WorkingSet(entries=[])), root_dir, repo_dir, cache_dir
开发者ID:cosmicexplorer,项目名称:pants,代码行数:38,代码来源:test_plugin_resolver.py

示例12: run

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def run(self):
    # Register our exiter at the beginning of the run() method so that any code in this process from
    # this point onwards will use that exiter in the case of a fatal error.
    ExceptionSink.reset_exiter(self._exiter)

    options_bootstrapper = OptionsBootstrapper.create(env=self._env, args=self._args)
    bootstrap_options = options_bootstrapper.bootstrap_options
    global_bootstrap_options = bootstrap_options.for_global_scope()

    # We enable Rust logging here,
    # and everything before it will be routed through regular Python logging.
    self._enable_rust_logging(global_bootstrap_options)

    ExceptionSink.reset_should_print_backtrace_to_terminal(global_bootstrap_options.print_exception_stacktrace)
    ExceptionSink.reset_log_location(global_bootstrap_options.pants_workdir)

    for message_regexp in global_bootstrap_options.ignore_pants_warnings:
      warnings.filterwarnings(action='ignore', message=message_regexp)

    if global_bootstrap_options.enable_pantsd:
      try:
        return RemotePantsRunner(self._exiter, self._args, self._env, options_bootstrapper).run()
      except RemotePantsRunner.Fallback as e:
        logger.warn('caught client exception: {!r}, falling back to non-daemon mode'.format(e))

    # N.B. Inlining this import speeds up the python thin client run by about 100ms.
    from pants.bin.local_pants_runner import LocalPantsRunner

    runner = LocalPantsRunner.create(
        self._exiter,
        self._args,
        self._env,
        options_bootstrapper=options_bootstrapper
    )
    runner.set_start_time(self._start_time)
    return runner.run()
开发者ID:cosmicexplorer,项目名称:pants,代码行数:38,代码来源:pants_runner.py

示例13: launch

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
def launch():
  """An external entrypoint that spawns a new pantsd instance."""
  PantsDaemon.Factory.create(OptionsBootstrapper.create()).run_sync()
开发者ID:jsirois,项目名称:pants,代码行数:5,代码来源:pants_daemon.py

示例14: create_options_bootstrapper

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
 def create_options_bootstrapper(*config_paths):
   return OptionsBootstrapper.create(args=['--pantsrc-files={}'.format(cp) for cp in config_paths])
开发者ID:cosmicexplorer,项目名称:pants,代码行数:4,代码来源:test_options_bootstrapper.py

示例15: test_invalid_version

# 需要导入模块: from pants.option.options_bootstrapper import OptionsBootstrapper [as 别名]
# 或者: from pants.option.options_bootstrapper.OptionsBootstrapper import create [as 别名]
  def test_invalid_version(self):
    options_bootstrapper = OptionsBootstrapper.create(args=['--pants-version=99.99.9999'])
    build_config = BuildConfigInitializer.get(options_bootstrapper)

    with self.assertRaises(BuildConfigurationError):
      OptionsInitializer.create(options_bootstrapper, build_config)
开发者ID:cosmicexplorer,项目名称:pants,代码行数:8,代码来源:test_options_initializer.py


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