Beispiel #1
0
    def __init__(self, name, dependencies, is_meta):
        Target.__init__(self, name, is_meta)

        self._injected_deps = []
        self.processed_dependencies = resolve(dependencies)

        self.add_label('internal')
        self.dependency_addresses = OrderedSet()
        self.dependencies = OrderedSet()
        self.internal_dependencies = OrderedSet()
        self.jar_dependencies = OrderedSet()

        # TODO(John Sirois): if meta targets were truly built outside parse contexts - we could instead
        # just use the more general check: if parsing: delay(doit) else: doit()
        # Fix how target _ids are built / addresses to not require a BUILD file - ie: support anonymous,
        # non-addressable targets - which is what meta-targets really are once created.
        if is_meta:
            # Meta targets are built outside any parse context - so update dependencies immediately
            self.update_dependencies(self.processed_dependencies)
        else:
            # Defer dependency resolution after parsing the current BUILD file to allow for forward
            # references
            self._post_construct(self.update_dependencies,
                                 self.processed_dependencies)

        self._post_construct(self.inject_dependencies)
Beispiel #2
0
  def __init__(self, name, binary, bundles, basename=None):
    """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param binary: The :class:`twitter.pants.targets.jvm_binary.JvmBinary`,
      or a :class:`twitter.pants.targets.pants_target.Pants` pointer to one.
    :param bundles: One or more :class:`twitter.pants.targets.jvm_binary.Bundle`'s
      describing "extra files" that should be included with this app
      (e.g.: config files, startup scripts).
    :param string basename: Name of this application, if different from the
      ``name``. Pants uses this in the ``bundle`` goal to name the distribution
      artifact. In most cases this parameter is not necessary.
    """
    super(JvmApp, self).__init__(name, dependencies=[])

    self._binaries = maybe_list(
        util.resolve(binary),
        expected_type=(Pants, JarLibrary, JvmBinary),
        raise_type=partial(TargetDefinitionException, self))

    self._bundles = maybe_list(bundles, expected_type=Bundle,
                               raise_type=partial(TargetDefinitionException, self))

    if name == basename:
      raise TargetDefinitionException(self, 'basename must not equal name.')
    self.basename = basename or name

    self._resolved_binary = None
    self._resolved_bundles = []
Beispiel #3
0
  def __init__(self, name, dependencies, is_meta):
    Target.__init__(self, name, is_meta)

    self._injected_deps = []
    self.processed_dependencies = resolve(dependencies)

    self.add_label('internal')
    self.dependency_addresses = OrderedSet()
    self.dependencies = OrderedSet()
    self.internal_dependencies = OrderedSet()
    self.jar_dependencies = OrderedSet()

    # TODO(John Sirois): if meta targets were truly built outside parse contexts - we could instead
    # just use the more general check: if parsing: delay(doit) else: doit()
    # Fix how target _ids are built / addresses to not require a BUILD file - ie: support anonymous,
    # non-addressable targets - which is what meta-targets really are once created.
    if is_meta:
      # Meta targets are built outside any parse context - so update dependencies immediately
      self.update_dependencies(self.processed_dependencies)
    else:
      # Defer dependency resolution after parsing the current BUILD file to allow for forward
      # references
      self._post_construct(self.update_dependencies, self.processed_dependencies)

    self._post_construct(self.inject_dependencies)
Beispiel #4
0
    def __init__(self, name, binary, bundles, basename=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param binary: The :class:`twitter.pants.targets.jvm_binary.JvmBinary`,
      or a :class:`twitter.pants.targets.pants_target.Pants` pointer to one.
    :param bundles: One or more :class:`twitter.pants.targets.jvm_binary.Bundle`'s
      describing "extra files" that should be included with this app
      (e.g.: config files, startup scripts).
    :param string basename: Name of this application, if different from the
      ``name``. Pants uses this in the ``bundle`` goal to name the distribution
      artifact. In most cases this parameter is not necessary.
    """
        super(JvmApp, self).__init__(name, dependencies=[])

        self._binaries = maybe_list(
            util.resolve(binary),
            expected_type=(Pants, JarLibrary, JvmBinary),
            raise_type=partial(TargetDefinitionException, self))

        self._bundles = maybe_list(bundles,
                                   expected_type=Bundle,
                                   raise_type=partial(
                                       TargetDefinitionException, self))

        if name == basename:
            raise TargetDefinitionException(self,
                                            'basename must not equal name.')
        self.basename = basename or name

        self._resolved_binary = None
        self._resolved_bundles = []
Beispiel #5
0
 def testMixedList(self):
   self.assertEquals(
     resolve([MockPantsTarget("1"), "2", MockPantsTarget("3"), "4", "5"], clazz=MockPantsTarget),
     [MockPantsTarget("1"),
      MockPantsTarget("2"),
      MockPantsTarget("3"),
      MockPantsTarget("4"),
      MockPantsTarget("5")])
Beispiel #6
0
  def __init__(self, name, sources, resources=None, dependencies=None):
    TargetWithSources.__init__(self, name)

    processed_dependencies = resolve(dependencies)

    self.add_label('python')
    self.sources = self._resolve_paths(self.target_base, sources)
    self.resources = self._resolve_paths(self.target_base, resources) if resources else OrderedSet()
    self.dependencies = OrderedSet(processed_dependencies) if processed_dependencies else OrderedSet()
Beispiel #7
0
  def __init__(self, name, dependencies):
    """name: The name of this module target, addressable via pants via the portion of the spec
        following the colon
    dependencies: one or more JarDependencies this JarLibrary bundles or Pants pointing to other
        JarLibraries or JavaTargets"""

    assert len(dependencies) > 0, "At least one dependency must be specified"
    Target.__init__(self, name, False)
    self.add_label('jars')
    self.dependencies = resolve(dependencies)
Beispiel #8
0
 def testNonTarget(self):
     self.assertEquals(
         resolve([
             MockPantsTarget(1),
             [4, 'asdf'],
             "qwer",
         ],
                 clazz=MockPantsTarget), [
                     MockPantsTarget(1), [4, MockPantsTarget('asdf')],
                     MockPantsTarget('qwer')
                 ])
Beispiel #9
0
 def testMixedList(self):
     self.assertEquals(
         resolve(
             [MockPantsTarget("1"), "2",
              MockPantsTarget("3"), "4", "5"],
             clazz=MockPantsTarget), [
                 MockPantsTarget("1"),
                 MockPantsTarget("2"),
                 MockPantsTarget("3"),
                 MockPantsTarget("4"),
                 MockPantsTarget("5")
             ])
Beispiel #10
0
    def __init__(self, name, sources, resources=None, dependencies=None):
        TargetWithSources.__init__(self, name)

        processed_dependencies = resolve(dependencies)

        self.add_label('python')
        self.sources = self._resolve_paths(self.target_base, sources)
        self.resources = self._resolve_paths(
            self.target_base, resources) if resources else OrderedSet()
        self.dependencies = OrderedSet(
            processed_dependencies) if processed_dependencies else OrderedSet(
            )
Beispiel #11
0
    def __init__(self, name, dependencies):
        """name: The name of this module target, addressable via pants via the portion of the spec
        following the colon
    dependencies: one or more JarDependencies this JarLibrary bundles or Pants pointing to other
        JarLibraries or JavaTargets"""

        assert len(
            dependencies) > 0, "At least one dependency must be specified"
        Target.__init__(self, name, False)
        self.add_label('jars')
        self.dependencies = resolve(dependencies)
        self.dependency_addresses = set()
        for dependency in self.dependencies:
            if hasattr(dependency, 'address'):
                self.dependency_addresses.add(dependency.address)
Beispiel #12
0
    def __init__(self,
                 name,
                 sources=None,
                 java_sources=None,
                 provides=None,
                 dependencies=None,
                 excludes=None,
                 resources=None,
                 exclusives=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param sources: A list of filenames representing the source code
      this library is compiled from.
    :type sources: list of strings
    :param java_sources:
      :class:`twitter.pants.targets.java_library.JavaLibrary` or list of
      JavaLibrary targets this library has a circular dependency on.
      Prefer using dependencies to express non-circular dependencies.
    :param Artifact provides:
      The :class:`twitter.pants.targets.artifact.Artifact`
      to publish that represents this target outside the repo.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param resources: An optional list of paths (DEPRECATED) or ``resources``
      targets containing resources that belong on this library's classpath.
    :param exclusives: An optional list of exclusives tags.
    """
        super(ScalaLibrary, self).__init__(name,
                                           sources,
                                           provides,
                                           dependencies,
                                           excludes,
                                           exclusives=exclusives)

        if (sources is None) and (resources is None):
            raise TargetDefinitionException(
                self, 'Must specify sources and/or resources.')

        self.resources = resources

        self._java_sources = []
        self._raw_java_sources = util.resolve(java_sources)

        self.add_labels('scala')
Beispiel #13
0
  def __init__(self,
               name,
               sources=None,
               java_sources=None,
               provides=None,
               dependencies=None,
               excludes=None,
               resources=None,
               exclusives=None):
    """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param sources: A list of filenames representing the source code
      this library is compiled from.
    :type sources: list of strings
    :param java_sources:
      :class:`twitter.pants.targets.java_library.JavaLibrary` or list of
      JavaLibrary targets this library has a circular dependency on.
      Prefer using dependencies to express non-circular dependencies.
    :param Artifact provides:
      The :class:`twitter.pants.targets.artifact.Artifact`
      to publish that represents this target outside the repo.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :type dependencies: list of targets
    :param excludes: List of :class:`twitter.pants.targets.exclude.Exclude` instances
      to filter this target's transitive dependencies against.
    :param resources: An optional list of paths (DEPRECATED) or ``resources``
      targets containing resources that belong on this library's classpath.
    :param exclusives: An optional list of exclusives tags.
    """
    super(ScalaLibrary, self).__init__(
        name,
        sources,
        provides,
        dependencies,
        excludes,
        exclusives=exclusives)

    if (sources is None) and (resources is None):
      raise TargetDefinitionException(self, 'Must specify sources and/or resources.')

    self.resources = resources

    self._java_sources = []
    self._raw_java_sources = util.resolve(java_sources)

    self.add_labels('scala')
Beispiel #14
0
  def __init__(self, org, name, repo, description=None):
    """
      :org the originization of this artifact, the group id in maven parlance
      :name the name of the artifact
      :repo the repository this artifact is published to
      :description a description of this artifact
    """

    self.org = org
    self.name = name
    self.rev = None
    repos = list(resolve(repo).resolve())
    if len(repos) != 1:
      raise Exception("An artifact must have exactly 1 repo, given: %s" % repos)
    self.repo = repos[0]
    self.description = description
Beispiel #15
0
    def __init__(self, org, name, repo, description=None):
        """
      :org the originization of this artifact, the group id in maven parlance
      :name the name of the artifact
      :repo the repository this artifact is published to
      :description a description of this artifact
    """

        self.org = org
        self.name = name
        self.rev = None
        repos = list(resolve(repo).resolve())
        if len(repos) != 1:
            raise Exception("An artifact must have exactly 1 repo, given: %s" %
                            repos)
        self.repo = repos[0]
        self.description = description
Beispiel #16
0
    def __init__(self, name, binary, bundles, basename=None):
        InternalTarget.__init__(self, name, dependencies=[])

        if not binary:
            raise TargetDefinitionException(self, 'binary is required')

        binaries = list(filter(is_concrete, util.resolve(binary).resolve()))
        if len(binaries) != 1 or not isinstance(binaries[0], JvmBinary):
            raise TargetDefinitionException(
                self, 'must supply exactly 1 JvmBinary, got %s' % binary)
        self.binary = binaries[0]

        self._post_construct(self.update_dependencies, binaries)

        if not bundles:
            raise TargetDefinitionException(self, 'bundles must be specified')

        def is_resolvable(item):
            return hasattr(item, 'resolve')

        def is_bundle(bundle):
            return isinstance(bundle, Bundle)

        def resolve(item):
            return list(item.resolve()) if is_resolvable(item) else [None]

        if is_resolvable(bundles):
            bundles = resolve(bundles)

        self.bundles = []
        try:
            for item in iter(bundles):
                for bundle in resolve(item):
                    if not is_bundle(bundle):
                        raise TypeError()
                    self.bundles.append(bundle)
        except TypeError:
            raise TargetDefinitionException(
                self, 'bundles must be one or more Bundle objects, '
                'got %s' % bundles)

        self.basename = basename or name
Beispiel #17
0
  def __init__(self, name, binary, bundles, basename=None):
    InternalTarget.__init__(self, name, dependencies=[])

    if not binary:
      raise TargetDefinitionException(self, 'binary is required')

    binaries = [t for t in util.resolve(binary).resolve() if t.is_concrete]

    if len(binaries) != 1 or not isinstance(binaries[0], JvmBinary):
      raise TargetDefinitionException(self, 'must supply exactly 1 JvmBinary, got %s' % binary)
    self.binary = binaries[0]

    self._post_construct(self.update_dependencies, binaries)

    if not bundles:
      raise TargetDefinitionException(self, 'bundles must be specified')

    def is_resolvable(item):
      return hasattr(item, 'resolve')

    def is_bundle(bundle):
      return isinstance(bundle, Bundle)

    def resolve(item):
      return list(item.resolve()) if is_resolvable(item) else [None]

    if is_resolvable(bundles):
      bundles = resolve(bundles)

    self.bundles = []
    try:
      for item in iter(bundles):
        for bundle in resolve(item):
          if not is_bundle(bundle):
            raise TypeError()
          self.bundles.append(bundle)
    except TypeError:
      raise TargetDefinitionException(self, 'bundles must be one or more Bundle objects, '
                                            'got %s' % bundles)

    self.basename = basename or name
Beispiel #18
0
  def __init__(self, name, dependencies, overrides=None, exclusives=None):
    """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :param overrides: List of strings, each of which will be recursively resolved to
      any targets that provide artifacts. Those artifacts will override corresponding
      direct/transitive dependencies in the dependencies list.
    :param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
    """
    super(JarLibrary, self).__init__(name, exclusives=exclusives)

    self._pre_override_dependencies = OrderedSet(
        maybe_list(util.resolve(dependencies),
                   expected_type=(ExternalDependency, AnonymousDeps, Target),
                   raise_type=partial(TargetDefinitionException, self)))
    self._dependencies = None
    self._dependency_addresses = None
    self.override_targets = set(map(Pants, overrides or []))
    self.add_labels('jars')
Beispiel #19
0
    def __init__(self, name, dependencies, overrides=None, exclusives=None):
        """
    :param string name: The name of this target, which combined with this
      build file defines the target :class:`twitter.pants.base.address.Address`.
    :param dependencies: List of :class:`twitter.pants.base.target.Target` instances
      this target depends on.
    :param overrides: List of strings, each of which will be recursively resolved to
      any targets that provide artifacts. Those artifacts will override corresponding
      direct/transitive dependencies in the dependencies list.
    :param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
    """
        super(JarLibrary, self).__init__(name, exclusives=exclusives)

        self._pre_override_dependencies = OrderedSet(
            maybe_list(util.resolve(dependencies),
                       expected_type=(ExternalDependency, AnonymousDeps,
                                      Target),
                       raise_type=partial(TargetDefinitionException, self)))
        self._dependencies = None
        self._dependency_addresses = None
        self.override_targets = set(map(Pants, overrides or []))
        self.add_labels('jars')
Beispiel #20
0
 def resources(self, resources):
   self._resources = []
   self._raw_resources = util.resolve(resources)
Beispiel #21
0
 def testUnicodeString(self):
   self.assertEquals(resolve(u"asdf", clazz=MockPantsTarget).foo, u"asdf")
Beispiel #22
0
 def inject_dependencies(self):
   self.update_dependencies(resolve(self._injected_deps))
Beispiel #23
0
 def testNone(self):
     self.assertEquals(resolve(None, clazz=MockPantsTarget), None)
Beispiel #24
0
 def resources(self, resources):
     self._resources = []
     self._raw_resources = util.resolve(resources)
Beispiel #25
0
 def testNonTarget(self):
   self.assertEquals(
     resolve([MockPantsTarget(1), [4, 'asdf'], "qwer",], clazz=MockPantsTarget),
     [MockPantsTarget(1), [4, MockPantsTarget('asdf')], MockPantsTarget('qwer')])
Beispiel #26
0
 def testNone(self):
   self.assertEquals(resolve(None, clazz=MockPantsTarget), None)
Beispiel #27
0
 def testPantsTarget(self):
   self.assertEquals(resolve(MockPantsTarget("asdf"), clazz=MockPantsTarget).foo, "asdf")
Beispiel #28
0
 def testPantsTarget(self):
     self.assertEquals(
         resolve(MockPantsTarget("asdf"), clazz=MockPantsTarget).foo,
         "asdf")
Beispiel #29
0
 def testString(self):
   self.assertEquals(resolve("asdf", clazz=MockPantsTarget).foo, "asdf")
Beispiel #30
0
 def testString(self):
     self.assertEquals(resolve("asdf", clazz=MockPantsTarget).foo, "asdf")
Beispiel #31
0
 def testUnicodeString(self):
     self.assertEquals(resolve(u"asdf", clazz=MockPantsTarget).foo, u"asdf")
Beispiel #32
0
 def inject_dependencies(self):
     self.update_dependencies(resolve(self._injected_deps))