Example #1
0
    def create(cls, options, build_root=None, change_calculator=None):
        """
    :param Options options: An `Options` instance to use.
    :param string build_root: The build root.
    :param ChangeCalculator change_calculator: A `ChangeCalculator` for calculating changes.
    """
        # Determine the literal target roots.
        spec_roots = cls.parse_specs(options.target_specs, build_root)

        # Determine `Changed` arguments directly from options to support pre-`Subsystem`
        # initialization paths.
        changed_options = options.for_scope('changed')
        changed_request = ChangedRequest.from_options(changed_options)

        logger.debug('spec_roots are: %s', spec_roots)
        logger.debug('changed_request is: %s', changed_request)

        if change_calculator and changed_request.is_actionable():
            if spec_roots:
                # We've been provided spec roots (e.g. `./pants list ::`) AND a changed request. Error out.
                raise InvalidSpecConstraint(
                    'cannot provide changed parameters and target specs!')

            # We've been provided no spec roots (e.g. `./pants list`) AND a changed request. Compute
            # alternate target roots.
            changed_addresses = change_calculator.changed_target_addresses(
                changed_request)
            logger.debug('changed addresses: %s', changed_addresses)
            return TargetRoots(
                tuple(
                    SingleAddress(a.spec_path, a.target_name)
                    for a in changed_addresses))

        return TargetRoots(spec_roots)
    def create(cls, options, session, symbol_table, build_root=None):
        """
    :param Options options: An `Options` instance to use.
    :param session: The Scheduler session
    :param symbol_table: The symbol table
    :param string build_root: The build root.
    """
        # Determine the literal target roots.
        spec_roots = cls.parse_specs(options.target_specs, build_root)

        # Determine `Changed` arguments directly from options to support pre-`Subsystem`
        # initialization paths.
        changed_options = options.for_scope('changed')
        changed_request = ChangedRequest.from_options(changed_options)

        # Determine the `--owner-of=` arguments provided from the global options
        owned_files = options.for_global_scope().owner_of

        logger.debug('spec_roots are: %s', spec_roots)
        logger.debug('changed_request is: %s', changed_request)
        logger.debug('owned_files are: %s', owned_files)
        scm = get_scm()
        change_calculator = ChangeCalculator(session, symbol_table,
                                             scm) if scm else None
        owner_calculator = OwnerCalculator(
            session, symbol_table) if owned_files else None
        targets_specified = sum(1 for item in (changed_request.is_actionable(),
                                               owned_files, spec_roots)
                                if item)

        if targets_specified > 1:
            # We've been provided a more than one of: a change request, an owner request, or spec roots.
            raise InvalidSpecConstraint(
                'Multiple target selection methods provided. Please use only one of '
                '--changed-*, --owner-of, or target specs')

        if change_calculator and changed_request.is_actionable():
            # We've been provided no spec roots (e.g. `./pants list`) AND a changed request. Compute
            # alternate target roots.
            changed_addresses = change_calculator.changed_target_addresses(
                changed_request)
            logger.debug('changed addresses: %s', changed_addresses)
            return TargetRoots(
                tuple(
                    SingleAddress(a.spec_path, a.target_name)
                    for a in changed_addresses))

        if owner_calculator and owned_files:
            # We've been provided no spec roots (e.g. `./pants list`) AND a owner request. Compute
            # alternate target roots.
            owner_addresses = owner_calculator.owner_target_addresses(
                owned_files)
            logger.debug('owner addresses: %s', owner_addresses)
            return TargetRoots(
                tuple(
                    SingleAddress(a.spec_path, a.target_name)
                    for a in owner_addresses))

        return TargetRoots(spec_roots)
Example #3
0
  def _init_engine(cls):
    if cls._scheduler is not None:
      return

    graph_session = EngineInitializer.setup_legacy_graph(
      pants_ignore_patterns=None,
      workdir=cls._pants_workdir(),
      build_file_imports_behavior='allow',
      native=init_native(),
      build_file_aliases=cls.alias_groups(),
      build_ignore_patterns=None,
    ).new_session()
    cls._scheduler = graph_session.scheduler_session
    cls._build_graph, cls._address_mapper = graph_session.create_build_graph(
        TargetRoots([]), cls._build_root()
      )
Example #4
0
    def _init_engine(cls):
        if cls._scheduler is not None:
            return

        # NB: This uses the long form of initialization because it needs to directly specify
        # `cls.alias_groups` rather than having them be provided by bootstrap options.
        graph_session = EngineInitializer.setup_legacy_graph_extended(
            pants_ignore_patterns=None,
            workdir=cls._pants_workdir(),
            build_file_imports_behavior='allow',
            native=init_native(),
            build_configuration=cls.build_config(),
            build_ignore_patterns=None,
        ).new_session()
        cls._scheduler = graph_session.scheduler_session
        cls._build_graph, cls._address_mapper = graph_session.create_build_graph(
            TargetRoots([]), cls._build_root())
Example #5
0
    def _init_engine(cls):
        if cls._scheduler is not None:
            return

        cls._local_store_dir = os.path.realpath(safe_mkdtemp())
        safe_mkdir(cls._local_store_dir)

        # NB: This uses the long form of initialization because it needs to directly specify
        # `cls.alias_groups` rather than having them be provided by bootstrap options.
        graph_session = EngineInitializer.setup_legacy_graph_extended(
            pants_ignore_patterns=None,
            local_store_dir=cls._local_store_dir,
            build_file_imports_behavior='allow',
            native=init_native(),
            options_bootstrapper=OptionsBootstrapper.create(
                args=['--pants-config-files=[]']),
            build_configuration=cls.build_config(),
            build_ignore_patterns=None,
        ).new_session(zipkin_trace_v2=False)
        cls._scheduler = graph_session.scheduler_session
        cls._build_graph, cls._address_mapper = graph_session.create_build_graph(
            TargetRoots([]), cls._build_root())
Example #6
0
  def _init_engine(self, local_store_dir: Optional[str] = None) -> None:
    if self._scheduler is not None:
      return

    options_bootstrapper = OptionsBootstrapper.create(args=['--pants-config-files=[]'])
    local_store_dir = local_store_dir or options_bootstrapper.bootstrap_options.for_global_scope().local_store_dir

    # NB: This uses the long form of initialization because it needs to directly specify
    # `cls.alias_groups` rather than having them be provided by bootstrap options.
    graph_session = EngineInitializer.setup_legacy_graph_extended(
      pants_ignore_patterns=None,
      local_store_dir=local_store_dir,
      build_file_imports_behavior='allow',
      native=init_native(),
      options_bootstrapper=options_bootstrapper,
      build_root=self.build_root,
      build_configuration=self.build_config(),
      build_ignore_patterns=None,
    ).new_session(zipkin_trace_v2=False, build_id="buildid_for_test")
    self._scheduler = graph_session.scheduler_session
    self._build_graph, self._address_mapper = graph_session.create_build_graph(
        TargetRoots(AddressSpecs([])), self._build_root()
      )
    def create(cls,
               options,
               session,
               symbol_table,
               build_root=None,
               exclude_patterns=None,
               tags=None):
        """
    :param Options options: An `Options` instance to use.
    :param session: The Scheduler session
    :param symbol_table: The symbol table
    :param string build_root: The build root.
    """
        # Determine the literal target roots.
        spec_roots = cls.parse_specs(target_specs=options.target_specs,
                                     build_root=build_root,
                                     exclude_patterns=exclude_patterns,
                                     tags=tags)

        # Determine `Changed` arguments directly from options to support pre-`Subsystem`
        # initialization paths.
        changed_options = options.for_scope('changed')
        changed_request = ChangedRequest.from_options(changed_options)

        # Determine the `--owner-of=` arguments provided from the global options
        owned_files = options.for_global_scope().owner_of

        logger.debug('spec_roots are: %s', spec_roots)
        logger.debug('changed_request is: %s', changed_request)
        logger.debug('owned_files are: %s', owned_files)
        targets_specified = sum(1 for item in (changed_request.is_actionable(),
                                               owned_files, spec_roots)
                                if item)

        if targets_specified > 1:
            # We've been provided more than one of: a change request, an owner request, or spec roots.
            raise InvalidSpecConstraint(
                'Multiple target selection methods provided. Please use only one of '
                '--changed-*, --owner-of, or target specs')

        if changed_request.is_actionable():
            scm = get_scm()
            if not scm:
                raise InvalidSpecConstraint(
                    'The --changed-* options are not available without a recognized SCM (usually git).'
                )
            changed_files = cls.changed_files(
                scm,
                changes_since=changed_request.changes_since,
                diffspec=changed_request.diffspec)
            # We've been provided no spec roots (e.g. `./pants list`) AND a changed request. Compute
            # alternate target roots.
            request = OwnersRequest(sources=tuple(changed_files),
                                    include_dependees=str(
                                        changed_request.include_dependees))
            changed_addresses, = session.product_request(
                BuildFileAddresses, [request])
            logger.debug('changed addresses: %s', changed_addresses)
            dependencies = tuple(
                SingleAddress(a.spec_path, a.target_name)
                for a in changed_addresses)
            return TargetRoots([
                Specs(dependencies=dependencies,
                      exclude_patterns=exclude_patterns,
                      tags=tags)
            ])

        if owned_files:
            # We've been provided no spec roots (e.g. `./pants list`) AND a owner request. Compute
            # alternate target roots.
            request = OwnersRequest(sources=tuple(owned_files),
                                    include_dependees=str('none'))
            owner_addresses, = session.product_request(BuildFileAddresses,
                                                       [request])
            logger.debug('owner addresses: %s', owner_addresses)
            dependencies = tuple(
                SingleAddress(a.spec_path, a.target_name)
                for a in owner_addresses)
            return TargetRoots([
                Specs(dependencies=dependencies,
                      exclude_patterns=exclude_patterns,
                      tags=tags)
            ])

        return TargetRoots(spec_roots)