Exemple #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)
Exemple #2
0
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)
Exemple #3
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')
Exemple #4
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)
Exemple #5
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')
Exemple #6
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]
  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)
Exemple #8
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]
Exemple #9
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)
Exemple #10
0
 def egg_package(version):
     return EggPackage('setuptools-%s-py2.7.egg' % version)