本文整理汇总了Python中twitter.common.python.interpreter.PythonInterpreter类的典型用法代码示例。如果您正苦于以下问题:Python PythonInterpreter类的具体用法?Python PythonInterpreter怎么用?Python PythonInterpreter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PythonInterpreter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: interpreter_from_options
def interpreter_from_options(options):
interpreter = None
if options.python:
if os.path.exists(options.python):
interpreter = PythonInterpreter.from_binary(options.python)
else:
interpreter = PythonInterpreter.from_env(options.python)
if interpreter is None:
die('Failed to find interpreter: %s' % options.python)
else:
interpreter = PythonInterpreter.get()
return interpreter
示例2: cmdline
def cmdline(self, args=()):
"""
The commandline to run this environment.
Optional arguments:
binary: The binary to run instead of the entry point in the environment
interpreter_args: Arguments to be passed to the interpreter before, e.g. '-E' or
['-m', 'pylint.lint']
args: Arguments to be passed to the application being invoked by the environment.
"""
interpreter = PythonInterpreter(sys.executable)
cmds = [interpreter.binary()]
cmds.append(self._pex.path())
cmds.extend(args)
return cmds
示例3: __init__
def __init__(self,
target,
root_dir,
extra_targets=None,
extra_requirements=None,
builder=None,
platforms=None,
interpreter=None,
conn_timeout=None):
self._config = Config.load()
self._target = target
self._root = root_dir
self._platforms = platforms
self._interpreter = interpreter or PythonInterpreter.get()
self._extra_targets = list(extra_targets) if extra_targets is not None else []
self._extra_requirements = list(extra_requirements) if extra_requirements is not None else []
self._builder = builder or PEXBuilder(tempfile.mkdtemp(), interpreter=self._interpreter)
# Note: unrelated to the general pants artifact cache.
self._egg_cache_root = os.path.join(
PythonSetup(self._config).scratch_dir('artifact_cache', default_name='artifacts'),
str(self._interpreter.identity))
self._key_generator = CacheKeyGenerator()
self._build_invalidator = BuildInvalidator( self._egg_cache_root)
示例4: build
def build(self, targets, args, interpreter=None, conn_timeout=None):
test_targets = []
binary_targets = []
interpreter = interpreter or PythonInterpreter.get()
for target in targets:
assert target.is_python, "PythonBuilder can only build PythonTargets, given %s" % str(target)
# PythonBuilder supports PythonTests and PythonBinaries
for target in targets:
if isinstance(target, PythonTests) or isinstance(target, PythonTestSuite):
test_targets.append(target)
elif isinstance(target, PythonBinary):
binary_targets.append(target)
rv = PythonTestBuilder(
test_targets,
args,
self._root_dir,
interpreter=interpreter,
conn_timeout=conn_timeout).run()
if rv != 0:
return rv
for binary_target in binary_targets:
rv = PythonBinaryBuilder(
binary_target,
self._root_dir,
self._run_tracker,
interpreter=interpreter,
conn_timeout=conn_timeout).run()
if rv != 0:
return rv
return 0
示例5: select_interpreter
def select_interpreter(self, compatibilities, allow_multiple=False):
if allow_multiple:
return compatibilities
me = PythonInterpreter.get()
if me in compatibilities:
return [me]
return [min(compatibilities)] if compatibilities else []
示例6: __init__
def __init__(self, targets, args, root_dir, interpreter=None, conn_timeout=None):
self.targets = targets
self.args = args
self.root_dir = root_dir
self.interpreter = interpreter or PythonInterpreter.get()
self.successes = {}
self._conn_timeout = conn_timeout
示例7: __init__
def __init__(self, target, root_dir, run_tracker, interpreter=None, conn_timeout=None):
self.target = target
self.interpreter = interpreter or PythonInterpreter.get()
if not isinstance(target, PythonBinary):
raise PythonBinaryBuilder.NotABinaryTargetException(
"Target %s is not a PythonBinary!" % target)
config = Config.load()
self.distdir = config.getdefault('pants_distdir')
distpath = tempfile.mktemp(dir=self.distdir, prefix=target.name)
run_info = run_tracker.run_info
build_properties = {}
build_properties.update(run_info.add_basic_info(run_id=None, timestamp=time.time()))
build_properties.update(run_info.add_scm_info())
pexinfo = target.pexinfo.copy()
pexinfo.build_properties = build_properties
builder = PEXBuilder(distpath, pex_info=pexinfo, interpreter=self.interpreter)
self.chroot = PythonChroot(
target,
root_dir,
builder=builder,
interpreter=self.interpreter,
conn_timeout=conn_timeout)
示例8: main
def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--entry-point', default='__main__')
parser.add_argument('--python', default=sys.executable)
parser.add_argument('output')
args = parser.parse_args(argv[1:])
# The manifest is passed via stdin, as it can sometimes get too large
# to be passed as a CLA.
manifest = json.load(sys.stdin)
# Setup a temp dir that the PEX builder will use as its scratch dir.
tmp_dir = tempfile.mkdtemp()
try:
# The version of pkg_resources.py (from setuptools) on some distros is
# too old for PEX. So we keep a recent version in the buck repo and
# force it into the process by constructing a custom PythonInterpreter
# instance using it.
interpreter = PythonInterpreter(
args.python, PythonInterpreter.from_binary(args.python).identity,
extras={('setuptools', '1.0'):
os.path.join(BUCK_ROOT, 'third-party/py/setuptools')})
pex_builder = PEXBuilder(
path=tmp_dir,
interpreter=interpreter,
)
# Mark this PEX as zip-safe, meaning everything will stayed zipped up
# and we'll rely on python's zip-import mechanism to load modules from
# the PEX. This may not work in some situations (e.g. native
# libraries, libraries that want to find resources via the FS), so
# we'll want to revisit this.
pex_builder.info.zip_safe = True
# Set the starting point for this PEX.
pex_builder.info.entry_point = args.entry_point
# Add the sources listed in the manifest.
for dst, src in manifest['modules'].iteritems():
# NOTE(agallagher): calls the `add_source` and `add_resource` below
# hard-link the given source into the PEX temp dir. Since OS X and
# Linux behave different when hard-linking a source that is a
# symbolic link (Linux does *not* follow symlinks), resolve any
# layers of symlinks here to get consistent behavior.
pex_builder.add_source(dereference_symlinks(src), dst)
# Add resources listed in the manifest.
for dst, src in manifest['resources'].iteritems():
# NOTE(agallagher): see rationale above.
pex_builder.add_resource(dereference_symlinks(src), dst)
# Generate the PEX file.
pex_builder.build(args.output)
# Always try cleaning up the scratch dir, ignoring failures.
finally:
shutil.rmtree(tmp_dir, True)
示例9: from_file
def from_file(filename, interpreter=PythonInterpreter.get()):
if filename.lower().endswith(".egg"):
return PythonDependency.from_eggs(filename, interpreter=interpreter)
else:
for suffix in VALID_SOURCE_EXTENSIONS:
if filename.lower().endswith(suffix):
return PythonDependency.from_source(filename, interpreter=interpreter)
raise PythonDependency.RequirementError("Unrecognized Python dependency file format: %s!" % filename)
示例10: test_iter_ordering
def test_iter_ordering():
pi = PythonInterpreter.get()
tgz = SourcePackage('psutil-0.6.1.tar.gz')
egg = EggPackage('psutil-0.6.1-py%s-%s.egg' % (pi.python, get_build_platform()))
req = Requirement.parse('psutil')
assert list(FakeObtainer([tgz, egg]).iter(req)) == [egg, tgz]
assert list(FakeObtainer([egg, tgz]).iter(req)) == [egg, tgz]
示例11: install_requirement
def install_requirement(req,
path=None,
extra_site_dirs=[],
index='http://pypi.python.org/simple',
repositories=['http://pypi.python.org/simple'],
interpreter=PythonInterpreter.get()):
"""
Install the requirement "req" to path "path" with extra_site_dirs put
onto the PYTHONPATH. Returns the set of newly added Distributions
(of type pkg_resource.Distribution.)
"req" can either be a pkg_resources.Requirement object (e.g. created by
pkg_resources.Requirement.parse("MySQL-python==1.2.2")) or an installable
package (e.g. a tar.gz source distribution, a source or binary .egg)
"path" is the into which we install the requirements. if path is None,
we'll create one for you.
"""
# TODO(wickman) Consider importing the easy_install Command class directly and
# manipulating it with initialize/finalize options + run.
if not isinstance(req, pkg_resources.Requirement):
if not os.path.exists(req):
try:
req = pkg_resources.Requirement.parse(req)
except:
raise TypeError(
"req should either be an installable file, a pkg_resources.Requirement "
"or a valid requirement string. got %s" % req)
if path is None:
path = tempfile.mkdtemp()
if not os.path.exists(path):
safe_mkdir(path)
easy_install_args = [
'--install-dir=%s' % path,
'--site-dirs=%s' % ','.join([path] + extra_site_dirs),
'--always-copy',
'--multi-version',
'--exclude-scripts',
'-i', index]
for repo in reversed(repositories):
easy_install_args.extend(['-f', repo])
easy_install_args.append(str(req))
distributions_backup = set(pkg_resources.find_distributions(path))
rc = ReqBuilder.run_easy_install([path] + extra_site_dirs + sys.path,
easy_install_args, interpreter)
distributions = set(pkg_resources.find_distributions(path))
new_distributions = distributions - distributions_backup
return new_distributions if rc else set()
示例12: execute
def execute(self, _):
setup_paths = self.context.options.python_setup_paths or os.getenv('PATH').split(':')
self.context.log.debug('Finding interpreters in %s' % setup_paths)
interpreters = PythonInterpreter.all(setup_paths)
self.context.log.debug('Found %d interpreters' % len(interpreters))
setup_virtualenv_py(self.context)
for interpreter in interpreters:
self.context.log.debug('Preparing %s' % interpreter)
install_virtualenv(self.context, interpreter)
示例13: __init__
def __init__(self, targets, args, interpreter=None, conn_timeout=None, fast=False):
self.targets = targets
self.args = args
self.interpreter = interpreter or PythonInterpreter.get()
self._conn_timeout = conn_timeout
# If fast is true, we run all the tests in a single chroot. This is MUCH faster than
# creating a chroot for each test target. However running each test separately is more
# correct, as the isolation verifies that its dependencies are correctly declared.
self._fast = fast
示例14: test_iter_ordering
def test_iter_ordering():
pi = PythonInterpreter.get()
tgz = SourcePackage('psutil-0.6.1.tar.gz')
egg = EggPackage('psutil-0.6.1-py%s-%s.egg' % (pi.python, get_build_platform()))
whl = WheelPackage('psutil-0.6.1-cp%s-none-%s.whl' % (
pi.python.replace('.', ''),
get_build_platform().replace('-', '_').replace('.', '_').lower()))
req = Requirement.parse('psutil')
assert list(FakeObtainer([tgz, egg, whl]).iter(req)) == [whl, egg, tgz]
assert list(FakeObtainer([egg, tgz, whl]).iter(req)) == [whl, egg, tgz]
示例15: _setup_paths
def _setup_paths(self, paths, filters):
for interpreter in self._matching(PythonInterpreter.all(paths), filters):
identity_str = str(interpreter.identity)
path = os.path.join(self._path, identity_str)
pi = self._interpreter_from_path(path, filters)
if pi is None:
self._setup_interpreter(interpreter)
pi = self._interpreter_from_path(path, filters)
if pi is None:
continue
self._interpreters.add(pi)