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


Python subsystem.Subsystem类代码示例

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


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

示例1: mk_cache

 def mk_cache(spec):
   Subsystem.reset()
   self.set_options_for_scope(CacheSetup.subscope(DummyTask.options_scope),
                              read_from=spec, compression=1)
   self.context(for_task_types=[DummyTask])  # Force option initialization.
   cache_factory = CacheSetup.create_cache_factory_for_task(DummyTask)
   return cache_factory.get_read_cache()
开发者ID:Gabriel439,项目名称:pants,代码行数:7,代码来源:test_cache_setup.py

示例2: init_subsystems

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,代码行数:34,代码来源:subsystem_util.py

示例3: _install_options

  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,代码行数:31,代码来源:options_initializer.py

示例4: setUp

  def setUp(self):
    super(BaseTest, self).setUp()
    Goal.clear()
    Subsystem.reset()

    self.real_build_root = BuildRoot().path

    self.build_root = os.path.realpath(mkdtemp(suffix='_BUILD_ROOT'))
    self.addCleanup(safe_rmtree, self.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
    self.addCleanup(BuildRoot().reset)

    # We need a pants.ini, even if empty. get_buildroot() uses its presence.
    self.create_file('pants.ini')
    self._build_configuration = BuildConfiguration()
    self._build_configuration.register_aliases(self.alias_groups)
    self.build_file_parser = BuildFileParser(self._build_configuration, self.build_root)
    self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
    self.build_graph = BuildGraph(address_mapper=self.address_mapper)
开发者ID:jduan,项目名称:pants,代码行数:32,代码来源:base_test.py

示例5: tearDown

 def tearDown(self):
   """
   :API: public
   """
   super(BaseTest, self).tearDown()
   BuildFile.clear_cache()
   Subsystem.reset()
开发者ID:benjyw,项目名称:pants,代码行数:7,代码来源:base_test.py

示例6: context

  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,代码行数:60,代码来源:base_test.py

示例7: _install_options

  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.

    # Gather the optionables that are not scoped to any other.  All known scopes are reachable
    # via these optionables' known_scope_infos() methods.
    top_level_optionables = ({GlobalOptionsRegistrar} |
                             GoalRunner.subsystems() |
                             build_configuration.subsystems() |
                             set(Goal.get_optionables()))

    known_scope_infos = sorted({
      si for optionable in top_level_optionables for si in optionable.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)

    distinct_optionable_classes = sorted({si.optionable_cls for si in known_scope_infos},
                                         key=lambda o: o.options_scope)
    for optionable_cls in distinct_optionable_classes:
      optionable_cls.register_options_on_scope(options)

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

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

示例8: subsystem_instance

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,代码行数:30,代码来源:subsystem_util.py

示例9: create

  def create(cls, options_bootstrapper, build_configuration, init_subsystems=True):
    global_bootstrap_options = options_bootstrapper.get_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())
      )

    pants_runtime_python_version = global_bootstrap_options.pants_runtime_python_version
    current_python_version = '.'.join(map(str, sys.version_info[0:2]))
    if pants_runtime_python_version and pants_runtime_python_version != current_python_version:
      raise BuildConfigurationError(
        'Running Pants with a different Python interpreter version than requested. '
        'You requested {}, but are running with {}.\n\n'
        'Note that Pants cannot use the value you give for `--pants-runtime-python-version` to '
        'dynamically change the interpreter it uses, as it is too late for it to change once the program '
        'is already running. Instead, your setup script (e.g. `./pants`) must configure which Python '
        'interpreter and virtualenv to use. For example, the setup script we distribute '
        'at https://www.pantsbuild.org/install.html#recommended-installation will read the '
        '`pants_runtime_python_version` defined in your pants.ini to determine which Python '
        'version to run with.'.format(pants_runtime_python_version, current_python_version)
      )

    # Parse and register options.
    options = cls._construct_options(options_bootstrapper, build_configuration)

    GlobalOptionsRegistrar.validate_instance(options.for_global_scope())

    if init_subsystems:
      Subsystem.set_options(options)

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

示例10: test_closure_cycle

  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,代码行数:25,代码来源:test_subsystem.py

示例11: select

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,代码行数:33,代码来源:binary_util.py

示例12: test_uninitialized_scoped_instance

  def test_uninitialized_scoped_instance(self):
    Subsystem.reset()

    class UninitializedOptional(Optionable):
      options_scope = 'optional'

    optional = UninitializedOptional()
    with self.assertRaisesRegexp(Subsystem.UninitializedSubsystemError,
                                 r'UninitializedSubsystem.*uninitialized-scope'):
      UninitializedSubsystem.scoped_instance(optional)
开发者ID:grimreaper,项目名称:pants,代码行数:10,代码来源:test_subsystem.py

示例13: _clean_runtime_state

  def _clean_runtime_state(self):
    """Resets the runtime state from running ./pants -> running in the fork()'d daemon context."""
    # TODO(kwlzn): Make this logic available to PantsRunner et al for inline state reset before
    # pants runs to improve testability and avoid potential bitrot.

    # Reset RunTracker state.
    RunTracker.global_instance().reset(reset_options=False)

    # Reset Subsystem options.
    Subsystem.set_options(None)

    # Reset Goals and Tasks.
    Goal.clear()
开发者ID:moshez,项目名称:pants,代码行数:13,代码来源:pants_daemon.py

示例14: _setup_options

  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,代码行数:51,代码来源:options_initializer.py

示例15: clean_global_runtime_state

def clean_global_runtime_state(reset_subsystem=False):
  """Resets the global runtime state of a pants runtime for cleaner forking.

  :param bool reset_subsystem: Whether or not to clean Subsystem global state.
  """
  if reset_subsystem:
    # Reset subsystem state.
    Subsystem.reset()

  # Reset Goals and Tasks.
  Goal.clear()

  # Reset backend/plugins state.
  OptionsInitializer.reset()
开发者ID:benjyw,项目名称:pants,代码行数:14,代码来源:util.py


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