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_sorter_sort():
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()))
assert Sorter().sort([tgz, egg, whl]) == [whl, egg, tgz]
assert Sorter().sort([egg, tgz, whl]) == [whl, egg, tgz]
# test unknown type
sorter = Sorter(precedence=(EggPackage, WheelPackage))
assert sorter.sort([egg, tgz, whl], filter=False) == [egg, whl, tgz]
assert sorter.sort([egg, tgz, whl], filter=True) == [egg, whl]
def test_all_does_not_raise_with_empty_path_envvar(self):
""" additionally, tests that the module does not raise at import """
with patch.dict(os.environ, clear=True):
if PY3:
import importlib
importlib.reload(interpreter)
else:
reload(interpreter)
interpreter.PythonInterpreter.all()
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={})
compile_folder = safe_mkdtemp()
pex_builder = PEXBuilder(
path=output if options.directory else compile_folder,
def __init__(self, context, target, run_tracker, interpreter=None):
self.context = context
self.target = target
self.interpreter = interpreter or PythonInterpreter.get()
if not isinstance(target, PythonBinary):
raise PythonBinaryBuilder.NotABinaryTargetException(
"Target %s is not a PythonBinary!" % target)
self.distdir = context.options.for_global_scope().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)
def prepare(cls, options, round_manager):
round_manager.require_data(PythonInterpreter)
round_manager.optional_product(SharedLibrary)
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()
with TRACER.timed('Setting up interpreter %s' % interpreter.binary, V=2):
resolve = functools.partial(resolve_interpreter, options.interpreter_cache_dir, options.repos)
# resolve setuptools
interpreter = resolve(interpreter, SETUPTOOLS_REQUIREMENT)
# possibly resolve wheel
if interpreter and options.use_wheel:
interpreter = resolve(interpreter, WHEEL_REQUIREMENT)
return interpreter
def prepare(cls, options, round_manager):
super().prepare(options, round_manager)
round_manager.require_data(PythonInterpreter)
round_manager.require_data(ResolveRequirements.REQUIREMENTS_PEX)
round_manager.require_data(GatherSources.PYTHON_SOURCES)
def execute(self):
if not self.context.targets(lambda t: is_python_target(t) or has_python_requirements(t)):
return
interpreter = self.context.products.get_data(PythonInterpreter)
pex = self.resolve_requirements(interpreter, self.context.targets(has_python_requirements))
self.context.products.register_data(self.REQUIREMENTS_PEX, pex)
unspecified only stable versions will be resolved, unless explicitly included.
:keyword pkg_blacklist: (optional) A blacklist dict (str->str) that maps package name to
an interpreter constraint. If a package name is in the blacklist and its interpreter
constraint matches the target interpreter, skip the requirement. This is needed to ensure
that universal requirement resolves for a target interpreter version do not error out on
interpreter specific requirements such as backport libs like `functools32`.
For example, a valid blacklist is {'functools32': 'CPython>3'}.
NOTE: this keyword is a temporary fix and will be reverted in favor of a long term solution
tracked by: https://github.com/pantsbuild/pex/issues/456
:yields: All :class:`pkg_resources.Distribution` instances meeting ``requirements``.
:raises Unsatisfiable: If ``requirements`` is not transitively satisfiable.
:raises Untranslateable: If no compatible distributions could be acquired for
a particular requirement.
"""
interpreters = interpreters or [PythonInterpreter.get()]
platforms = platforms or ['current']
seen = set()
for interpreter in interpreters:
for platform in platforms:
for resolvable in resolve(requirements,
fetchers,
interpreter,
platform,
context,
precedence,
cache,
cache_ttl,
allow_prereleases,
pkg_blacklist=pkg_blacklist,
use_manylinux=use_manylinux):