Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def test_href_translation():
  VERSIONS = ['0.4.0', '0.4.1', '0.5.0', '0.6.0']

  def fake_link(version):
    return 'http://www.example.com/foo/bar/psutil-%s.tar.gz' % version

  fc = FakeCrawler([fake_link(v) for v in VERSIONS])
  ob = Obtainer(fc, [], [])

  for v in VERSIONS:
    pkgs = list(ob.iter(Requirement.parse('psutil==%s' % v)))
    assert len(pkgs) == 1, 'Version: %s' % v
    assert pkgs[0] == SourcePackage(fake_link(v))

  assert list(ob.iter(Requirement.parse('psutil>=0.5.0'))) == [
    SourcePackage(fake_link('0.6.0')),
    SourcePackage(fake_link('0.5.0'))]

  assert list(ob.iter(Requirement.parse('psutil'))) == [
      SourcePackage(fake_link(v)) for v in reversed(VERSIONS)]
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)