Esempio n. 1
0
File: pex.py Progetto: Houzz/pex
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(
            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)
Esempio n. 2
0
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.
  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')
Esempio n. 3
0
def _resolve_and_link(config,
                      requirement,
                      target_link,
                      installer_provider,
                      logger=print):
    # 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

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

    for link in links:
        logger('    fetching %s' % link.url)
        sdist = context.fetch(link)
        logger('    installing %s' % sdist)
        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)
        logger('    installed %s' % target_location)
        return EggPackage(target_location)
Esempio n. 4
0
File: pex.py Progetto: windie/heron
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(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)
Esempio n. 5
0
def _resolve_and_link(config,
                      requirement,
                      target_link,
                      installer_provider,
                      logger=print):
    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
    fetchers = fetchers_from_config(config)
    crawler = crawler_from_config(config)
    obtainer = Obtainer(crawler, fetchers, [])
    obtainer_iterator = obtainer.iter(requirement)
    links = [
        link for link in obtainer_iterator if isinstance(link, SourcePackage)
    ]
    for link in links:
        logger('    fetching %s' % link.url)
        sdist = link.fetch()
        logger('    installing %s' % sdist)
        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)
        logger('    installed %s' % target_location)
        return EggPackage(target_location)
Esempio n. 6
0
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.
    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')
Esempio n. 7
0
def _resolve_and_link(config, requirement, target_link, installer_provider, logger=print):
  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
  fetchers = fetchers_from_config(config)
  crawler = crawler_from_config(config)
  obtainer = Obtainer(crawler, fetchers, [])
  obtainer_iterator = obtainer.iter(requirement)
  links = [link for link in obtainer_iterator if isinstance(link, SourcePackage)]
  for link in links:
    logger('    fetching %s' % link.url)
    sdist = link.fetch()
    logger('    installing %s' % sdist)
    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)
    logger('    installed %s' % target_location)
    return EggPackage(target_location)
Esempio n. 8
0
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'):
    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')
Esempio n. 9
0
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(FakeIterator([tgz, egg, whl]).iter(req)) == [whl, egg, tgz]
    assert list(FakeIterator([egg, tgz, whl]).iter(req)) == [whl, egg, tgz]
Esempio n. 10
0
def _resolve_and_link(config, requirement, target_link, installer_provider, logger=print):
  # 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

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

  for link in links:
    logger('    fetching %s' % link.url)
    sdist = context.fetch(link)
    logger('    installing %s' % sdist)
    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)
    logger('    installed %s' % target_location)
    return EggPackage(target_location)
Esempio n. 11
0
  def _resolve_and_link(self, requirement, 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

    fetchers = self._python_repos.get_fetchers()
    context = self._python_repos.get_network_context()
    iterator = Iterator(fetchers=fetchers, crawler=Crawler(context))
    links = [link for link in iterator.iter(requirement) if isinstance(link, SourcePackage)]

    for link in links:
      self._logger('    fetching {}'.format(link.url))
      sdist = context.fetch(link)
      self._logger('    installing {}'.format(sdist))
      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)
      self._logger('    installed {}'.format(target_location))
      return EggPackage(target_location)
Esempio n. 12
0
  def _resolve_and_link(self, requirement, 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

    fetchers = self._python_repos.get_fetchers()
    context = self._python_repos.get_network_context()
    iterator = Iterator(fetchers=fetchers, crawler=Crawler(context))
    links = [link for link in iterator.iter(requirement) if isinstance(link, SourcePackage)]

    for link in links:
      self._logger('    fetching {}'.format(link.url))
      sdist = context.fetch(link)
      self._logger('    installing {}'.format(sdist))
      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)
      self._logger('    installed {}'.format(target_location))
      return EggPackage(target_location)
Esempio n. 13
0
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]
Esempio n. 14
0
def test_resolvable_set_built():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.packages() == [(rq, set([source_pkg]), None, False)]

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])

  updated_rs = rs.replace_built({source_pkg: binary_pkg})
  updated_rs.merge(rq, [binary_pkg])
  assert updated_rs.get('foo') == set([binary_pkg])
  assert updated_rs.packages() == [(rq, set([binary_pkg]), None, False)]
Esempio n. 15
0
def test_resolvable_set_built():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.packages() == [(rq, set([source_pkg]), None, False)]

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])

  updated_rs = rs.replace_built({source_pkg: binary_pkg})
  updated_rs.merge(rq, [binary_pkg])
  assert updated_rs.get('foo') == set([binary_pkg])
  assert updated_rs.packages() == [(rq, set([binary_pkg]), None, False)]
Esempio n. 16
0
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 Sorter.package_precedence(whl) > Sorter.package_precedence(egg)
  assert Sorter.package_precedence(egg) > Sorter.package_precedence(source)
  assert Sorter.package_precedence(whl) > Sorter.package_precedence(source)

  # overridden precedence
  PRECEDENCE = (EggPackage, WheelPackage)
  assert Sorter.package_precedence(source, PRECEDENCE) == (
      source.version, -1, 0, True, source.url)  # unknown rank
  assert Sorter.package_precedence(whl, PRECEDENCE) > Sorter.package_precedence(
      source, PRECEDENCE)
  assert Sorter.package_precedence(egg, PRECEDENCE) > Sorter.package_precedence(
      whl, PRECEDENCE)
Esempio n. 17
0
def test_resolvable_set():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo[ext]', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg, binary_pkg])
  assert rs.get('foo') == set([source_pkg, binary_pkg])
  assert rs.packages() == [(rq, set([source_pkg, binary_pkg]), None)]

  # test methods
  assert rs.extras('foo') == set(['ext'])

  # test filtering
  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])
Esempio n. 18
0
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.
  with pytest.raises(EggPackage.InvalidLink):
    EggPackage('bar.egg')

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

  with pytest.raises(EggPackage.InvalidLink):
    EggPackage('bar-py2.6.egg')

  dateutil = 'python_dateutil-1.5-py2.6.egg'
  with create_layout([dateutil]) as td:
    el = EggPackage('file://' + os.path.join(td, dateutil), opener=Web())

    with temporary_dir() as td2:
      # local file fetch w/o location will always remain same
      loc1 = el.fetch()
      assert loc1 == os.path.join(td, dateutil)

      el.fetch(location=td2)
      assert os.listdir(td2) == [dateutil]
Esempio n. 19
0
def test_resolvable_set():
  builder = ResolverOptionsBuilder()
  rs = _ResolvableSet()
  rq = ResolvableRequirement.from_string('foo[ext]', builder)
  source_pkg = SourcePackage.from_href('foo-2.3.4.tar.gz')
  binary_pkg = EggPackage.from_href('Foo-2.3.4-py3.4.egg')

  rs.merge(rq, [source_pkg, binary_pkg])
  assert rs.get(source_pkg.name) == set([source_pkg, binary_pkg])
  assert rs.get(binary_pkg.name) == set([source_pkg, binary_pkg])
  assert rs.packages() == [(rq, set([source_pkg, binary_pkg]), None, False)]

  # test methods
  assert rs.extras('foo') == set(['ext'])
  assert rs.extras('Foo') == set(['ext'])

  # test filtering
  rs.merge(rq, [source_pkg])
  assert rs.get('foo') == set([source_pkg])
  assert rs.get('Foo') == set([source_pkg])

  with pytest.raises(Unsatisfiable):
    rs.merge(rq, [binary_pkg])
Esempio n. 20
0
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'):
        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')
Esempio n. 21
0
 def egg_package(version):
     return EggPackage('setuptools-%s-py2.7.egg' % version)