예제 #1
0
  def create_sources_field(self, sources, sources_rel_path, address=None, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """

    if sources is None:
      sources = FilesetWithSpec.empty(sources_rel_path)
    elif isinstance(sources, FilesetWithSpec):
      pass
    elif isinstance(sources, (set, list, tuple)):
      # Received a literal sources list: convert to a FilesetWithSpec via Files.
      sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
    else:
      key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
      raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
                                            .format(key_arg_section, type(sources)))

    return SourcesField(sources=sources)
예제 #2
0
파일: target.py 프로젝트: Gointer/pants
  def create_sources_field(self, sources, sources_rel_path, address=None, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """

    if isinstance(sources, Addresses):
      # Currently, this is only created by the result of from_target() which takes a single argument
      if len(sources.addresses) != 1:
        raise self.WrongNumberOfAddresses(
          "Expected a single address to from_target() as argument to {spec}"
          .format(spec=address.spec))
      referenced_address = Address.parse(sources.addresses[0], relative_to=sources.rel_path)
      return DeferredSourcesField(ref_address=referenced_address)
    elif sources is None:
      sources = FilesetWithSpec.empty(sources_rel_path)
    elif not isinstance(sources, FilesetWithSpec):
      # Received a literal sources list: convert to a FilesetWithSpec via Files.
      sources = Files.create_fileset_with_spec(sources_rel_path, *sources)

    return SourcesField(sources=sources)
예제 #3
0
    def create_sources_field(self, sources, sources_rel_path, key_arg=None):
        """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """
        if sources is None:
            # Make sure we don't apply the defaulting to uses of this method other than for
            # creating a sources= field (e.g., we also use this for creating resources= fields).
            # Note that the check for supports_default_sources() precedes the subsystem check.
            # This is so that tests don't need to set up the subsystem when creating targets that
            # legitimately do not require sources.
            if ((key_arg is None or key_arg == 'sources')
                    and self.supports_default_sources() and self.Arguments.
                    global_instance().get_options().implicit_sources):
                sources = self.default_sources(sources_rel_path)
            else:
                sources = FilesetWithSpec.empty(sources_rel_path)
        elif isinstance(sources, (set, list, tuple)):
            # Received a literal sources list: convert to a FilesetWithSpec via Files.
            sources = Files.create_fileset_with_spec(sources_rel_path,
                                                     *sources)
        elif not isinstance(sources, FilesetWithSpec):
            key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
            raise TargetDefinitionException(
                self,
                "Expected {}a glob, an address or a list, but was {}".format(
                    key_arg_section, type(sources)))

        return SourcesField(sources=sources)
예제 #4
0
파일: target.py 프로젝트: lahosken/pants
  def create_sources_field(self, sources, sources_rel_path, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """
    if sources is None:
      # Make sure we don't apply the defaulting to uses of this method other than for
      # creating a sources= field (e.g., we also use this for creating resources= fields).
      # Note that the check for supports_default_sources() precedes the subsystem check.
      # This is so that tests don't need to set up the subsystem when creating targets that
      # legitimately do not require sources.
      if ((key_arg is None or key_arg == 'sources') and
          self.supports_default_sources() and
          self.Arguments.global_instance().get_options().implicit_sources):
        sources = self.default_sources(sources_rel_path)
      else:
        sources = FilesetWithSpec.empty(sources_rel_path)
    elif isinstance(sources, (set, list, tuple)):
      # Received a literal sources list: convert to a FilesetWithSpec via Files.
      sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
    elif not isinstance(sources, FilesetWithSpec):
      key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
      raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
                                            .format(key_arg_section, type(sources)))

    return SourcesField(sources=sources)
예제 #5
0
파일: target.py 프로젝트: CaitieM20/pants
  def create_sources_field(self, sources, sources_rel_path, address=None, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """

    if isinstance(sources, Addresses):
      # Currently, this is only created by the result of from_target() which takes a single argument
      if len(sources.addresses) != 1:
        key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
        spec_section = " to '{}'".format(address.spec) if address else ""
        raise self.WrongNumberOfAddresses(
          "Expected {key_arg_section}a single address to from_target() as argument{spec_section}"
          .format(key_arg_section=key_arg_section, spec_section=spec_section))
      referenced_address = Address.parse(sources.addresses[0], relative_to=sources.rel_path)
      return DeferredSourcesField(ref_address=referenced_address)
    elif sources is None:
      sources = FilesetWithSpec.empty(sources_rel_path)
    elif isinstance(sources, FilesetWithSpec):
      pass
    elif isinstance(sources, (set, list, tuple)):
      # Received a literal sources list: convert to a FilesetWithSpec via Files.
      sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
    else:
      key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
      raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
                                            .format(key_arg_section, type(sources)))

    return SourcesField(sources=sources)
예제 #6
0
    def create_sources_field(self,
                             sources,
                             sources_rel_path,
                             address=None,
                             key_arg=None):
        """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """

        if isinstance(sources, Addresses):
            # Currently, this is only created by the result of from_target() which takes a single argument
            if len(sources.addresses) != 1:
                raise self.WrongNumberOfAddresses(
                    "Expected a single address to from_target() as argument to {spec}"
                    .format(spec=address.spec))
            referenced_address = Address.parse(sources.addresses[0],
                                               relative_to=sources.rel_path)
            return DeferredSourcesField(ref_address=referenced_address)
        elif sources is None:
            sources = FilesetWithSpec.empty(sources_rel_path)
        elif not isinstance(sources, FilesetWithSpec):
            # Received a literal sources list: convert to a FilesetWithSpec via Files.
            sources = Files.create_fileset_with_spec(sources_rel_path,
                                                     *sources)

        return SourcesField(sources=sources)
예제 #7
0
  def create_sources_field(self, sources, sources_rel_path, address=None, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """

    if isinstance(sources, Addresses):
      # Currently, this is only created by the result of from_target() which takes a single argument
      if len(sources.addresses) != 1:
        key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
        spec_section = " to '{}'".format(address.spec) if address else ""
        raise self.WrongNumberOfAddresses(
          "Expected {key_arg_section}a single address to from_target() as argument{spec_section}"
          .format(key_arg_section=key_arg_section, spec_section=spec_section))
      referenced_address = Address.parse(sources.addresses[0], relative_to=sources.rel_path)
      return DeferredSourcesField(ref_address=referenced_address)
    elif sources is None:
      sources = FilesetWithSpec.empty(sources_rel_path)
    elif isinstance(sources, FilesetWithSpec):
      pass
    elif isinstance(sources, (set, list, tuple)):
      # Received a literal sources list: convert to a FilesetWithSpec via Files.
      sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
    else:
      key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
      raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
                                            .format(key_arg_section, type(sources)))

    return SourcesField(sources=sources)
예제 #8
0
파일: target.py 프로젝트: foursquare/pants
  def create_sources_field(self, sources, sources_rel_path, key_arg=None):
    """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """
    if sources is None:
      # Make sure we don't apply the defaulting to uses of this method other than for
      # creating a sources= field (e.g., we also use this for creating resources= fields).
      # Note that the check for supports_default_sources() precedes the subsystem check.
      # This is so that tests don't need to set up the subsystem when creating targets that
      # legitimately do not require sources.
      if (key_arg is None or key_arg == 'sources') and self.supports_default_sources():
        deprecated_conditional(
          lambda: True,
          '1.11.0.dev0',
          'Default sources should always be parsed through the engine not by create_sources_field. '
          'This code should be unreachable, and this message should never be displayed. '
          'If you see this message, please contact pants-dev. '
          'Class which caused this message: {}'.format(self.__class__.__name__)
        )
        sources = self.default_sources(sources_rel_path)
      else:
        sources = FilesetWithSpec.empty(sources_rel_path)
    elif isinstance(sources, (set, list, tuple)):
      if sources:
        # Received a literal sources list: convert to a FilesetWithSpec via Files.
        deprecated_conditional(
          lambda: True,
          '1.11.0.dev0',
          ('Passing collections as the value of the sources argument to create_sources_field is '
           'deprecated, and now takes a slow path. Instead, class {} should have its sources '
           'argument populated by the engine, either by using the standard parsing pipeline, or by '
           'requesting a SourcesField product from the v2 engine.').format(self.__class__.__name__)
        )
        sources = Files.create_fileset_with_spec(sources_rel_path, *sources)
      else:
        sources = FilesetWithSpec.empty(sources_rel_path)
    elif not isinstance(sources, FilesetWithSpec):
      key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
      raise TargetDefinitionException(self, "Expected {}a glob, an address or a list, but was {}"
                                            .format(key_arg_section, type(sources)))
    elif not isinstance(sources, EagerFilesetWithSpec):
      deprecated_conditional(
        lambda: True,
        '1.11.0.dev0',
        ('FilesetWithSpec sources values are deprecated except for EagerFilesetWithSpec values. '
         'Saw value of type {}').format(type(sources))
      )


    return SourcesField(sources=sources)
예제 #9
0
파일: target.py 프로젝트: ryokugyu/pants
    def create_sources_field(self, sources, sources_rel_path, key_arg=None):
        """Factory method to create a SourcesField appropriate for the type of the sources object.

    Note that this method is called before the call to Target.__init__ so don't expect fields to
    be populated!

    :API: public

    :return: a payload field object representing the sources parameter
    :rtype: SourcesField
    """
        if sources is None:
            # Make sure we don't apply the defaulting to uses of this method other than for
            # creating a sources= field (e.g., we also use this for creating resources= fields).
            # Note that the check for supports_default_sources() precedes the subsystem check.
            # This is so that tests don't need to set up the subsystem when creating targets that
            # legitimately do not require sources.
            if (key_arg is None or key_arg
                    == 'sources') and self.supports_default_sources():
                deprecated_conditional(
                    lambda: True, '1.11.0.dev0',
                    'Default sources should always be parsed through the engine not by create_sources_field. '
                    'This code should be unreachable, and this message should never be displayed. '
                    'If you see this message, please contact pants-dev. '
                    'Class which caused this message: {}'.format(
                        self.__class__.__name__))
                sources = self.default_sources(sources_rel_path)
            else:
                sources = FilesetWithSpec.empty(sources_rel_path)
        elif isinstance(sources, (set, list, tuple)):
            if sources:
                # Received a literal sources list: convert to a FilesetWithSpec via Files.
                deprecated_conditional(lambda: True, '1.11.0.dev0', (
                    'Passing collections as the value of the sources argument to create_sources_field is '
                    'deprecated, and now takes a slow path. Instead, class {} should have its sources '
                    'argument populated by the engine, either by using the standard parsing pipeline, or by '
                    'requesting a SourcesField product from the v2 engine.'
                ).format(self.__class__.__name__))
                sources = Files.create_fileset_with_spec(
                    sources_rel_path, *sources)
            else:
                sources = FilesetWithSpec.empty(sources_rel_path)
        elif not isinstance(sources, FilesetWithSpec):
            key_arg_section = "'{}' to be ".format(key_arg) if key_arg else ""
            raise TargetDefinitionException(
                self,
                "Expected {}a glob, an address or a list, but was {}".format(
                    key_arg_section, type(sources)))
        elif not isinstance(sources, EagerFilesetWithSpec):
            deprecated_conditional(lambda: True, '1.11.0.dev0', (
                'FilesetWithSpec sources values are deprecated except for EagerFilesetWithSpec values. '
                'Saw value of type {}').format(type(sources)))

        return SourcesField(sources=sources)
예제 #10
0
  def populate(self, sources, rel_path):
    """Call this method to set the list of files represented by the target.

    Intended to be invoked by the DeferredSourcesMapper task.
    :param list sources: strings representing paths of files to be included in the source set
    :param string rel_path: common prefix for files.
    """
    if self._populated:
      raise self.AlreadyPopulatedError("Called with rel_path={rel_path} sources={sources}"
      .format(rel_path=rel_path, sources=sources))
    self._populated = True
    sources = Files.create_fileset_with_spec(rel_path, *sources)
    self._sources = self._validate_sources(sources)
예제 #11
0
    def populate(self, sources, rel_path):
        """Call this method to set the list of files represented by the target.

    Intended to be invoked by the DeferredSourcesMapper task.
    :param list sources: strings representing absolute paths of files to be included in the source set
    :param string rel_path: common prefix for files.
    """
        if self._populated:
            raise self.AlreadyPopulatedError(
                "Called with rel_path={rel_path} sources={sources}".format(
                    rel_path=rel_path, sources=sources))
        self._populated = True
        sources = Files.create_fileset_with_spec(rel_path, *sources)
        self._sources = self._validate_sources(sources)
예제 #12
0
 def process_remote_sources(self):
   """Create synthetic targets with populated sources from remote_sources targets."""
   unpacked_sources = self.context.products.get_data('unpacked_archives')
   remote_sources_targets = self.context.targets(predicate=lambda t: isinstance(t, RemoteSources))
   for target in remote_sources_targets:
     sources, rel_unpack_dir = unpacked_sources[target.sources_target]
     synthetic_target = self.context.add_new_target(
       address=Address(os.path.relpath(self.workdir, get_buildroot()), target.id),
       target_type=target.destination_target_type,
       dependencies=target.dependencies,
       sources=Files.create_fileset_with_spec(rel_unpack_dir, *sources),
       derived_from=target,
       **target.destination_target_args
     )
     for dependent in self.context.build_graph.dependents_of(target.address):
       self.context.build_graph.inject_dependency(dependent, synthetic_target.address)