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_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] == SourceLink(fake_link(v)) assert list(ob.iter(Requirement.parse('psutil>=0.5.0'))) == [ SourceLink(fake_link('0.6.0')), SourceLink(fake_link('0.5.0'))] assert list(ob.iter(Requirement.parse('psutil'))) == [ SourceLink(fake_link(v)) for v in reversed(VERSIONS)]
def iter(self, requirement): if hasattr(requirement, 'repository') and requirement.repository: obtainer = Obtainer(crawler=self._crawler, fetchers=[Fetcher([requirement.repository])], translators=self._translator) for package in obtainer.iter(requirement): yield package else: for package in super(PantsObtainer, self).iter(requirement): yield package
def iter(self, requirement): if hasattr(requirement, 'repository') and requirement.repository: obtainer = Obtainer( crawler=self._crawler, fetchers=[Fetcher([requirement.repository])], translators=self._translator) for package in obtainer.iter(requirement): yield package else: for package in super(PantsObtainer, self).iter(requirement): yield package
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(map(fake_link, VERSIONS)) ob = Obtainer(fc, [], []) for v in VERSIONS: pkgs = list(ob.iter(Requirement.parse('psutil==%s' % v))) assert len(pkgs) == 1 assert pkgs[0] == SourceLink(fake_link(v)) assert list(ob.iter(Requirement.parse('psutil>=0.5.0'))) == [ SourceLink(fake_link('0.6.0')), SourceLink(fake_link('0.5.0')) ] assert list(ob.iter(Requirement.parse('psutil'))) == map( SourceLink, map(fake_link, reversed(VERSIONS)))
def setup_distribute(self, interpreter, dest): obtainer = Obtainer(self._crawler, self._fetchers, []) obtainer_iterator = obtainer.iter(self._setuptools_requirement) links = [link for link in obtainer_iterator if isinstance(link, SourceLink)] for link in links: self._logger('Fetching %s' % link) sdist = link.fetch() self._logger('Installing %s' % sdist) installer = Installer(sdist, strict=False, interpreter=interpreter) dist = installer.distribution() self._logger('Distilling %s' % dist) egg = Distiller(dist).distill(into=dest) safe_link(egg, os.path.join(dest, 'distribute')) break
def setup_distribute(self, interpreter, dest): obtainer = Obtainer(self._crawler, self._fetchers, []) obtainer_iterator = obtainer.iter(self._setuptools_requirement) links = [ link for link in obtainer_iterator if isinstance(link, SourceLink) ] for link in links: self._logger('Fetching %s' % link) sdist = link.fetch() self._logger('Installing %s' % sdist) installer = Installer(sdist, strict=False, interpreter=interpreter) dist = installer.distribution() self._logger('Distilling %s' % dist) egg = Distiller(dist).distill(into=dest) safe_link(egg, os.path.join(dest, 'distribute')) break
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)