How to use the pex.package.EggPackage function in pex

To help you get started, we’ve selected a few pex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pantsbuild / pex / tests / test_package.py View on Github external
for req in ('psutil', 'psutil>0.4', 'psutil==0.4.1', 'psutil>0.4.0,<0.4.2'):
    assert el.satisfies(req)
  for req in ('foo', 'bar==0.4.1'):
    assert not el.satisfies(req)

  el = EggPackage('pytz-2012b-py2.6.egg')
  assert el.name == 'pytz'
  assert el.raw_version == '2012b'
  assert el.py_version == '2.6'
  assert el.platform is None

  # Eggs must have their own version and a python version.
  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-1.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-py2.6.egg')
github pantsbuild / pex / tests / test_package.py View on Github external
def test_egg_packages():
  el = EggPackage('psutil-0.4.1-py2.6-macosx-10.7-intel.egg')
  assert el.name == 'psutil'
  assert el.raw_version == '0.4.1'
  assert el.py_version == '2.6'
  assert el.platform == 'macosx-10.7-intel'
  for req in ('psutil', 'psutil>0.4', 'psutil==0.4.1', 'psutil>0.4.0,<0.4.2'):
    assert el.satisfies(req)
  for req in ('foo', 'bar==0.4.1'):
    assert not el.satisfies(req)

  el = EggPackage('pytz-2012b-py2.6.egg')
  assert el.name == 'pytz'
  assert el.raw_version == '2012b'
  assert el.py_version == '2.6'
  assert el.platform is None

  # Eggs must have their own version and a python version.
github pantsbuild / pex / tests / test_environment.py View on Github external
def test_osx_platform_intel_issue_523():
  def bad_interpreter(include_site_extras=True):
    return PythonInterpreter.from_binary(_KNOWN_BAD_APPLE_INTERPRETER,
                                         include_site_extras=include_site_extras)

  interpreter = bad_interpreter(include_site_extras=False)
  with temporary_dir() as cache:
    # We need to run the bad interpreter with a modern, non-Apple-Extras setuptools in order to
    # successfully install psutil.
    for requirement in (SETUPTOOLS_REQUIREMENT, WHEEL_REQUIREMENT):
      for dist in resolver.resolve([requirement],
                                   cache=cache,
                                   # We can't use wheels since we're bootstrapping them.
                                   precedence=(SourcePackage, EggPackage),
                                   interpreter=interpreter):
        interpreter = interpreter.with_extra(dist.key, dist.version, dist.location)

    with nested(yield_pex_builder(installer_impl=WheelInstaller, interpreter=interpreter),
                temporary_filename()) as (pb, pex_file):
      for dist in resolver.resolve(['psutil==5.4.3'],
                                   cache=cache,
                                   precedence=(SourcePackage, WheelPackage),
                                   interpreter=interpreter):
        pb.add_dist_location(dist.location)
      pb.build(pex_file)

      # NB: We want PEX to find the bare bad interpreter at runtime.
      pex = PEX(pex_file, interpreter=bad_interpreter())
      args = ['-c', 'import pkg_resources; print(pkg_resources.get_supported_platform())']
      env = os.environ.copy()
github pantsbuild / pex / tests / test_package.py View on Github external
def test_egg_packages():
  el = EggPackage('psutil-0.4.1-py2.6-macosx-10.7-intel.egg')
  assert el.name == 'psutil'
  assert el.raw_version == '0.4.1'
  assert el.py_version == '2.6'
  assert el.platform == 'macosx-10.7-intel'
  for req in ('psutil', 'psutil>0.4', 'psutil==0.4.1', 'psutil>0.4.0,<0.4.2'):
    assert el.satisfies(req)
  for req in ('foo', 'bar==0.4.1'):
    assert not el.satisfies(req)

  # Legacy pkg_resources normalized version numbers.
  el = EggPackage('pyfoo-1.0.0_bar-py2.7-linux-x86_64.egg')
  assert el.name == 'pyfoo'
  assert el.raw_version == '1.0.0-bar'
  assert el.py_version == '2.7'
  assert el.platform == 'linux-x86_64'
  for req in ('pyfoo', 'pyfoo==1.0.0-bar'):
github pantsbuild / pex / tests / test_package.py View on Github external
assert el.platform == 'linux-x86_64'
  for req in ('pyfoo', 'pyfoo==1.0.0-bar'):
    assert el.satisfies(req)

  el = EggPackage('pytz-2012b-py2.6.egg')
  assert el.name == 'pytz'
  assert el.raw_version == '2012b0'
  assert el.py_version == '2.6'
  assert el.platform is None

  # Eggs must have their own version and a python version.
  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-1.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-py2.6.egg')
github pantsbuild / pex / tests / test_package.py View on Github external
assert el.satisfies(req)
  for req in ('foo', 'bar==0.4.1'):
    assert not el.satisfies(req)

  el = EggPackage('pytz-2012b-py2.6.egg')
  assert el.name == 'pytz'
  assert el.raw_version == '2012b'
  assert el.py_version == '2.6'
  assert el.platform is None

  # Eggs must have their own version and a python version.
  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-1.egg')

  with pytest.raises(EggPackage.InvalidPackage):
    EggPackage('bar-py2.6.egg')
github pantsbuild / pex / tests / test_iterator.py View on Github external
def test_package_precedence():
  source = SourcePackage('psutil-0.6.1.tar.gz')
  egg = EggPackage('psutil-0.6.1-py2.6.egg')
  whl = WheelPackage('psutil-0.6.1-cp26-none-macosx_10_4_x86_64.whl')

  # default precedence
  assert Iterator.package_precedence(whl) > Iterator.package_precedence(egg)
  assert Iterator.package_precedence(egg) > Iterator.package_precedence(source)
  assert Iterator.package_precedence(whl) > Iterator.package_precedence(source)

  # overridden precedence
  PRECEDENCE = (EggPackage, WheelPackage)
  assert Iterator.package_precedence(source, PRECEDENCE) == (
      source.version, -1, True)  # unknown rank
  assert Iterator.package_precedence(whl, PRECEDENCE) > Iterator.package_precedence(
      source, PRECEDENCE)
  assert Iterator.package_precedence(egg, PRECEDENCE) > Iterator.package_precedence(
      whl, PRECEDENCE)
github apache / incubator-heron / third_party / pex / pex / bin / pex.py View on Github external
links = [link for link in iterator.iter(requirement) if isinstance(link, SourcePackage)]

  with TRACER.timed('Interpreter cache resolving %s' % requirement, V=2):
    for link in links:
      with TRACER.timed('Fetching %s' % link, V=3):
        sdist = context.fetch(link)

      with TRACER.timed('Installing %s' % link, V=3):
        installer = installer_provider(sdist)
        dist_location = installer.bdist()
        target_location = os.path.join(
            os.path.dirname(target_link), os.path.basename(dist_location))
        shutil.move(dist_location, target_location)
        _safe_link(target_location, target_link)

      return EggPackage(target_location)
github pantsbuild / pex / pex / sorter.py View on Github external
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import absolute_import

from pex.package import EggPackage, SourcePackage, WheelPackage


class Sorter(object):
  DEFAULT_PACKAGE_PRECEDENCE = (
      WheelPackage,
      EggPackage,
      SourcePackage,
  )

  @classmethod
  def package_type_precedence(cls, package, precedence=DEFAULT_PACKAGE_PRECEDENCE):
    for rank, package_type in enumerate(reversed(precedence)):
      if isinstance(package, package_type):
        return rank
    # If we do not recognize the package, it gets lowest precedence
    return -1

  @classmethod
  def package_platform_tag_precedence(cls, package):
    # Give all non 'any' tags higher precedence
    supported_tags = package.supported_tags or []
    platforms = set([tags[2] for tags in supported_tags])
github apache / incubator-heron / third_party / pex / pex / bin / pex.py View on Github external
def _resolve_and_link_interpreter(requirement, fetchers, target_link, installer_provider):
  # Short-circuit if there is a local copy
  if os.path.exists(target_link) and os.path.exists(os.path.realpath(target_link)):
    egg = EggPackage(os.path.realpath(target_link))
    if egg.satisfies(requirement):
      return egg

  context = Context.get()
  iterator = Iterator(fetchers=fetchers, crawler=Crawler(context))
  links = [link for link in iterator.iter(requirement) if isinstance(link, SourcePackage)]

  with TRACER.timed('Interpreter cache resolving %s' % requirement, V=2):
    for link in links:
      with TRACER.timed('Fetching %s' % link, V=3):
        sdist = context.fetch(link)

      with TRACER.timed('Installing %s' % link, V=3):
        installer = installer_provider(sdist)
        dist_location = installer.bdist()
        target_location = os.path.join(