Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_interpreter_caching(self, test_interpreter1, test_interpreter2):
py_interpreter1 = interpreter.PythonInterpreter.from_binary(test_interpreter1)
py_interpreter2 = interpreter.PythonInterpreter.from_binary(test_interpreter2)
assert py_interpreter1 is not py_interpreter2
assert py_interpreter2.identity.version == self.TEST_INTERPRETER2_VERSION_TUPLE
py_interpreter3 = interpreter.PythonInterpreter.from_binary(test_interpreter1)
assert py_interpreter1 is py_interpreter3
def _validate_good_interpreter_path_file(path):
with open(path, 'r') as fp:
lines = fp.readlines()
binary = lines[0].strip()
try:
interpreter = PythonInterpreter.from_binary(binary)
return True if interpreter else False
except Executor.ExecutableNotFound:
return False
def wheel_installer(*mixins):
bare_interpreter = PythonInterpreter.from_binary(ensure_python_interpreter(PY36))
with make_installer(installer_impl=OrderableInstaller,
interpreter=bare_interpreter,
mixins=list(mixins)) as installer:
yield installer
def test_resolve_current_and_foreign_platforms(p537_resolve_cache):
foreign_platform = 'macosx-10.13-x86_64-cp-37-m' if IS_LINUX else 'manylinux1_x86_64-cp-37-m'
resolve_current_and_foreign = functools.partial(resolve_p537_wheel_names,
cache=p537_resolve_cache,
platforms=['current', foreign_platform])
assert 2 == len(resolve_current_and_foreign())
other_python_version = PY36 if PY_VER == (3, 5) else PY35
other_python = PythonInterpreter.from_binary(ensure_python_interpreter(other_python_version))
current_python = PythonInterpreter.get()
assert 2 == len(resolve_current_and_foreign(interpreters=[current_python]))
assert 2 == len(resolve_current_and_foreign(interpreters=[other_python]))
assert 2 == len(resolve_current_and_foreign(interpreters=[current_python, current_python]))
# Here we have 2 local interpreters, satisfying current, but with different platforms and thus
# different dists and then the foreign platform for 3 total dists.
assert 3 == len(resolve_current_and_foreign(interpreters=[current_python, other_python]))
return 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)
# 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.
if not options.python:
options.python = sys.executable
identity = PythonIdentity.get()
elif not options.python_version:
# Note: this is expensive (~500ms). prefer passing --python-version when possible.
identity = PythonInterpreter.from_binary(options.python).identity
else:
# Convert "CPython 2.7" to "CPython 2 7 0"
python_version = options.python_version.replace(".", " ").split()
if len(python_version) == 3:
python_version.append("0")
identity = PythonIdentity.from_id_string(" ".join(python_version))
interpreter = PythonInterpreter(options.python, identity, extras={})
pex_builder = PEXBuilder(
path=output if options.directory else None, interpreter=interpreter
)
if options.python_shebang is not None:
pex_builder.set_shebang(options.python_shebang)
def to_python_interpreter(full_path_or_basename):
if os.path.exists(full_path_or_basename):
return PythonInterpreter.from_binary(full_path_or_basename)
else:
interpreter = PythonInterpreter.from_env(full_path_or_basename)
if interpreter is None:
die('Failed to find interpreter: %s' % full_path_or_basename)
return interpreter
def try_create(try_path):
try:
return PythonInterpreter.from_binary(try_path)
except Executor.ExecutionError:
return None
poptions.find_links = options.find_links
poptions.pypi = options.pypi
poptions.python = options.python
poptions.zip_safe = options.zip_safe
poptions.disable_cache = options.disable_cache
#print("pex options: %s" % poptions)
os.environ["PATH"] = ".:%s:/bin:/usr/bin" % poptions.python
# The version of pkg_resources.py (from setuptools) on some distros is too old for PEX. So
# we keep a recent version in and force it into the process by constructing a custom
# PythonInterpreter instance using it.
interpreter = PythonInterpreter(
poptions.python,
PythonInterpreter.from_binary(options.python).identity,
extras={
# TODO: Fix this to resolve automatically
('setuptools', '18.0.1'): 'third_party/pex/setuptools-18.0.1-py2.py3-none-any.whl',
('wheel', '0.23.0'): 'third_party/pex/wheel-0.23.0-py2.7.egg'
})
# resolve setuptools
interpreter = resolve_or_die(interpreter, SETUPTOOLS_REQUIREMENT, poptions)
# possibly resolve wheel
if interpreter and poptions.use_wheel:
interpreter = resolve_or_die(interpreter, WHEEL_REQUIREMENT, poptions)
# Add prebuilt libraries listed in the manifest.
reqs = manifest.get('requirements', {}).keys()
#if len(reqs) > 0: