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 = Address.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 assert_files(self, lang, rel_path, contents, service_writer, expected_files): assert_list(expected_files) with temporary_file() as fp: fp.write(contents) fp.close() self.assertEqual(set(expected_files), calculate_genfiles(fp.name, rel_path, service_writer)[lang])
def test_valid_inputs(self): list_result0 = assert_list(["file1.txt"]) list_result1 = assert_list(["file1.txt", "file2.txt"]) list_result2 = assert_list(None) self.assertEqual(list_result0, ["file1.txt"]) # list of strings gives list of strings self.assertEqual(list_result1, ["file1.txt", "file2.txt"]) self.assertEqual(list_result2, []) # None is ok by default
def __init__(self, payload=None, service_writer=None, service_writer_options=None, service_factory=None, service_factory_options=None, roots=None, registry_class=None, enum_options=None, no_options=None, **kwargs): """ :param string service_writer: the name of the class to pass as the --service_writer option to the Wire compiler (For wire 1.x compatibility) :param list service_writer_options: A list of options to pass to the service writer (For wire 1.x compatibility) :param string service_factory: the name of the class to pass as the --service_factory option to the Wire compiler :param list service_factory_options: A list of options to pass to the service factory :param list roots: passed through to the --roots option of the Wire compiler :param string registry_class: fully qualified class name of RegistryClass to create. If in doubt, specify com.squareup.wire.SimpleServiceWriter :param list enum_options: list of enums to pass to as the --enum-enum_options option, # optional :param boolean no_options: boolean that determines if --no_options flag is passed """ if service_writer and service_factory: raise TargetDefinitionException( self, 'Specify only one of "service_writer" (wire 1.x only) or "service_factory"') if not service_writer and service_writer_options: raise TargetDefinitionException(self, 'service_writer_options requires setting service_writer') if not service_factory and service_factory_options: raise TargetDefinitionException(self, 'service_factory_options requires setting service_factory') payload = payload or Payload() payload.add_fields({ 'service_writer': PrimitiveField(service_writer or None), 'service_writer_options': PrimitiveField( assert_list(service_writer_options, key_arg='service_writer_options', raise_type=TargetDefinitionException)), 'service_factory': PrimitiveField(service_factory or None), 'service_factory_options': PrimitiveField( assert_list(service_factory_options, key_arg='service_factory_options', raise_type=TargetDefinitionException)), 'roots': PrimitiveField(roots or []), 'registry_class': PrimitiveField(registry_class or None), 'enum_options': PrimitiveField(enum_options or []), 'no_options': PrimitiveField(no_options or False), }) super(JavaWireLibrary, self).__init__(payload=payload, **kwargs) self.add_labels('codegen')
def __init__(self, payload=None, requirements=None, **kwargs): """ :param requirements: pip requirements :type requirements: List of :ref:`python_requirement <bdict_python_requirement>`\s """ payload = payload or Payload() assert_list(requirements, expected_type=PythonRequirement) payload.add_fields({ 'requirements': PythonRequirementsField(requirements or []), }) super(PythonRequirementLibrary, self).__init__(payload=payload, **kwargs)
def __init__(self, payload=None, requirements=None, **kwargs): """ :param requirements: pip requirements as `python_requirement <#python_requirement>`_\\s. :type requirements: List of python_requirement calls """ payload = payload or Payload() assert_list(requirements, expected_type=PythonRequirement, key_arg='requirements') payload.add_fields({ 'requirements': PythonRequirementsField(requirements or []), }) super(PythonRequirementLibrary, self).__init__(payload=payload, **kwargs)
def __init__(self, payload=None, packages=None, **kwargs): """ :param list packages: the `ConanRequirement`s to resolve into a `packaged_native_library()` target. """ payload = payload or Payload() assert_list(packages, key_arg='packages', expected_type=ConanRequirement, raise_type=self._DeprecatedStringPackage) payload.add_fields({ 'packages': ConanRequirementSetField(packages), }) super(ExternalNativeLibrary, self).__init__(payload=payload, **kwargs)
def __init__(self, payload=None, packages=None, **kwargs): """ :param packages: a list of Conan-style package strings Example: lzo/2.10@twitter/stable """ payload = payload or Payload() assert_list(packages, key_arg='packages') payload.add_fields({ 'packages': PrimitiveField(packages), }) super(ExternalNativeLibrary, self).__init__(payload=payload, **kwargs)
def __init__(self, user_id=None, name=None, email=None, url=None, organization=None, organization_url=None, roles=None): """One of `user_id`, `name`, or `email` is required, all other parameters are optional. :param string user_id: The user id of the developer; typically the one used to access the scm. :param string name: The developer's full name. :param string email: the developer's email address. :param string url: An optional url pointing to more information about the developer. :param string organization: An optional name for the organization the developer works on the library for. :param string organization_url: An optional url pointing to more information about the developer's organization. :param list roles: An optional list of role names that apply to this developer on this project. """ if not (user_id or name or email): raise ValueError( "At least one of 'user_id', 'name' or 'email' must be specified for each " "developer.") self.user_id = _validate_maybe_string('user_id', user_id) self.name = _validate_maybe_string('name', name) self.email = _validate_maybe_string('email', email) self.url = _validate_maybe_string('url', url) self.organization = _validate_maybe_string('organization', organization) self.organization_url = _validate_maybe_string('organization_url', organization_url) self.roles = assert_list(roles, key_arg='roles')
def skip_signatures_and_duplicates_concat_well_known_metadata( cls, default_dup_action=None, additional_rules=None): """Produces a rule set useful in many deploy jar creation contexts. The rule set skips duplicate entries by default, retaining the 1st encountered. In addition it has the following special handling: - jar signature metadata is dropped - ``java.util.ServiceLoader`` provider-configuration files are concatenated in the order encountered :param default_dup_action: An optional default action to take for duplicates. Defaults to `Duplicate.SKIP` if not specified. :param additional_rules: Optionally one or more jar rules to add to those described above. :returns: JarRules """ default_dup_action = Duplicate.validate_action(default_dup_action or Duplicate.SKIP) additional_rules = assert_list(additional_rules, expected_type=(Duplicate, Skip)) rules = [ Skip(r'^META-INF/[^/]+\.SF$'), # signature file Skip(r'^META-INF/[^/]+\.DSA$'), # default signature alg. file Skip(r'^META-INF/[^/]+\.RSA$'), # default signature alg. file Duplicate(r'^META-INF/services/', Duplicate.CONCAT) ] # 1 svc fqcn per line return cls(rules=rules + additional_rules, default_dup_action=default_dup_action)
def assert_list(self, putative_list, expected_type=string_types, key_arg=None): """ :API: public """ return assert_list( putative_list, expected_type, key_arg=key_arg, raise_type=lambda msg: TargetDefinitionException(self, msg) )
def skip_signatures_and_duplicates_concat_well_known_metadata(cls, default_dup_action=None, additional_rules=None): """Produces a rule set useful in many deploy jar creation contexts. The rule set skips duplicate entries by default, retaining the 1st encountered. In addition it has the following special handling: - jar signature metadata is dropped - ``java.util.ServiceLoader`` provider-configuration files are concatenated in the order encountered :param default_dup_action: An optional default action to take for duplicates. Defaults to `Duplicate.SKIP` if not specified. :param additional_rules: Optionally one or more jar rules to add to those described above. :returns: JarRules """ default_dup_action = Duplicate.validate_action(default_dup_action or Duplicate.SKIP) additional_rules = assert_list(additional_rules, expected_type=(Duplicate, Skip)) rules = [Skip(r'^META-INF/[^/]+\.SF$'), # signature file Skip(r'^META-INF/[^/]+\.DSA$'), # default signature alg. file Skip(r'^META-INF/[^/]+\.RSA$'), # default signature alg. file Duplicate(r'^META-INF/services/', Duplicate.CONCAT)] # 1 svc fqcn per line return JarRules(rules=rules + additional_rules, default_dup_action=default_dup_action)
def test_invalid_inputs(self): with self.assertRaises(ValueError): assert_list({"file2.txt": True}) # Can't pass a dict by default with self.assertRaises(ValueError): assert_list([["file2.txt"], "file2.txt"]) # All values in list must be stringy values with self.assertRaises(ValueError): assert_list(None, can_be_none=False) # The default is ok as None only when can_be_noe is true with self.assertRaises(ValueError): assert_list(["file.txt"], allowable=(set,)) # Incorrect type
def __init__(self, payload=None, packages=None, **kwargs): """ :param list packages: the `ConanRequirement`s to resolve into a `packaged_native_library()` target. """ payload = payload or Payload() assert_list( packages, key_arg="packages", expected_type=ConanRequirement, raise_type=self._DeprecatedStringPackage, ) payload.add_fields({ "packages": ConanRequirementSetField(packages), }) super().__init__(payload=payload, **kwargs)
def assert_list(self, putative_list, expected_type=str, key_arg=None): """ :API: public """ return assert_list( putative_list, expected_type, key_arg=key_arg, raise_type=lambda msg: TargetDefinitionException(self, msg))
def assert_list(self, maybe_list, expected_type=string_types, key_arg=None): return assert_list( maybe_list, expected_type, key_arg=key_arg, raise_type=lambda msg: TargetDefinitionException(self, msg))
def __init__(self, sources_rel_path, sources, ref_address=None): """ :param sources_rel_path: path that sources parameter may be relative to :param sources: list of strings representing relative file paths :param ref_address: optional address spec of target that provides these sources """ self._rel_path = sources_rel_path self._source_paths = assert_list(sources) self._ref_address = ref_address
def __init__(self, rules=None, default_dup_action=Duplicate.SKIP): """Creates a new set of jar rules with the default duplicate action of ``Duplicate.SKIP``. :param rules: One or more rules that will be applied in order to jar entries being packaged in a deploy jar. :param default_dup_action: The default action to take when a duplicate entry is encountered and no explicit rules apply to the entry. """ self._default_dup_action = Duplicate.validate_action(default_dup_action) self._rules = assert_list(rules, expected_type=JarRule)
def __init__(self, rules=None, default_dup_action=Duplicate.SKIP): """Creates a new set of jar rules with the default duplicate action of ``Duplicate.SKIP``. :param rules: One or more rules that will be applied in order to jar entries being packaged in a deploy jar. `Skip <#Skip>`_ rules can go here. :param default_dup_action: The default action to take when a duplicate entry is encountered and no explicit rules apply to the entry. """ self._default_dup_action = Duplicate.validate_action(default_dup_action) self._rules = assert_list(rules, expected_type=JarRule)
def __init__(self, sources_rel_path=None, sources=None, provides=None, excludes=None, configurations=None): super(JvmTargetPayload, self).__init__(sources_rel_path, assert_list(sources)) self.provides = provides self.excludes = OrderedSet(excludes) self.configurations = OrderedSet(configurations)
def _prepare_excludes(excludes): return tuple( assert_list(excludes, expected_type=Exclude, can_be_none=True, key_arg='excludes', allowable=( tuple, list, )))
def parse(self, content): """Parse raw response content for a list of remote artifact cache URLs.""" if self.format == 'json_map': try: return assert_list(json.loads(content.decode(self.encoding))[self.index]) except (KeyError, UnicodeDecodeError, ValueError) as e: raise self.ResponseParserError("Error while parsing response content: {0}".format(str(e))) # Should never get here. raise ValueError('Unknown content format: "{}"'.format(self.format))
def __init__(self, sources_rel_path, sources, ref_address=None, filespec=None): """ :param sources_rel_path: path that sources parameter may be relative to :param sources: list of strings representing relative file paths :param ref_address: optional address spec of target that provides these sources :param filespec: glob and exclude data that generated this set of sources """ self._rel_path = sources_rel_path self._source_paths = assert_list(sources, key_arg='sources') self._ref_address = ref_address self._filespec = filespec
def __init__(self, rules=None, default_dup_action=Duplicate.SKIP): """Creates a new set of jar rules with the default duplicate action of ``Duplicate.SKIP``. :param rules: One or more rules that will be applied in order to jar entries being packaged in a deploy jar. `Skip <#Skip>`_ rules can go here. :param default_dup_action: The default action to take when a duplicate entry is encountered and no explicit rules apply to the entry. """ self.payload = Payload() self.payload.add_fields({"default_dup_action": PrimitiveField(Duplicate.validate_action(default_dup_action))}) self._rules = assert_list(rules, expected_type=JarRule, key_arg="rules")
def __init__(self, payload=None, packages=None, **kwargs): """ :param list packages: the `ConanRequirement`s to resolve into a `packaged_native_library()` target. """ payload = payload or Payload() try: assert_list(packages, key_arg='packages', expected_type=ConanRequirement, raise_type=self._DeprecatedStringPackage) except self._DeprecatedStringPackage as e: warn_or_error('1.16.0.dev1', 'Raw strings as conan package descriptors', hint='Use conan_requirement(...) instead! Error was: {}'.format(str(e)), stacklevel=2, context=0) packages = [ConanRequirement(s) if not isinstance(s, ConanRequirement) else s for s in packages] payload.add_fields({ 'packages': ConanRequirementSetField(packages), }) super(ExternalNativeLibrary, self).__init__(payload=payload, **kwargs)
def parse(self, content): """Parse raw response content for a list of remote artifact cache URLs.""" if self.format == 'json_map': try: return assert_list( json.loads(content.decode(self.encoding))[self.index]) except (KeyError, UnicodeDecodeError, ValueError) as e: raise self.ResponseParserError( "Error while parsing response content: {0}".format(str(e))) # Should never get here. raise ValueError('Unknown content format: "{}"'.format(self.format))
def __init__(self, payload=None, service_writer=None, service_writer_options=None, roots=None, registry_class=None, enum_options=None, no_options=None, ordered_sources=None, **kwargs): """ :param string service_writer: the name of the class to pass as the --service_writer option to the Wire compiler (For wire 1.0 only) :param list service_writer_options: A list of options to pass to the service writer (For wire 1.x only) :param list roots: passed through to the --roots option of the Wire compiler :param string registry_class: fully qualified class name of RegistryClass to create. If in doubt, specify com.squareup.wire.SimpleServiceWriter :param list enum_options: list of enums to pass to as the --enum-enum_options option, # optional :param boolean no_options: boolean that determines if --no_options flag is passed :param boolean ordered_sources: boolean that declares whether the sources argument represents literal ordered sources to be passed directly to the compiler. If false, no ordering is guaranteed for the sources passed to an individual compiler invoke. """ if not service_writer and service_writer_options: raise TargetDefinitionException( self, "service_writer_options requires setting service_writer") payload = payload or Payload() payload.add_fields({ "service_writer": PrimitiveField(service_writer or None), "service_writer_options": PrimitiveField( assert_list( service_writer_options, key_arg="service_writer_options", raise_type=TargetDefinitionException, )), "roots": PrimitiveField(roots or []), "registry_class": PrimitiveField(registry_class or None), "enum_options": PrimitiveField(enum_options or []), "no_options": PrimitiveField(no_options or False), "ordered_sources": PrimitiveField(ordered_sources or False), }) super().__init__(payload=payload, **kwargs)
def __init__(self, org, name, rev=None, force=False, ext=None, url=None, apidocs=None, classifier=None, mutable=None, intransitive=False, excludes=None): """ :param string org: The Maven ``groupId`` of this dependency. :param string name: The Maven ``artifactId`` of this dependency. :param string rev: The Maven ``version`` of this dependency. If unspecified the latest available version is used. :param boolean force: Force this specific artifact revision even if other transitive dependencies specify a different revision. This requires specifying the ``rev`` parameter. :param string ext: Extension of the artifact if different from the artifact type. This is sometimes needed for artifacts packaged with Maven bundle type but stored as jars. :param string url: URL of this artifact, if different from the Maven repo standard location (specifying this parameter is unusual). :param string apidocs: URL of existing javadocs, which if specified, pants-generated javadocs will properly hyperlink {\ @link}s. :param string classifier: Classifier specifying the artifact variant to use. :param boolean mutable: Inhibit caching of this mutable artifact. A common use is for Maven -SNAPSHOT style artifacts in an active development/integration cycle. :param boolean intransitive: Declares this Dependency intransitive, indicating only the jar for the dependency itself should be downloaded and placed on the classpath :param list excludes: Transitive dependencies of this jar to exclude. :type excludes: list of :class:`pants.backend.jvm.targets.exclude.Exclude` """ self.org = org self._base_name = name self.rev = rev self.force = force self.ext = ext self.url = url self.apidocs = apidocs self.classifier = classifier self.transitive = not intransitive self.mutable = mutable self.excludes = tuple( assert_list(excludes, expected_type=Exclude, can_be_none=True, key_arg='excludes', allowable=( tuple, list, )))
def test_invalid_inputs_with_key_arg(self): with self.assertRaisesRegexp(ValueError, "In key 'resources':"): assert_list({"file3.txt": "source"}, key_arg='resources') # Can't pass a dict with self.assertRaisesRegexp(ValueError, "In key 'artifacts':"): assert_list([["file3.txt"]], key_arg='artifacts') # All values most be strings with self.assertRaisesRegexp(ValueError, "In key 'jars':"): assert_list(None, can_be_none=False, key_arg='jars') # The default is ok as None only when can_be_none is true
def populate(self, sources, rel_path=None): """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._rel_path = rel_path self._source_paths = assert_list(sources, key_arg='sources') self._populated = True
def test_additional_allowables(self): def generator(): for x in range(11): yield str(x) assert_list(generator(), allowable_add=(GeneratorType,)) assert_list(['1', '2'], allowable_add=(GeneratorType,)) with self.assertRaises(ValueError): assert_list(generator(), allowable_add=[])
def __call__(self, rel_path=None, mapper=None, relative_to=None, fileset=None): """ :param rel_path: Base path of the "source" file paths. By default, path of the BUILD file. Useful for assets that don't live in the source code repo. :param mapper: Function that takes a path string and returns a path string. Takes a path in the source tree, returns a path to use in the resulting bundle. By default, an identity mapper. :param string relative_to: Set up a simple mapping from source path to bundle path. :param fileset: The set of files to include in the bundle. A string filename, or list of filenames, or a Fileset object (e.g. globs()). E.g., ``relative_to='common'`` removes that prefix from all files in the application bundle. """ if fileset is None: raise ValueError( "In {}:\n Bare bundle() declarations without a `fileset=` parameter " "are no longer supported.".format( self._parse_context.rel_path)) if mapper and relative_to: raise ValueError( "Must specify exactly one of 'mapper' or 'relative_to'") if rel_path and isinstance( fileset, FilesetWithSpec) and fileset.rel_root != rel_path: raise ValueError( "Must not use a glob for 'fileset' with 'rel_path'." " Globs are eagerly evaluated and ignore 'rel_path'.") # A fileset is either a glob, a string or a list of strings. if isinstance(fileset, FilesetWithSpec): pass elif isinstance(fileset, six.string_types): fileset = [fileset] else: fileset = assert_list(fileset, key_arg='fileset') real_rel_path = rel_path or self._parse_context.rel_path if relative_to: base = os.path.join(get_buildroot(), real_rel_path, relative_to) mapper = RelativeToMapper(base) else: mapper = mapper or RelativeToMapper( os.path.join(get_buildroot(), real_rel_path)) return BundleProps(real_rel_path, mapper, fileset)
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 = Address.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, payload=None, service_writer=None, service_writer_options=None, roots=None, registry_class=None, enum_options=None, no_options=None, **kwargs): """ :param string service_writer: the name of the class to pass as the --service_writer option to the Wire compiler (For wire 1.0 only) :param list service_writer_options: A list of options to pass to the service writer (For wire 1.x only) :param list roots: passed through to the --roots option of the Wire compiler :param string registry_class: fully qualified class name of RegistryClass to create. If in doubt, specify com.squareup.wire.SimpleServiceWriter :param list enum_options: list of enums to pass to as the --enum-enum_options option, # optional :param boolean no_options: boolean that determines if --no_options flag is passed """ if not service_writer and service_writer_options: raise TargetDefinitionException( self, 'service_writer_options requires setting service_writer') payload = payload or Payload() payload.add_fields({ 'service_writer': PrimitiveField(service_writer or None), 'service_writer_options': PrimitiveField( assert_list(service_writer_options, key_arg='service_writer_options', raise_type=TargetDefinitionException)), 'roots': PrimitiveField(roots or []), 'registry_class': PrimitiveField(registry_class or None), 'enum_options': PrimitiveField(enum_options or []), 'no_options': PrimitiveField(no_options or False), }) super(JavaWireLibrary, self).__init__(payload=payload, **kwargs) self.add_labels('codegen')
def __init__(self, org, name, rev=None, force=False, ext=None, url=None, apidocs=None, type_=None, classifier=None, mutable=None, intransitive=False, excludes=None): """ :param string org: The Maven ``groupId`` of this dependency. :param string name: The Maven ``artifactId`` of this dependency. :param string rev: The Maven ``version`` of this dependency. If unspecified the latest available version is used. :param boolean force: Force this specific artifact revision even if other transitive dependencies specify a different revision. This requires specifying the ``rev`` parameter. :param string ext: Extension of the artifact if different from the artifact type. This is sometimes needed for artifacts packaged with Maven bundle type but stored as jars. :param string url: URL of this artifact, if different from the Maven repo standard location (specifying this parameter is unusual). :param string apidocs: URL of existing javadocs, which if specified, pants-generated javadocs will properly hyperlink {\ @link}s. :param string type_: Artifact packaging type - Deprecated: use `ext` instead. :param string classifier: Classifier specifying the artifact variant to use. :param boolean mutable: Inhibit caching of this mutable artifact. A common use is for Maven -SNAPSHOT style artifacts in an active development/integration cycle. :param boolean intransitive: Declares this Dependency intransitive, indicating only the jar for the dependency itself should be downloaded and placed on the classpath :param list excludes: Transitive dependencies of this jar to exclude. :type excludes: list of :class:`pants.backend.jvm.targets.exclude.Exclude` """ self.org = org self._base_name = name self.rev = rev self.force = force self.ext = ext if type_: self._maybe_set_ext(type_) self.url = url self.apidocs = apidocs self.classifier = classifier self.transitive = not intransitive self.mutable = mutable self.excludes = tuple(assert_list(excludes, expected_type=Exclude, can_be_none=True, key_arg='excludes', allowable=(tuple, list,)))
def __call__(self, rel_path=None, mapper=None, relative_to=None, fileset=None): """ :param rel_path: Base path of the "source" file paths. By default, path of the BUILD file. Useful for assets that don't live in the source code repo. :param mapper: Function that takes a path string and returns a path string. Takes a path in the source tree, returns a path to use in the resulting bundle. By default, an identity mapper. :param string relative_to: Set up a simple mapping from source path to bundle path. :param fileset: The set of files to include in the bundle. A string filename, or list of filenames, or a Fileset object (e.g. globs()). E.g., ``relative_to='common'`` removes that prefix from all files in the application bundle. """ if fileset is None: raise ValueError( "In {}:\n Bare bundle() declarations without a `fileset=` parameter " "are no longer supported.".format(self._rel_path) ) if mapper and relative_to: raise ValueError("Must specify exactly one of 'mapper' or 'relative_to'") if rel_path and isinstance(fileset, FilesetWithSpec) and fileset.rel_root != rel_path: raise ValueError( "Must not use a glob for 'fileset' with 'rel_path'." " Globs are eagerly evaluated and ignore 'rel_path'." ) # A fileset is either a glob, a string or a list of strings. if isinstance(fileset, FilesetWithSpec): pass elif isinstance(fileset, six.string_types): fileset = [fileset] else: fileset = assert_list(fileset, key_arg="fileset") real_rel_path = rel_path or self._rel_path if relative_to: base = os.path.join(get_buildroot(), real_rel_path, relative_to) mapper = RelativeToMapper(base) else: mapper = mapper or RelativeToMapper(os.path.join(get_buildroot(), real_rel_path)) return BundleProps(real_rel_path, mapper, fileset)
def __init__(self, payload=None, service_writer=None, service_writer_options=None, roots=None, registry_class=None, enum_options=None, no_options=None, ordered_sources=None, **kwargs): """ :param string service_writer: the name of the class to pass as the --service_writer option to the Wire compiler (For wire 1.0 only) :param list service_writer_options: A list of options to pass to the service writer (For wire 1.x only) :param list roots: passed through to the --roots option of the Wire compiler :param string registry_class: fully qualified class name of RegistryClass to create. If in doubt, specify com.squareup.wire.SimpleServiceWriter :param list enum_options: list of enums to pass to as the --enum-enum_options option, # optional :param boolean no_options: boolean that determines if --no_options flag is passed :param boolean ordered_sources: boolean that declares whether the sources argument represents literal ordered sources to be passed directly to the compiler. If false, no ordering is guaranteed for the sources passed to an individual compiler invoke. """ if not service_writer and service_writer_options: raise TargetDefinitionException(self, 'service_writer_options requires setting service_writer') payload = payload or Payload() payload.add_fields({ 'service_writer': PrimitiveField(service_writer or None), 'service_writer_options': PrimitiveField( assert_list(service_writer_options, key_arg='service_writer_options', raise_type=TargetDefinitionException)), 'roots': PrimitiveField(roots or []), 'registry_class': PrimitiveField(registry_class or None), 'enum_options': PrimitiveField(enum_options or []), 'no_options': PrimitiveField(no_options or False), 'ordered_sources': PrimitiveField(ordered_sources or False), }) super(JavaWireLibrary, self).__init__(payload=payload, **kwargs)
def __init__(self, user_id=None, name=None, email=None, url=None, organization=None, organization_url=None, roles=None): """One of `user_id`, `name`, or `email` is required, all other parameters are optional. :param string user_id: The user id of the developer; typically the one used to access the scm. :param string name: The developer's full name. :param string email: the developer's email address. :param string url: An optional url pointing to more information about the developer. :param string organization: An optional name for the organization the developer works on the library for. :param string organization_url: An optional url pointing to more information about the developer's organization. :param list roles: An optional list of role names that apply to this developer on this project. """ if not (user_id or name or email): raise ValueError("At least one of 'user_id', 'name' or 'email' must be specified for each " "developer.") self.user_id = _validate_maybe_string('user_id', user_id) self.name = _validate_maybe_string('name', name) self.email = _validate_maybe_string('email', email) self.url = _validate_maybe_string('url', url) self.organization = _validate_maybe_string('organization', organization) self.organization_url = _validate_maybe_string('organization_url', organization_url) self.roles = assert_list(roles)
def assert_list(self, maybe_list, expected_type=string_types, key_arg=None): return assert_list(maybe_list, expected_type, key_arg=key_arg, raise_type=lambda msg: TargetDefinitionException(self, msg))
def assert_list(self, maybe_list, expected_type=Compatibility.string): return assert_list(maybe_list, expected_type, raise_type=lambda msg: TargetDefinitionException(self, msg))
def assert_files(self, task, rel_path, contents, expected_files): assert_list(expected_files) with temporary_file() as fp: fp.write(contents) fp.close() self.assertEqual(set(expected_files), set(task.calculate_genfiles(fp.name, rel_path)))
def _validate_source_paths(self, sources): if isinstance(sources, FilesetWithSpec): return sources else: return assert_list(sources, key_arg='sources')
def __init__(self, org, name, rev=None, force=False, ext=None, url=None, apidocs=None, type_=None, classifier=None, mutable=None, artifacts=None, intransitive=False): """ :param string org: The Maven ``groupId`` of this dependency. :param string name: The Maven ``artifactId`` of this dependency. :param string rev: The Maven ``version`` of this dependency. If unspecified the latest available version is used. :param boolean force: Force this specific artifact revision even if other transitive dependencies specify a different revision. This requires specifying the ``rev`` parameter. :param string ext: Extension of the artifact if different from the artifact type. This is sometimes needed for artifacts packaged with Maven bundle type but stored as jars. :param string url: URL of this artifact, if different from the Maven repo standard location (specifying this parameter is unusual). :param string apidocs: URL of existing javadocs, which if specified, pants-generated javadocs will properly hyperlink {\ @link}s. :param string type_: Artifact packaging type. :param string classifier: Classifier specifying the artifact variant to use. Use multiple ``with_artifact`` statements to include multiple artifacts of the same org.name, but with different classifiers. :param boolean mutable: Inhibit caching of this mutable artifact. A common use is for Maven -SNAPSHOT style artifacts in an active development/integration cycle. :param list artifacts: A list of additional IvyArtifacts :param boolean intransitive: Declares this Dependency intransitive, indicating only the jar for the dependency itself should be downloaded and placed on the classpath """ self.org = org self.name = name self.rev = rev self.force = force self.excludes = tuple() self.transitive = not intransitive self.apidocs = apidocs self.mutable = mutable self.artifacts = tuple(assert_list(artifacts, expected_type=IvyArtifact, key_arg='artifacts')) if ext or url or type_ or classifier: self.append_artifact(name, type_=type_, ext=ext, url=url, classifier=classifier) self._configurations = ('default',) # Support legacy method names # TODO(John Sirois): introduce a deprecation cycle for these and then kill self.withSources = self.with_sources self.withDocs = self.with_docs if classifier: self.classifier = classifier elif len(self.artifacts) == 1: self.classifier = self.artifacts[0].classifier else: self.classifier = None self._coordinates = (self.org, self.name, self.rev) if self.classifier: self._coordinates += (self.classifier,) if not self.classifier and len(self.artifacts) > 1: raise ValueError('Cannot determine classifier. No explicit classifier is set and this jar ' 'has more than 1 artifact: {}\n\t{}'.format(self, '\n\t'.join(map(str, self.artifacts))))
def __init__(self, sources_rel_path, sources): self.rel_path = sources_rel_path self.source_paths = assert_list(sources)
def __init__(self, sources_rel_path, sources): self.sources_rel_path = sources_rel_path self.sources = assert_list(sources) self.excludes = OrderedSet()
def assert_list(self, maybe_list, expected_type=Compatibility.string): return assert_list( maybe_list, expected_type, raise_type=lambda msg: TargetDefinitionException(self, msg))
def _prepare_excludes(excludes): return tuple(assert_list(excludes, expected_type=Exclude, can_be_none=True, key_arg='excludes', allowable=(tuple, list,)))
def validate_nonempty_list(list_name, item, expected_type): assert_list(item, expected_type=expected_type, can_be_none=False, allowable=(list,)) if not item: raise ValueError('At least 1 entry is required in the {} list.'.format(list_name)) return item
def make_artifacts(): return tuple( assert_list(artifacts, expected_type=IvyArtifact, key_arg='artifacts'))