def test_sources_field(self): self.create_file('foo/bar/a.txt', 'a_contents') self.create_file('foo/bar/b.txt', 'b_contents') self.assertNotEqual( SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint(), SourcesField( sources_rel_path='foo/bar', sources=['b.txt'], ).fingerprint(), ) self.assertEqual( SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint(), SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint(), ) self.assertEqual( SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint(), SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint(), ) self.assertEqual( SourcesField( sources_rel_path='foo/bar', sources=['a.txt', 'b.txt'], ).fingerprint(), SourcesField( sources_rel_path='foo/bar', sources=['b.txt', 'a.txt'], ).fingerprint(), ) fp1 = SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint() self.create_file('foo/bar/a.txt', 'a_contents_different') fp2 = SourcesField( sources_rel_path='foo/bar', sources=['a.txt'], ).fingerprint() self.assertNotEqual(fp1, fp2)
def __init__(self, address=None, payload=None, source=None, links=None, resources=None, provides=None, **kwargs): """ :param source: Source of the page in markdown format. :param links: Other ``page`` targets that this `page` links to. :type links: List of target specs :param provides: Optional "Addresses" at which this page is published. E.g., a wiki location. :type provides: List of ``wiki_artifact``s :param resources: An optional list of Resources objects. """ payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(sources=[source], sources_rel_path=address.spec_path), 'links': PrimitiveField(links or []), 'provides': self.ProvidesTupleField(provides or []), }) self._resource_specs = resources or [] super(Page, self).__init__(address=address, payload=payload, **kwargs) if provides and not isinstance(provides[0], WikiArtifact): raise ValueError( 'Page must provide a wiki_artifact. Found instead: %s' % provides)
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! :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 = SyntheticAddress.parse(sources.addresses[0], relative_to=sources.rel_path) return DeferredSourcesField(ref_address=referenced_address) elif isinstance(sources, FilesetWithSpec): filespec = sources.filespec else: sources = sources or [] assert_list(sources, key_arg=key_arg) filespec = {'globs' : [os.path.join(sources_rel_path, src) for src in (sources or [])]} return SourcesField(sources=sources, sources_rel_path=sources_rel_path, filespec=filespec)
def __init__(self, address=None, payload=None, sources=None, **kwargs): """ :param sources: Files to "include". Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` or list of strings """ payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(sources=self.assert_list(sources), sources_rel_path=address.spec_path), }) super(Resources, self).__init__(address=address, payload=payload, **kwargs)
def __init__(self, address=None, payload=None, sources_rel_path=None, sources=None, provides=None, excludes=None, resources=None, configurations=None, no_cache=False, **kwargs): """ :param configurations: One or more ivy configurations to resolve for this target. This parameter is not intended for general use. :type configurations: tuple of strings :param excludes: List of `exclude <#exclude>`_\s to filter this target's transitive dependencies against. :param sources: Source code files to build. Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` (from globs or rglobs) or list of strings :param no_cache: If True, this should not be stored in the artifact cache """ if sources_rel_path is None: sources_rel_path = address.spec_path payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(sources=self.assert_list(sources), sources_rel_path=sources_rel_path), 'provides': provides, 'excludes': ExcludesField(self.assert_list(excludes, expected_type=Exclude)), 'configurations': ConfigurationsField(self.assert_list(configurations)), }) self._resource_specs = self.assert_list(resources) super(JvmTarget, self).__init__(address=address, payload=payload, **kwargs) self.add_labels('jvm') if no_cache: self.add_labels('no_cache')
def __init__(self, address=None, payload=None, source=None, format=None, links=None, resources=None, provides=None, **kwargs): """ :param source: Path to page source file. :param format: Page's format, ``md`` or ``rst``. By default, Pants infers from ``source`` file extension: ``.rst`` is ReStructured Text; anything else is Markdown. :param links: Other ``page`` targets that this `page` links to. :type links: List of target specs :param provides: Optional "Addresses" at which this page is published. E.g., a wiki location. :type provides: List of ``wiki_artifact``s :param resources: An optional list of Resources objects. """ payload = payload or Payload() if not format: if source and source.lower().endswith('.rst'): format = 'rst' else: format = 'md' payload.add_fields({ 'sources': SourcesField(sources=[source], sources_rel_path=address.spec_path), 'format': PrimitiveField(format), 'links': PrimitiveField(links or []), 'provides': self.ProvidesTupleField(provides or []), }) self._resource_specs = resources or [] super(Page, self).__init__(address=address, payload=payload, **kwargs) if provides and not isinstance(provides[0], WikiArtifact): raise ValueError( 'Page must provide a wiki_artifact. Found instead: %s' % provides)
def __init__(self, address=None, payload=None, sources_rel_path=None, sources=None, resources=None, # Old-style resources (file list, Fileset). resource_targets=None, # New-style resources (Resources target specs). provides=None, compatibility=None, **kwargs): """ :param dependencies: Other targets that this target depends on. These dependencies may be ``python_library``-like targets (``python_library``, ``python_thrift_library``, ``python_antlr_library`` and so forth) or ``python_requirement_library`` targets. :type dependencies: List of target specs :param sources: Files to "include". Paths are relative to the BUILD file's directory. :type sources: ``Fileset`` or list of strings :param resources: non-Python resources, e.g. templates, keys, other data (it is recommended that your application uses the pkgutil package to access these resources in a .zip-module friendly way.) :param provides: The `setup_py <#setup_py>`_ to publish that represents this target outside the repo. :param compatibility: either a string or list of strings that represents interpreter compatibility for this target, using the Requirement-style format, e.g. ``'CPython>=3', or just ['>=2.7','<3']`` for requirements agnostic to interpreter class. """ if sources_rel_path is None: sources_rel_path = address.spec_path payload = payload or Payload() payload.add_fields({ 'sources': SourcesField(sources=self.assert_list(sources), sources_rel_path=sources_rel_path), 'resources': SourcesField(sources=self.assert_list(resources), sources_rel_path=address.spec_path), 'provides': provides, 'compatibility': PrimitiveField(maybe_list(compatibility or ())), }) super(PythonTarget, self).__init__(address=address, payload=payload, **kwargs) self._resource_target_specs = resource_targets self.add_labels('python') self._synthetic_resources_target = None if provides and not isinstance(provides, PythonArtifact): raise TargetDefinitionException(self, "Target must provide a valid pants setup_py object. Received a '%s' object instead." % provides.__class__.__name__) self._provides = provides # Check that the compatibility requirements are well-formed. for req in self.payload.compatibility: try: PythonIdentity.parse_requirement(req) except ValueError as e: raise TargetDefinitionException(self, str(e))
def _make_payload_from_sources(self, sources): p = Payload() p.add_field('sources', SourcesField('', sources)) p.freeze() return p