本文整理汇总了Python中twitter.common.collections.maybe_list函数的典型用法代码示例。如果您正苦于以下问题:Python maybe_list函数的具体用法?Python maybe_list怎么用?Python maybe_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maybe_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _scrub_args
def _scrub_args(classpath, main, jvm_options, args, cwd):
classpath = maybe_list(classpath)
if not isinstance(main, string_types) or not main:
raise ValueError('A non-empty main classname is required, given: {}'.format(main))
jvm_options = maybe_list(jvm_options or ())
args = maybe_list(args or ())
return classpath, main, jvm_options, args, cwd
示例2: _scrub_args
def _scrub_args(classpath, main, jvm_options, args):
classpath = maybe_list(classpath)
if not isinstance(main, Compatibility.string) or not main:
raise ValueError('A non-empty main classname is required, given: %s' % main)
jvm_options = maybe_list(jvm_options or ())
args = maybe_list(args or ())
return classpath, main, jvm_options, args
示例3: __init__
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 = []
示例4: __init__
def __init__(self,
name,
sources,
dependencies,
excludes=None,
configurations=None,
exclusives=None):
"""
:param string name: The name of this target, which combined with this
build file defines the target :class:`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 dependencies: List of :class:`pants.base.target.Target` instances
this target depends on.
:type dependencies: list of targets
:param excludes: One or more :class:`pants.targets.exclude.Exclude` instances
to filter this target's transitive dependencies against.
: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
"""
InternalTarget.__init__(self, name, dependencies, exclusives=exclusives)
TargetWithSources.__init__(self, name, sources)
self.add_labels('jvm')
for source in self.sources:
rel_path = os.path.join(self.target_base, source)
TargetWithSources.register_source(rel_path, self)
self.excludes = maybe_list(excludes or [], Exclude)
self.configurations = maybe_list(configurations or [])
示例5: distribution
def distribution(self, files=None, executables=None):
with temporary_dir() as jdk:
for f in maybe_list(files or ()):
touch(os.path.join(jdk, f))
for exe in maybe_list(executables or (), expected_type=self.EXE):
path = os.path.join(jdk, exe.name)
with safe_open(path, 'w') as fp:
fp.write(exe.contents or '')
chmod_plus_x(path)
yield jdk
示例6: distribution
def distribution(files=None, executables=None, java_home=None):
with temporary_dir() as dist_root:
for f in maybe_list(files or ()):
touch(os.path.join(dist_root, f))
for executable in maybe_list(executables or (), expected_type=EXE):
path = os.path.join(dist_root, executable.relpath)
with safe_open(path, 'w') as fp:
java_home = os.path.join(dist_root, java_home) if java_home else dist_root
fp.write(executable.contents(java_home))
chmod_plus_x(path)
yield dist_root
示例7: distribution
def distribution(files=None, executables=None, java_home=None):
with subsystem_instance(DistributionLocator):
with temporary_dir() as dist_root:
with environment_as(DIST_ROOT=os.path.join(dist_root, java_home) if java_home else dist_root):
for f in maybe_list(files or ()):
touch(os.path.join(dist_root, f))
for executable in maybe_list(executables or (), expected_type=EXE):
path = os.path.join(dist_root, executable.relpath)
with safe_open(path, 'w') as fp:
fp.write(executable.contents or '')
chmod_plus_x(path)
yield dist_root
示例8: __init__
def __init__(self, classpath, ivy_settings=None, ivy_cache_dir=None, extra_jvm_options=None):
"""Configures an ivy wrapper for the ivy distribution at the given classpath.
:param ivy_settings: path to find settings.xml file
:param ivy_cache_dir: path to store downloaded ivy artifacts
:param extra_jvm_options: list of strings to add to command line when invoking Ivy
"""
self._classpath = maybe_list(classpath)
self._ivy_settings = ivy_settings
if self._ivy_settings and not isinstance(self._ivy_settings, string_types):
raise ValueError(
"ivy_settings must be a string, given {} of type {}".format(
self._ivy_settings, type(self._ivy_settings)
)
)
self._ivy_cache_dir = ivy_cache_dir
if not isinstance(self._ivy_cache_dir, string_types):
raise ValueError(
"ivy_cache_dir must be a string, given {} of type {}".format(
self._ivy_cache_dir, type(self._ivy_cache_dir)
)
)
self._extra_jvm_options = extra_jvm_options or []
示例9: distribution
def distribution(installed_sdks=('18', '19'),
installed_build_tools=('19.1.0', '20.0.0'),
files=('android.jar',),
executables=('aapt', 'zipalign')):
"""Mock Android SDK Distribution.
:param tuple[strings] installed_sdks: SDK versions of the files being mocked.
:param tuple[strings] installed_build_tools: Build tools version of any tools.
:param tuple[strings] files: The files are to mock non-executables and one will be created for
each installed_sdks version.
:param tuple[strings] executables: Executables are any required tools and one is created for
each installed_build_tools version.
"""
with temporary_dir() as sdk:
for sdk_version in installed_sdks:
for android_file in files:
touch(os.path.join(sdk, 'platforms', 'android-' + sdk_version, android_file))
for version in installed_build_tools:
for exe in maybe_list(executables or ()):
path = os.path.join(sdk, 'build-tools', version, exe)
touch(path)
chmod_plus_x(path)
dx_path = os.path.join(sdk, 'build-tools', version, 'lib/dx.jar')
touch(dx_path)
yield sdk
示例10: __init__
def __init__(self,
sources=None,
**kwargs):
"""
:param string name: The name of this target, which combined with this
build file defines the :doc:`target address <target_addresses>`.
:param sources: Source code files to compile. Paths are relative to the
BUILD file's directory.
:type sources: ``Fileset`` or list of strings
:param provides: The ``artifact``
to publish that represents this target outside the repo.
:param dependencies: Other targets that this target depends on.
:type dependencies: list of target specs
:param excludes: List of :ref:`exclude <bdict_exclude>`\s
to filter this target's transitive dependencies against.
:param resources: An optional list of ``resources`` targets containing text
file resources to place in this module's jar.
:param exclusives: An optional map of exclusives tags. See CheckExclusives for details.
"""
_sources = maybe_list(sources or [], expected_type=Compatibility.string)
super(JavaTests, self).__init__(sources=_sources, **kwargs)
if not _sources:
raise TargetDefinitionException(self, 'JavaTests must include a non-empty set of sources.')
# TODO(John Sirois): These could be scala, clojure, etc. 'jvm' and 'tests' are the only truly
# applicable labels - fixup the 'java' misnomer.
self.add_labels('java', 'tests')
示例11: __init__
def __init__(self,
address=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):
payload = PythonPayload(sources_rel_path=address.spec_path,
sources=sources or [],
resources=resources)
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
self.compatibility = maybe_list(compatibility or ())
for req in self.compatibility:
try:
PythonIdentity.parse_requirement(req)
except ValueError as e:
raise TargetDefinitionException(self, str(e))
示例12: generate_ivy
def generate_ivy(cls, targets, jars, excludes, ivyxml, confs):
org, name = cls.identify(targets)
# As it turns out force is not transitive - it only works for dependencies pants knows about
# directly (declared in BUILD files - present in generated ivy.xml). The user-level ivy docs
# don't make this clear [1], but the source code docs do (see isForce docs) [2]. I was able to
# edit the generated ivy.xml and use the override feature [3] though and that does work
# transitively as you'd hope.
#
# [1] http://ant.apache.org/ivy/history/2.3.0/settings/conflict-managers.html
# [2] https://svn.apache.org/repos/asf/ant/ivy/core/branches/2.3.0/
# src/java/org/apache/ivy/core/module/descriptor/DependencyDescriptor.java
# [3] http://ant.apache.org/ivy/history/2.3.0/ivyfile/override.html
dependencies = [cls._generate_jar_template(jar, confs) for jar in jars]
overrides = [cls._generate_override_template(dep) for dep in dependencies if dep.force]
excludes = [cls._generate_exclude_template(exclude) for exclude in excludes]
template_data = TemplateData(
org=org,
module=name,
version='latest.integration',
publications=None,
configurations=maybe_list(confs), # Mustache doesn't like sets.
dependencies=dependencies,
excludes=excludes,
overrides=overrides)
safe_mkdir(os.path.dirname(ivyxml))
with open(ivyxml, 'w') as output:
generator = Generator(pkgutil.get_data(__name__, cls.IVY_TEMPLATE_PATH),
root_dir=get_buildroot(),
lib=template_data)
generator.write(output)
示例13: __init__
def __init__(self, org, name, repo, description=None):
"""
:param string org: Organization of this artifact, or groupId in maven parlance.
:param string name: Name of the artifact, or artifactId in maven parlance.
:param repo: :class:`twitter.pants.targets.repository.Repository`
this artifact is published to.
:param string description: Description of this artifact.
"""
if not isinstance(org, Compatibility.string):
raise ValueError("org must be %s but was %s" % (Compatibility.string, org))
if not isinstance(name, Compatibility.string):
raise ValueError("name must be %s but was %s" % (Compatibility.string, name))
if repo is None:
raise ValueError("repo must be supplied")
repos = []
for tgt in maybe_list(resolve(repo), expected_type=(Pants, Repository)):
repos.extend(tgt.resolve())
if len(repos) != 1:
raise ValueError("An artifact must have exactly 1 repo, given: %s" % repos)
repo = repos[0]
if description is not None and not isinstance(description, Compatibility.string):
raise ValueError("description must be None or %s but was %s"
% (Compatibility.string, description))
self.org = org
self.name = name
self.rev = None
self.repo = repo
self.description = description
示例14: __init__
def __init__(self,
name,
sources,
resources=None,
dependencies=None,
provides=None,
compatibility=None,
exclusives=None):
TargetWithSources.__init__(self, name, sources=sources, exclusives=exclusives)
TargetWithDependencies.__init__(self, name, dependencies=dependencies, exclusives=exclusives)
self.add_labels('python')
self.resources = self._resolve_paths(resources) if resources else OrderedSet()
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
self.compatibility = maybe_list(compatibility or ())
for req in self.compatibility:
try:
PythonIdentity.parse_requirement(req)
except ValueError as e:
raise TargetDefinitionException(self, str(e))
示例15: skip_signatures_and_duplicates_concat_well_known_metadata
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: :class:`twitter.pants.targets.JarRules`
"""
default_dup_action = Duplicate.validate_action(default_dup_action or Duplicate.SKIP)
additional_rules = maybe_list(additional_rules or [], 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)