本文整理汇总了Python中twitter.common.python.platforms.Platform类的典型用法代码示例。如果您正苦于以下问题:Python Platform类的具体用法?Python Platform怎么用?Python Platform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Platform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = configure_clp()
options, args = parser.parse_args()
verbosity = 5 if options.verbosity else -1
with Tracer.env_override(
PEX_VERBOSE=verbosity,
TWITTER_COMMON_PYTHON_HTTP=verbosity,
PYTHON_VERBOSE=verbosity):
pex_builder = build_pex(args, options)
if options.pex_name is not None:
log('Saving PEX file to %s' % options.pex_name, v=options.verbosity)
tmp_name = options.pex_name + '~'
safe_delete(tmp_name)
pex_builder.build(tmp_name)
os.rename(tmp_name, options.pex_name)
return 0
if options.platform != Platform.current():
log('WARNING: attempting to run PEX with differing platform!')
pex_builder.freeze()
log('Running PEX file at %s with args %s' % (pex_builder.path(), args), v=options.verbosity)
pex = PEX(pex_builder.path(), interpreter=pex_builder.interpreter)
return pex.run(args=list(args))
示例2: dump
def dump(self):
self.debug('Building PythonBinary %s:' % self._target)
targets = self.resolve([self._target] + self._extra_targets)
for lib in targets['libraries'] | targets['binaries']:
self._dump_library(lib)
generated_reqs = OrderedSet()
if targets['thrifts']:
for thr in set(targets['thrifts']):
if thr not in self.MEMOIZED_THRIFTS:
self.MEMOIZED_THRIFTS[thr] = self._generate_thrift_requirement(thr)
generated_reqs.add(self.MEMOIZED_THRIFTS[thr])
with ParseContext.temp():
# trick pants into letting us add this python requirement, otherwise we get
# TargetDefinitionException: Error in target BUILD.temp:thrift: duplicate to
# PythonRequirement(thrift)
#
# TODO(wickman) Instead of just blindly adding a PythonRequirement for thrift, we
# should first detect if any explicit thrift requirements have been added and use
# those. Only if they have not been supplied should we auto-inject it.
generated_reqs.add(PythonRequirement('thrift', use_2to3=True,
name='thrift-' + ''.join(random.sample('0123456789abcdef' * 8, 8))))
for antlr in targets['antlrs']:
generated_reqs.add(self._generate_antlr_requirement(antlr))
targets['reqs'] |= generated_reqs
reqs_to_build = OrderedSet()
for req in targets['reqs']:
if not req.should_build(self._interpreter.python, Platform.current()):
self.debug('Skipping %s based upon version filter' % req)
continue
reqs_to_build.add(req)
self._dump_requirement(req._requirement, False, req._repository)
platforms = self._platforms
if isinstance(self._target, PythonBinary):
platforms = self._target.platforms
distributions = resolve_multi(
self._config,
reqs_to_build,
interpreter=self._interpreter,
platforms=platforms)
locations = set()
for platform, dist_set in distributions.items():
for dist in dist_set:
if dist.location not in locations:
self._dump_distribution(dist)
locations.add(dist.location)
if len(targets['binaries']) > 1:
print('WARNING: Target has multiple python_binary targets!', file=sys.stderr)
return self._builder
示例3: test_unknown
def test_unknown(self):
with pytest.raises(Platform.UnknownPlatformError):
Platform.compatible('macosx-10.0-morfgorf', 'macosx-10.1-morfgorf')
with pytest.raises(Platform.UnknownPlatformError):
Platform.compatible('macosx-10.0-x86_64', 'macosx-10.1-morfgorf')
with pytest.raises(Platform.UnknownPlatformError):
Platform.compatible('macosx-10.0-morfgorf', 'macosx-10.1-x86_64')
示例4: dump
def dump(self):
self.debug('Building PythonBinary %s:' % self._target)
targets = self.resolve([self._target] + self._extra_targets)
for lib in targets['libraries'] | targets['binaries']:
self._dump_library(lib)
generated_reqs = OrderedSet()
if targets['thrifts']:
for thr in set(targets['thrifts']):
if thr not in self.MEMOIZED_THRIFTS:
self.MEMOIZED_THRIFTS[thr] = self._generate_thrift_requirement(thr)
generated_reqs.add(self.MEMOIZED_THRIFTS[thr])
generated_reqs.add(PythonRequirement('thrift', use_2to3=True))
for antlr in targets['antlrs']:
generated_reqs.add(self._generate_antlr_requirement(antlr))
reqs_from_libraries = OrderedSet()
for req_lib in targets['reqs']:
for req in req_lib.payload.requirements:
reqs_from_libraries.add(req)
reqs_to_build = OrderedSet()
for req in reqs_from_libraries | generated_reqs | self._extra_requirements:
if not req.should_build(self._interpreter.python, Platform.current()):
self.debug('Skipping %s based upon version filter' % req)
continue
reqs_to_build.add(req)
self._dump_requirement(req._requirement, False, req._repository)
platforms = self._platforms
if isinstance(self._target, PythonBinary):
platforms = self._target.platforms
distributions = resolve_multi(
self._config,
reqs_to_build,
interpreter=self._interpreter,
platforms=platforms)
locations = set()
for platform, dist_set in distributions.items():
for dist in dist_set:
if dist.location not in locations:
self._dump_distribution(dist)
locations.add(dist.location)
if len(targets['binaries']) > 1:
print('WARNING: Target has multiple python_binary targets!', file=sys.stderr)
return self._builder
示例5: test_versioning
def test_versioning(self):
# Major versions incompatible
assert not Platform.compatible('macosx-9.1-x86_64', 'macosx-10.0-x86_64')
assert not Platform.compatible('macosx-10.0-x86_64', 'macosx-9.1-x86_64')
# Platforms equal
assert Platform.compatible('macosx-10.0-x86_64', 'macosx-10.0-x86_64')
# Minor versions less than
assert Platform.compatible('macosx-10.0-x86_64', 'macosx-10.1-x86_64')
assert not Platform.compatible('macosx-10.1-x86_64', 'macosx-10.0-x86_64')
assert Platform.compatible('macosx-10.9-x86_64', 'macosx-10.10-x86_64')
assert not Platform.compatible('macosx-10.10-x86_64', 'macosx-10.9-x86_64')
示例6: __init__
def __init__(self,
caches=(),
install_cache=None,
fetcher=None,
fetcher_provider=None,
platform=Platform.current(),
python=sys.version[:3]):
assert (fetcher is not None) + (fetcher_provider is not None) == 1, (
"At most one of fetcher or fetcher_provider should be supplied")
self._subcaches = [Resolver.Subcache(cache, self) for cache in caches]
self._fetcher = fetcher
self._fetcher_provider = fetcher_provider
self._install_cache = install_cache
self._ws = WorkingSet([])
with self.timed('Calling environment super'):
super(Resolver, self).__init__(search_path=[], platform=platform, python=python)
示例7: __init__
def __init__(self, target, root_dir, extra_targets=None, builder=None):
self._config = Config.load()
self._target = target
self._root = root_dir
self._cache = BuildCache(os.path.join(self._config.get('python-setup', 'artifact_cache'),
'%s' % PythonIdentity.get()))
self._extra_targets = list(extra_targets) if extra_targets is not None else []
self._resolver = PythonResolver([self._target] + self._extra_targets)
self._builder = builder or PEXBuilder(tempfile.mkdtemp())
self._platforms = (Platform.current(),)
self._pythons = (sys.version[:3],)
# TODO(wickman) Should this be in the binary builder?
if isinstance(self._target, PythonBinary):
self._platforms = self._target._platforms
self._pythons = self._target._interpreters
示例8: test_platform_subsets
def test_platform_subsets(self):
# Pure platform subset
assert Platform.compatible('macosx-10.0-i386', 'macosx-10.0-intel')
# Version and platform subset
assert Platform.compatible('macosx-10.0-i386', 'macosx-10.1-intel')
assert Platform.compatible('macosx-10.0-x86_64', 'macosx-10.1-intel')
# Intersecting sets of platform but not pure subset
assert Platform.compatible('macosx-10.0-fat', 'macosx-10.1-intel')
# Non-intersecting sets of platform
assert not Platform.compatible('macosx-10.0-ppc', 'macosx-10.1-intel')
# Test our common case
assert Platform.compatible('macosx-10.4-x86_64', 'macosx-10.7-intel')
示例9: test_get_current_platform
def test_get_current_platform(self):
expected_platforms = [Platform.current(), 'linux-x86_64']
self.assertEqual(expected_platforms,
list(get_platforms(self.config.getlist('python-setup', 'platforms'))))
示例10: test_get_current_platform
def test_get_current_platform(self):
expected_platforms = [Platform.current(), "linux-x86_64"]
self.assertEqual(expected_platforms, list(get_platforms(self.config.getlist("python-setup", "platforms"))))
示例11: translate
def translate(platform):
return Platform.current() if platform == 'current' else platform
示例12: platform_compatible
def platform_compatible():
return Platform.compatible(dist.platform, self.platform)
示例13: _safe_open
close_fds=True,
cwd=get_buildroot()
)
with _safe_open(self._pidfile, 'w') as pidfile:
pidfile.write('%d' % process.pid)
log.debug('Spawned ng server @ %d' % process.pid)
# Prevents finally blocks being executed, unlike sys.exit(). We don't want to execute finally
# blocks because we might, e.g., clean up tempfiles that the parent still needs.
os._exit(0)
# Pick implementations for killall and _find. We don't use psutil, as it uses
# native code and so is not portable, leading to packaging and deployment headaches.
# TODO: Extract this to a class and add a paired test guarded by
# http://pytest.org/latest/skipping.html#skipping.
plat = Platform.current()
if plat.startswith('linux') or plat.startswith('macosx'):
# TODO: add other platforms as needed, after checking that these cmds work there as expected.
# Returns the cmd's output, as a list of lines, including the newline characters.
def _run_cmd(cmd):
runcmd = cmd + ' && echo "\n${PIPESTATUS[*]}"'
popen = subprocess.Popen(runcmd, shell=True, executable='/bin/bash', bufsize=-1, close_fds=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(stdout_data, _) = popen.communicate()
stdout_data_lines = [line for line in stdout_data.strip().split('\n') if line]
if not stdout_data_lines:
raise NailgunError('No output for command (%s)' % runcmd)
try:
# Get the return codes of each piped cmd.
piped_return_codes = [int(x) for x in stdout_data_lines[-1].split(' ') if x]
示例14: __init__
def __init__(self, interpreter, platform=None):
platform = platform or Platform.current()
self.__interpreter = interpreter
super(PantsEnvironment, self).__init__(
search_path=[], python=interpreter.python, platform=platform)
示例15: can_add
def can_add(self, dist):
return Platform.distribution_compatible(dist, python=self.python, platform=self.platform)