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)
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]
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)