本文整理汇总了Python中twitter.common.collections.maybe_list函数的典型用法代码示例。如果您正苦于以下问题:Python maybe_list函数的具体用法?Python maybe_list怎么用?Python maybe_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maybe_list函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:cosmicexplorer,项目名称:pants,代码行数:7,代码来源:executor.py
示例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
开发者ID:Yasumoto,项目名称:pants,代码行数:7,代码来源:executor.py
示例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 = []
开发者ID:FernandoG26,项目名称:commons,代码行数:29,代码来源:jvm_binary.py
示例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 [])
开发者ID:govindkabra,项目名称:pants,代码行数:31,代码来源:jvm_target.py
示例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
开发者ID:CodeWarltz,项目名称:commons,代码行数:10,代码来源:test_distribution.py
示例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
开发者ID:baroquebobcat,项目名称:pants,代码行数:11,代码来源:test_distribution.py
示例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
开发者ID:jduan,项目名称:pants,代码行数:12,代码来源:test_distribution.py
示例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 []
开发者ID:ahamilton55,项目名称:pants,代码行数:25,代码来源:ivy.py
示例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
开发者ID:dturner-tw,项目名称:pants,代码行数:25,代码来源:test_android_base.py
示例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')
开发者ID:cheecheeo,项目名称:pants,代码行数:29,代码来源:java_tests.py
示例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))
开发者ID:ejconlon,项目名称:pants,代码行数:30,代码来源:python_target.py
示例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)
开发者ID:jinfeng,项目名称:jinfeng-pants-fork,代码行数:34,代码来源:ivy_utils.py
示例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
开发者ID:CodeWarltz,项目名称:commons,代码行数:31,代码来源:artifact.py
示例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))
开发者ID:govindkabra,项目名称:pants,代码行数:26,代码来源:python_target.py
示例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)
开发者ID:Docworld,项目名称:pants,代码行数:25,代码来源:jvm_binary.py
示例16: __init__
def __init__(self,
address=None,
payload=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.
"""
self.address = address
payload = payload or Payload()
payload.add_fields({
'sources': self.create_sources_field(sources, address.spec_path, key_arg='sources'),
'resources': self.create_sources_field(resources, address.spec_path, key_arg='resources'),
'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 '{}' object instead.".format(
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))
开发者ID:Gabriel439,项目名称:pants,代码行数:60,代码来源:python_target.py
示例17: __init__
def __init__(self,
timeout=Amount(2, Time.MINUTES),
coverage=None,
soft_dependencies=False,
entry_point='pytest',
**kwargs):
"""
:param name: See PythonLibrary target
:param sources: A list of filenames representing the source code
this library is compiled from.
:type sources: list of strings
:param resources: See PythonLibrary target
:param dependencies: List of :class:`pants.base.target.Target` instances
this target depends on.
:type dependencies: list of targets
:param timeout: Amount of time before this test should be considered timed-out.
:param coverage: the module(s) whose coverage should be generated, e.g.
'twitter.common.log' or ['twitter.common.log', 'twitter.common.http']
:param soft_dependencies: Whether or not we should ignore dependency resolution
errors for this test.
:param entry_point: The entry point to use to run the tests.
:param dict exclusives: An optional dict of exclusives tags. See CheckExclusives for details.
"""
self._timeout = timeout
self._soft_dependencies = bool(soft_dependencies)
self._coverage = maybe_list(coverage) if coverage is not None else []
self._entry_point = entry_point
super(PythonTests, self).__init__(**kwargs)
self.add_labels('python', 'tests')
开发者ID:ejconlon,项目名称:pants,代码行数:29,代码来源:python_tests.py
示例18: __init__
def __init__(self,
address=None,
payload=None,
sources=None,
setup_requires=None,
**kwargs):
"""
:param address: The Address that maps to this Target in the BuildGraph.
:type address: :class:`pants.build_graph.address.Address`
:param payload: The configuration encapsulated by this target. Also in charge of most
fingerprinting details.
:type payload: :class:`pants.base.payload.Payload`
:param sources: Files to "include". Paths are relative to the
BUILD file's directory.
:type sources: :class:`twitter.common.dirutil.Fileset` or list of strings. Must include
setup.py.
:param list setup_requires: A list of python requirements to provide during the invocation of
setup.py.
"""
if not 'setup.py' in sources:
raise TargetDefinitionException(
self,
'A file named setup.py must be in the same '
'directory as the BUILD file containing this target.')
payload = payload or Payload()
payload.add_fields({
'setup_requires': PrimitiveField(maybe_list(setup_requires or ()))
})
super(PythonDistribution, self).__init__(
address=address, payload=payload, sources=sources, **kwargs)
开发者ID:jsirois,项目名称:pants,代码行数:31,代码来源:python_distribution.py
示例19: parse_addresses
def parse_addresses(self, specs, fail_fast=False):
"""Process a list of command line specs and perform expansion. This method can expand a list
of command line specs.
:param list specs: either a single spec string or a list of spec strings.
:return: a generator of specs parsed into addresses.
:raises: CmdLineSpecParser.BadSpecError if any of the address selectors could not be parsed.
"""
specs = maybe_list(specs)
addresses = OrderedSet()
for spec in specs:
for address in self._parse_spec(spec, fail_fast):
addresses.add(address)
results = filter(self._not_excluded_address, addresses)
# Print debug information about the excluded targets
if logger.getEffectiveLevel() <= logging.DEBUG and self._exclude_patterns:
logger.debug('excludes:\n {excludes}'
.format(excludes='\n '.join(self._exclude_target_regexps)))
targets = ', '.join(self._excluded_target_map[CmdLineSpecParser._UNMATCHED_KEY])
logger.debug('Targets after excludes: {targets}'.format(targets=targets))
excluded_count = 0
for pattern, targets in six.iteritems(self._excluded_target_map):
if pattern != CmdLineSpecParser._UNMATCHED_KEY:
logger.debug('Targets excluded by pattern {pattern}\n {targets}'
.format(pattern=pattern,
targets='\n '.join(targets)))
excluded_count += len(targets)
logger.debug('Excluded {count} target{plural}.'
.format(count=excluded_count,
plural=('s' if excluded_count != 1 else '')))
return results
开发者ID:dturner-tw,项目名称:pants,代码行数:33,代码来源:cmd_line_spec_parser.py
示例20: run_export
def run_export(self, test_target, workdir, load_libs=False, only_default=False, extra_args=None):
"""Runs ./pants export ... and returns its json output.
:param string|list test_target: spec of the targets to run on.
:param string workdir: working directory to run pants with.
:param bool load_libs: whether to load external libraries (of any conf).
:param bool only_default: if loading libraries, whether to only resolve the default conf, or to
additionally resolve sources and javadocs.
:param list extra_args: list of extra arguments for the pants invocation.
:return: the json output of the console task.
:rtype: dict
"""
export_out_file = os.path.join(workdir, 'export_out.txt')
args = ['export',
'--output-file={out_file}'.format(out_file=export_out_file)] + maybe_list(test_target)
libs_args = ['--no-export-libraries'] if not load_libs else self._confs_args
if load_libs and only_default:
libs_args = []
pants_run = self.run_pants_with_workdir(args + libs_args + (extra_args or []), workdir)
self.assert_success(pants_run)
self.assertTrue(os.path.exists(export_out_file),
msg='Could not find export output file in {out_file}'
.format(out_file=export_out_file))
with open(export_out_file) as json_file:
json_data = json.load(json_file)
if not load_libs:
self.assertIsNone(json_data.get('libraries'))
return json_data
开发者ID:grimreaper,项目名称:pants,代码行数:28,代码来源:test_export_integration.py
注:本文中的twitter.common.collections.maybe_list函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论