本文整理汇总了Python中pex.interpreter.PythonInterpreter.all方法的典型用法代码示例。如果您正苦于以下问题:Python PythonInterpreter.all方法的具体用法?Python PythonInterpreter.all怎么用?Python PythonInterpreter.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pex.interpreter.PythonInterpreter
的用法示例。
在下文中一共展示了PythonInterpreter.all方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_compatible_interpreters
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
def test_find_compatible_interpreters():
py27 = ensure_python_interpreter(PY27)
py35 = ensure_python_interpreter(PY35)
py36 = ensure_python_interpreter(PY36)
pex_python_path = ':'.join([py27, py35, py36])
def find_interpreters(*constraints):
return [interp.binary for interp in
find_compatible_interpreters(pex_python_path=pex_python_path,
compatibility_constraints=constraints)]
assert [py35, py36] == find_interpreters('>3')
assert [py27] == find_interpreters('<3')
assert [py36] == find_interpreters('>{}'.format(PY35))
assert [py35] == find_interpreters('>{}, <{}'.format(PY27, PY36))
assert [py36] == find_interpreters('>=3.6')
assert [] == find_interpreters('<2')
assert [] == find_interpreters('>4')
assert [] == find_interpreters('>{}, <{}'.format(PY27, PY35))
# All interpreters on PATH including whatever interpreter is currently running.
all_known_interpreters = set(PythonInterpreter.all())
all_known_interpreters.add(PythonInterpreter.get())
interpreters = find_compatible_interpreters(compatibility_constraints=['<3'])
assert set(interpreters).issubset(all_known_interpreters)
示例2: find_compatible_interpreters
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
def find_compatible_interpreters(pex_python_path=None, compatibility_constraints=None):
"""Find all compatible interpreters on the system within the supplied constraints and use
PEX_PYTHON_PATH if it is set. If not, fall back to interpreters on $PATH.
"""
if pex_python_path:
interpreters = []
for binary in pex_python_path.split(os.pathsep):
try:
interpreters.append(PythonInterpreter.from_binary(binary))
except Executor.ExecutionError:
print("Python interpreter %s in PEX_PYTHON_PATH failed to load properly." % binary,
file=sys.stderr)
if not interpreters:
die('PEX_PYTHON_PATH was defined, but no valid interpreters could be identified. Exiting.')
else:
# We may have been invoked with a specific interpreter not on the $PATH, make sure our
# sys.executable is included as a candidate in this case.
interpreters = OrderedSet([PythonInterpreter.get()])
# Add all qualifying interpreters found in $PATH.
interpreters.update(PythonInterpreter.all())
return list(
matched_interpreters(interpreters, compatibility_constraints)
if compatibility_constraints
else interpreters
)
示例3: _setup_paths
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
def _setup_paths(self, paths, filters=()):
"""Find interpreters under paths, and cache them."""
for interpreter in self._matching(PythonInterpreter.all(paths), filters=filters):
identity_str = str(interpreter.identity)
pi = self._interpreter_from_relpath(identity_str, filters=filters)
if pi is None:
self._setup_interpreter(interpreter, identity_str)
pi = self._interpreter_from_relpath(identity_str, filters=filters)
if pi:
yield pi
示例4: _setup_paths
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
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)
示例5: _setup_paths
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
def _setup_paths(self, paths, filters):
"""Find interpreters under paths, and cache them."""
for interpreter in self._matching(PythonInterpreter.all(paths), filters):
identity_str = str(interpreter.identity)
cache_path = os.path.join(self._cache_dir, identity_str)
pi = self._interpreter_from_path(cache_path, filters)
if pi is None:
self._setup_interpreter(interpreter, cache_path)
pi = self._interpreter_from_path(cache_path, filters)
if pi:
yield pi
示例6: test_find_compatible_interpreters
# 需要导入模块: from pex.interpreter import PythonInterpreter [as 别名]
# 或者: from pex.interpreter.PythonInterpreter import all [as 别名]
def test_find_compatible_interpreters():
pex_python_path = ':'.join([
ensure_python_interpreter('2.7.9'),
ensure_python_interpreter('2.7.10'),
ensure_python_interpreter('2.7.11'),
ensure_python_interpreter('3.4.2'),
ensure_python_interpreter('3.5.4'),
ensure_python_interpreter('3.6.2'),
ensure_python_interpreter('3.6.3')
])
interpreters = find_compatible_interpreters(pex_python_path, ['>3'])
assert interpreters[0].binary == pex_python_path.split(':')[3] # 3.4.2
interpreters = find_compatible_interpreters(pex_python_path, ['<3'])
assert interpreters[0].binary == pex_python_path.split(':')[0] # 2.7.9
interpreters = find_compatible_interpreters(pex_python_path, ['>3.5.4'])
assert interpreters[0].binary == pex_python_path.split(':')[5] # 3.6.2
interpreters = find_compatible_interpreters(pex_python_path, ['>3.4.2, <3.6'])
assert interpreters[0].binary == pex_python_path.split(':')[4] # 3.5.4
interpreters = find_compatible_interpreters(pex_python_path, ['>3.6.2'])
assert interpreters[0].binary == pex_python_path.split(':')[6] # 3.6.3
interpreters = find_compatible_interpreters(pex_python_path, ['<2'])
assert not interpreters
interpreters = find_compatible_interpreters(pex_python_path, ['>4'])
assert not interpreters
interpreters = find_compatible_interpreters(pex_python_path, ['<2.7.11, >2.7.9'])
assert interpreters[0].binary == pex_python_path.split(':')[1] # 2.7.10
interpreters = find_compatible_interpreters('', ['<3'])
assert interpreters[0] in PythonInterpreter.all() # All interpreters on PATH