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)
Beispiel #2
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)
Beispiel #3
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(FakeObtainer([tgz, egg, whl]).iter(req)) == [whl, egg, tgz]
    assert list(FakeObtainer([egg, tgz, whl]).iter(req)) == [whl, egg, tgz]
Beispiel #4
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]
Beispiel #5
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 Obtainer.package_precedence(whl) > Obtainer.package_precedence(egg)
    assert Obtainer.package_precedence(egg) > Obtainer.package_precedence(
        source)
    assert Obtainer.package_precedence(whl) > Obtainer.package_precedence(
        source)

    # overridden precedence
    PRECEDENCE = (EggPackage, WheelPackage)
    assert Obtainer.package_precedence(source,
                                       PRECEDENCE) == (source.version, -1
                                                       )  # unknown rank
    assert Obtainer.package_precedence(
        whl, PRECEDENCE) > Obtainer.package_precedence(source, PRECEDENCE)
    assert Obtainer.package_precedence(
        egg, PRECEDENCE) > Obtainer.package_precedence(whl, PRECEDENCE)
Beispiel #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.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]