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


Python Subsystem.closure方法代码示例

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


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

示例1: test_closure_cycle

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def test_closure_cycle(self):
    class SubsystemC(Subsystem):
      options_scope = 'c'

      @classmethod
      def subsystem_dependencies(cls):
        return (SubsystemA,)

    class SubsystemB(Subsystem):
      options_scope = 'b'

      @classmethod
      def subsystem_dependencies(cls):
        return (SubsystemC,)

    class SubsystemA(Subsystem):
      options_scope = 'a'

      @classmethod
      def subsystem_dependencies(cls):
        return (SubsystemB,)

    for root in SubsystemA, SubsystemB, SubsystemC:
      with self.assertRaises(Subsystem.CycleException):
        Subsystem.closure((root,))
开发者ID:grimreaper,项目名称:pants,代码行数:27,代码来源:test_subsystem.py

示例2: _install_options

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def _install_options(self, options_bootstrapper, build_configuration):
    """Parse and register options.

    :returns: An Options object representing the full set of runtime options.
    """
    # TODO: This inline import is currently necessary to resolve a ~legitimate cycle between
    # `GoalRunner`->`EngineInitializer`->`OptionsInitializer`->`GoalRunner`.
    from pants.bin.goal_runner import GoalRunner

    # Now that plugins and backends are loaded, we can gather the known scopes.
    known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]

    # Add scopes for all needed subsystems via a union of all known subsystem sets.
    subsystems = Subsystem.closure(
      GoalRunner.subsystems() | Goal.subsystems() | build_configuration.subsystems()
    )
    for subsystem in subsystems:
      known_scope_infos.append(subsystem.get_scope_info())

    # Add scopes for all tasks in all goals.
    for goal in Goal.all():
      known_scope_infos.extend(filter(None, goal.known_scope_infos()))

    # Now that we have the known scopes we can get the full options.
    options = options_bootstrapper.get_full_options(known_scope_infos)
    self._register_options(subsystems, options)

    # Make the options values available to all subsystems.
    Subsystem.set_options(options)

    return options
开发者ID:ericzundel,项目名称:pants,代码行数:33,代码来源:options_initializer.py

示例3: subsystem_instance

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
def subsystem_instance(subsystem_type, scope=None, **options):
  """Creates a Subsystem instance for test.

  :API: public

  :param type subsystem_type: The subclass of :class:`pants.subsystem.subsystem.Subsystem`
                              to create.
  :param string scope: An optional scope to create the subsystem in; defaults to global.
  :param **options: Keyword args representing option values explicitly set via the command line.
  """
  if not issubclass(subsystem_type, Subsystem):
    raise TypeError('The given `subsystem_type` was not a subclass of `Subsystem`: {}'
                    .format(subsystem_type))

  optionables = Subsystem.closure([subsystem_type])
  updated_options = dict(Subsystem._options.items()) if Subsystem._options else {}
  if options:
    updated_options.update(options)

  Subsystem._options = create_options_for_optionables(optionables, options=updated_options)
  try:
    if scope is None:
      yield subsystem_type.global_instance()
    else:
      class ScopedOptionable(Optionable):
        options_scope = scope
        options_scope_category = ScopeInfo.SUBSYSTEM
      yield subsystem_type.scoped_instance(ScopedOptionable)
  finally:
    Subsystem.reset()
开发者ID:Gointer,项目名称:pants,代码行数:32,代码来源:subsystem_util.py

示例4: context

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def context(self, for_task_types=None, for_subsystems=None, options=None,
              target_roots=None, console_outstream=None, workspace=None,
              **kwargs):
    """
    :API: public

    :param dict **kwargs: keyword arguments passed in to `create_options_for_optionables`.
    """
    # Many tests use source root functionality via the SourceRootConfig.global_instance().
    # (typically accessed via Target.target_base), so we always set it up, for convenience.
    optionables = {SourceRootConfig}
    extra_scopes = set()

    for_subsystems = for_subsystems or ()
    for subsystem in for_subsystems:
      if subsystem.options_scope is None:
        raise TaskError('You must set a scope on your subsystem type before using it in tests.')
      optionables.add(subsystem)

    for_task_types = for_task_types or ()
    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.')
      optionables.add(task_type)
      # If task is expected to inherit goal-level options, register those directly on the task,
      # by subclassing the goal options registrar and settings its scope to the task scope.
      if issubclass(task_type, GoalOptionsMixin):
        subclass_name = b'test_{}_{}_{}'.format(
          task_type.__name__, task_type.goal_options_registrar_cls.options_scope,
          task_type.options_scope)
        optionables.add(type(subclass_name, (task_type.goal_options_registrar_cls, ),
                             {b'options_scope': task_type.options_scope}))

      extra_scopes.update([si.scope for si in task_type.known_scope_infos()])
      optionables.update(Subsystem.closure(
        set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()]) |
            self._build_configuration.subsystems()))

    # Now default the option values and override with any caller-specified values.
    # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
    options = options.copy() if options else {}
    for s, opts in self.options.items():
      scoped_opts = options.setdefault(s, {})
      scoped_opts.update(opts)

    fake_options = create_options_for_optionables(
      optionables, extra_scopes=extra_scopes, options=options, **kwargs)

    Subsystem.reset(reset_options=True)
    Subsystem.set_options(fake_options)

    context = create_context_from_options(fake_options,
                                          target_roots=target_roots,
                                          build_graph=self.build_graph,
                                          build_file_parser=self.build_file_parser,
                                          address_mapper=self.address_mapper,
                                          console_outstream=console_outstream,
                                          workspace=workspace)
    return context
开发者ID:benjyw,项目名称:pants,代码行数:62,代码来源:base_test.py

示例5: test_closure_tree

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def test_closure_tree(self):
    class SubsystemB(Subsystem):
      options_scope = 'b'

    class SubsystemA(Subsystem):
      options_scope = 'a'

      @classmethod
      def subsystem_dependencies(cls):
        return (DummySubsystem, SubsystemB)

    self.assertEqual({DummySubsystem, SubsystemA, SubsystemB}, Subsystem.closure((SubsystemA,)))
    self.assertEqual({DummySubsystem, SubsystemA, SubsystemB},
                     Subsystem.closure((SubsystemA, SubsystemB)))
    self.assertEqual({DummySubsystem, SubsystemA, SubsystemB},
                     Subsystem.closure((DummySubsystem, SubsystemA, SubsystemB)))
开发者ID:grimreaper,项目名称:pants,代码行数:18,代码来源:test_subsystem.py

示例6: init_subsystems

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
def init_subsystems(subsystem_types, options=None):
  """Initialize subsystems for use in tests.

  Does not create an instance.  This function is for setting up subsystems that the code
  under test creates.

  Note that there is some redundancy between this function and BaseTest.context(for_subsystems=...).
  TODO: Fix that.

  :API: public

  :param list subsystem_types: The subclasses of :class:`pants.subsystem.subsystem.Subsystem`
                               to create.
  :param options: dict of scope -> (dict of option name -> value).
                  The scopes may be those of the global instances of the subsystems (i.e.,
                  subsystem_type.options_scope) and/or the scopes of instances of the
                  subsystems they transitively depend on.
  """
  for s in subsystem_types:
    if not Subsystem.is_subsystem_type(s):
      raise TypeError('{} is not a subclass of `Subsystem`'.format(s))
  optionables = Subsystem.closure(subsystem_types)
  if options:
    allowed_scopes = {o.options_scope for o in optionables}
    for scope in options.keys():
      if scope != '' and scope not in allowed_scopes:
        raise ValueError('`{}` is not the scope of any of these subsystems: {}'.format(
          scope, optionables))
  # Don't trample existing subsystem options, in case a test has set up some
  # other subsystems in some other way.
  updated_options = dict(Subsystem._options.items()) if Subsystem._options else {}
  if options:
    updated_options.update(options)
  Subsystem.set_options(create_options_for_optionables(optionables, options=updated_options))
开发者ID:benjyw,项目名称:pants,代码行数:36,代码来源:subsystem_util.py

示例7: context

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
    def context(
        self,
        for_task_types=None,
        options=None,
        passthru_args=None,
        target_roots=None,
        console_outstream=None,
        workspace=None,
        for_subsystems=None,
    ):

        optionables = set()
        extra_scopes = set()

        for_subsystems = for_subsystems or ()
        for subsystem in for_subsystems:
            if subsystem.options_scope is None:
                raise TaskError("You must set a scope on your subsystem type before using it in tests.")
            optionables.add(subsystem)

        for_task_types = for_task_types or ()
        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.")
            optionables.add(task_type)
            extra_scopes.update([si.scope for si in task_type.known_scope_infos()])
            optionables.update(
                Subsystem.closure(
                    set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()])
                    | self._build_configuration.subsystems()
                )
            )

        # Now default the option values and override with any caller-specified values.
        # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
        options = options.copy() if options else {}
        for s, opts in self.options.items():
            scoped_opts = options.setdefault(s, {})
            scoped_opts.update(opts)

        option_values = create_options_for_optionables(optionables, extra_scopes=extra_scopes, options=options)

        context = create_context(
            options=option_values,
            passthru_args=passthru_args,
            target_roots=target_roots,
            build_graph=self.build_graph,
            build_file_parser=self.build_file_parser,
            address_mapper=self.address_mapper,
            console_outstream=console_outstream,
            workspace=workspace,
        )
        Subsystem._options = context.options
        return context
开发者ID:slyphon,项目名称:pants,代码行数:57,代码来源:base_test.py

示例8: _setup_options

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def _setup_options(self, options_bootstrapper, working_set):
    # TODO: This inline import is currently necessary to resolve a ~legitimate cycle between
    # `GoalRunner`->`EngineInitializer`->`OptionsInitializer`->`GoalRunner`.
    from pants.bin.goal_runner import GoalRunner

    bootstrap_options = options_bootstrapper.get_bootstrap_options()
    global_bootstrap_options = bootstrap_options.for_global_scope()

    if global_bootstrap_options.pants_version != pants_version():
      raise BuildConfigurationError(
        'Version mismatch: Requested version was {}, our version is {}.'.format(
          global_bootstrap_options.pants_version, pants_version()
        )
      )

    # Get logging setup prior to loading backends so that they can log as needed.
    if self._init_logging:
      self._setup_logging(global_bootstrap_options)

    # Add any extra paths to python path (e.g., for loading extra source backends).
    for path in global_bootstrap_options.pythonpath:
      sys.path.append(path)
      pkg_resources.fixup_namespace_packages(path)

    # Load plugins and backends.
    plugins = global_bootstrap_options.plugins
    backend_packages = global_bootstrap_options.backend_packages
    build_configuration = load_plugins_and_backends(plugins, working_set, backend_packages)

    # Now that plugins and backends are loaded, we can gather the known scopes.
    known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]

    # Add scopes for all needed subsystems via a union of all known subsystem sets.
    subsystems = Subsystem.closure(
      GoalRunner.subsystems() | Goal.subsystems() | build_configuration.subsystems()
    )
    for subsystem in subsystems:
      known_scope_infos.append(subsystem.get_scope_info())

    # Add scopes for all tasks in all goals.
    for goal in Goal.all():
      known_scope_infos.extend(filter(None, goal.known_scope_infos()))

    # Now that we have the known scopes we can get the full options.
    options = options_bootstrapper.get_full_options(known_scope_infos)
    self._register_options(subsystems, options)

    # Make the options values available to all subsystems.
    Subsystem.set_options(options)

    return options, build_configuration
开发者ID:anubnair,项目名称:pants,代码行数:53,代码来源:options_initializer.py

示例9: context

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def context(self, for_task_types=None, options=None, passthru_args=None, target_roots=None,
              console_outstream=None, workspace=None, for_subsystems=None):
    """
    :API: public
    """
    # Many tests use source root functionality via the SourceRootConfig.global_instance()
    # (typically accessed via Target.target_base), so we always set it up, for convenience.
    optionables = {SourceRootConfig}
    extra_scopes = set()

    for_subsystems = for_subsystems or ()
    for subsystem in for_subsystems:
      if subsystem.options_scope is None:
        raise TaskError('You must set a scope on your subsystem type before using it in tests.')
      optionables.add(subsystem)

    for_task_types = for_task_types or ()
    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.')
      optionables.add(task_type)
      extra_scopes.update([si.scope for si in task_type.known_scope_infos()])
      optionables.update(Subsystem.closure(
        set([dep.subsystem_cls for dep in task_type.subsystem_dependencies_iter()]) |
            self._build_configuration.subsystems()))

    # Now default the option values and override with any caller-specified values.
    # TODO(benjy): Get rid of the options arg, and require tests to call set_options.
    options = options.copy() if options else {}
    for s, opts in self.options.items():
      scoped_opts = options.setdefault(s, {})
      scoped_opts.update(opts)

    options = create_options_for_optionables(optionables,
                                             extra_scopes=extra_scopes,
                                             options=options)

    Subsystem.reset(reset_options=True)
    Subsystem.set_options(options)

    context = create_context(options=options,
                             passthru_args=passthru_args,
                             target_roots=target_roots,
                             build_graph=self.build_graph,
                             build_file_parser=self.build_file_parser,
                             address_mapper=self.address_mapper,
                             console_outstream=console_outstream,
                             workspace=workspace)
    return context
开发者ID:adamchainz,项目名称:pants,代码行数:52,代码来源:base_test.py

示例10: _setup_options

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def _setup_options(self, options_bootstrapper, working_set):
    bootstrap_options = options_bootstrapper.get_bootstrap_options()
    global_bootstrap_options = bootstrap_options.for_global_scope()

    # The pants_version may be set in pants.ini for bootstrapping, so we make sure the user actually
    # requested the version on the command line before deciding to print the version and exit.
    if global_bootstrap_options.is_flagged('pants_version'):
      print(global_bootstrap_options.pants_version)
      self._exiter(0)

    # Get logging setup prior to loading backends so that they can log as needed.
    self._setup_logging(global_bootstrap_options)

    # Add any extra paths to python path (e.g., for loading extra source backends).
    for path in global_bootstrap_options.pythonpath:
      sys.path.append(path)
      pkg_resources.fixup_namespace_packages(path)

    # Load plugins and backends.
    plugins = global_bootstrap_options.plugins
    backend_packages = global_bootstrap_options.backend_packages
    build_configuration = load_plugins_and_backends(plugins, working_set, backend_packages)

    # Now that plugins and backends are loaded, we can gather the known scopes.
    known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]

    # Add scopes for all needed subsystems via a union of all known subsystem sets.
    subsystems = Subsystem.closure(
      GoalRunner.subsystems() | Goal.subsystems() | build_configuration.subsystems()
    )
    for subsystem in subsystems:
      known_scope_infos.append(subsystem.get_scope_info())

    # Add scopes for all tasks in all goals.
    for goal in Goal.all():
      known_scope_infos.extend(filter(None, goal.known_scope_infos()))

    # Now that we have the known scopes we can get the full options.
    options = options_bootstrapper.get_full_options(known_scope_infos)
    self._register_options(subsystems, options)

    # Make the options values available to all subsystems.
    Subsystem.set_options(options)

    return options, build_configuration
开发者ID:megaserg,项目名称:pants,代码行数:47,代码来源:goal_runner.py

示例11: _options

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def _options(self):
    # NB: The PluginResolver runs very early in the pants startup sequence before the standard
    # Subsystem facility is wired up.  As a result PluginResolver is not itself a Subsystem with
    # PythonRepos as a dependency.  Instead it does the minimum possible work to hand-roll
    # bootstrapping of the Subsystem it needs.
    subsystems = Subsystem.closure([PythonRepos])
    known_scope_infos = [subsystem.get_scope_info() for subsystem in subsystems]
    options = self._options_bootstrapper.get_full_options(known_scope_infos)

    # Ignore command line flags since we'd blow up on any we don't understand (most of them).
    # If someone wants to bootstrap plugins in a one-off custom way they'll need to use env vars
    # or a --pants-config-files pointing to a custom pants.ini snippet.
    defaulted_only_options = options.drop_flag_values()

    GlobalOptionsRegistrar.register_options_on_scope(defaulted_only_options)
    for subsystem in subsystems:
      subsystem.register_options_on_scope(defaulted_only_options)
    return defaulted_only_options
开发者ID:benjyw,项目名称:pants,代码行数:20,代码来源:plugin_resolver.py

示例12: test_closure_simple

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
 def test_closure_simple(self):
   self.assertEqual({DummySubsystem}, Subsystem.closure((DummySubsystem,)))
开发者ID:grimreaper,项目名称:pants,代码行数:4,代码来源:test_subsystem.py

示例13: setup

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
  def setup(self, options_bootstrapper, working_set):
    bootstrap_options = options_bootstrapper.get_bootstrap_options()
    global_bootstrap_options = bootstrap_options.for_global_scope()

    # The pants_version may be set in pants.ini for bootstrapping, so we make sure the user actually
    # requested the version on the command line before deciding to print the version and exit.
    if global_bootstrap_options.is_flagged('pants_version'):
      print(global_bootstrap_options.pants_version)
      self._exiter(0)

    # Get logging setup prior to loading backends so that they can log as needed.
    self._setup_logging(global_bootstrap_options)

    # Add any extra paths to python path (e.g., for loading extra source backends).
    for path in global_bootstrap_options.pythonpath:
      sys.path.append(path)
      pkg_resources.fixup_namespace_packages(path)

    # Load plugins and backends.
    plugins = global_bootstrap_options.plugins
    backend_packages = global_bootstrap_options.backend_packages
    build_configuration = load_plugins_and_backends(plugins, working_set, backend_packages)

    # Now that plugins and backends are loaded, we can gather the known scopes.
    self.targets = []

    known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]

    # Add scopes for all needed subsystems.
    subsystems = Subsystem.closure(set(self.subsystems) |
                                   Goal.subsystems() |
                                   build_configuration.subsystems())
    for subsystem in subsystems:
      known_scope_infos.append(subsystem.get_scope_info())

    # Add scopes for all tasks in all goals.
    for goal in Goal.all():
      known_scope_infos.extend(filter(None, goal.known_scope_infos()))

    # Now that we have the known scopes we can get the full options.
    self.options = options_bootstrapper.get_full_options(known_scope_infos)
    self.register_options(subsystems)

    # Make the options values available to all subsystems.
    Subsystem._options = self.options

    # Now that we have options we can instantiate subsystems.
    self.run_tracker = RunTracker.global_instance()
    self.reporting = Reporting.global_instance()
    report = self.reporting.initial_reporting(self.run_tracker)
    self.run_tracker.start(report)
    url = self.run_tracker.run_info.get_info('report_url')
    if url:
      self.run_tracker.log(Report.INFO, 'See a report at: {}'.format(url))
    else:
      self.run_tracker.log(Report.INFO, '(To run a reporting server: ./pants server)')

    self.build_file_parser = BuildFileParser(build_configuration=build_configuration,
                                             root_dir=self.root_dir,
                                             run_tracker=self.run_tracker)

    rev = self.options.for_global_scope().build_file_rev
    if rev:
      ScmBuildFile.set_rev(rev)
      ScmBuildFile.set_scm(get_scm())
      build_file_type = ScmBuildFile
    else:
      build_file_type = FilesystemBuildFile
    self.address_mapper = BuildFileAddressMapper(self.build_file_parser, build_file_type)
    self.build_graph = BuildGraph(run_tracker=self.run_tracker,
                                  address_mapper=self.address_mapper)

    # TODO(John Sirois): Kill when source root registration is lifted out of BUILD files.
    with self.run_tracker.new_workunit(name='bootstrap', labels=[WorkUnitLabel.SETUP]):
      source_root_bootstrapper = SourceRootBootstrapper.global_instance()
      source_root_bootstrapper.bootstrap(self.address_mapper, self.build_file_parser)

    self._expand_goals_and_specs()

    # Now that we've parsed the bootstrap BUILD files, and know about the SCM system.
    self.run_tracker.run_info.add_scm_info()
开发者ID:tsdeng,项目名称:pants,代码行数:83,代码来源:goal_runner.py

示例14: test_closure_simple

# 需要导入模块: from pants.subsystem.subsystem import Subsystem [as 别名]
# 或者: from pants.subsystem.subsystem.Subsystem import closure [as 别名]
 def test_closure_simple(self):
   self.assertEqual({DummySubsystem}, Subsystem.closure((DummySubsystem,)))
   self.assertEqual({DummySubsystem, ScopedDependentSubsystem},
                    Subsystem.closure((ScopedDependentSubsystem,)))
开发者ID:benjyw,项目名称:pants,代码行数:6,代码来源:test_subsystem.py


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