def _get_dist(self, requirement, ws, always_unzip): """The only difference between this and the standard implementation is that it doesn't copy eggs from the egg cache but links to them in place.""" __doing__ = 'Getting distribution for %r.', str(requirement) # Maybe an existing dist is already the best dist that satisfies the # requirement dist, avail = self._satisfied(requirement) if dist is None: if self._dest is not None: easy_install.logger.info(*__doing__) # Retrieve the dist: if avail is None: raise easy_install.MissingDistribution(requirement, ws) # We may overwrite distributions, so clear importer # cache. sys.path_importer_cache.clear() tmp = self._download_cache if tmp is None: tmp = easy_install.tempfile.mkdtemp('get_dist') try: dist = self._fetch(avail, tmp, self._download_cache) if dist is None: raise easy_install.zc.buildout.UserError( "Couldn't download distribution %s." % avail) if dist.precedence == pkg_resources.EGG_DIST: # It's already an egg, just fetch it into the dest newloc = os.path.join(self._dest, os.path.basename(dist.location)) # The next 2 lines are new, this is the only bit that is different from the standard if egg_cache.is_from_egg_cache(dist.location): newloc = dist.location elif os.path.isdir(dist.location): # we got a directory. It must have been # obtained locally. Just copy it. shutil.copytree(dist.location, newloc) else: if self._always_unzip: should_unzip = True else: metadata = pkg_resources.EggMetadata( zipimport.zipimporter(dist.location)) should_unzip = ( metadata.has_metadata('not-zip-safe') or not metadata.has_metadata('zip-safe')) if should_unzip: easy_install.setuptools.archive_util.unpack_archive( dist.location, newloc) else: shutil.copyfile(dist.location, newloc) easy_install.redo_pyc(newloc) # Getting the dist from the environment causes the # distribution meta data to be read. Cloning isn't # good enough. dists = pkg_resources.Environment( [newloc], python=easy_install._get_version(self._executable), )[dist.project_name] else: # It's some other kind of dist. We'll let easy_install # deal with it: dists = self._call_easy_install(dist.location, ws, self._dest, dist) for dist in dists: easy_install.redo_pyc(dist.location) finally: if tmp != self._download_cache: shutil.rmtree(tmp) self._env.scan([self._dest]) dist = self._env.best_match(requirement, ws) easy_install.logger.info("Got %s.", dist) else: dists = [dist] for dist in dists: if (dist.has_metadata('dependency_links.txt') and not self._install_from_cache and self._use_dependency_links): for link in dist.get_metadata_lines('dependency_links.txt'): link = link.strip() if link not in self._links: easy_install.logger.debug( 'Adding find link %r from %s', link, dist) self._links.append(link) self._index = easy_install._get_index( self._executable, self._index_url, self._links, self._allow_hosts, self._path) for dist in dists: # Check whether we picked a version and, if we did, report it: if not (dist.precedence == pkg_resources.DEVELOP_DIST or (len(requirement.specs) == 1 and requirement.specs[0][0] == '==')): easy_install.logger.debug('Picked: %s = %s', dist.project_name, dist.version) if not self._allow_picked_versions: raise easy_install.zc.buildout.UserError( 'Picked: %s = %s' % (dist.project_name, dist.version)) return dists
def _get_dist(self, requirement, ws, always_unzip): """The only difference between this and the standard implementation is that it doesn't copy eggs from the egg cache but links to them in place.""" __doing__ = 'Getting distribution for %r.', str(requirement) # Maybe an existing dist is already the best dist that satisfies the # requirement dist, avail = self._satisfied(requirement) if dist is None: if self._dest is not None: easy_install.logger.info(*__doing__) # Retrieve the dist: if avail is None: raise easy_install.MissingDistribution(requirement, ws) # We may overwrite distributions, so clear importer # cache. sys.path_importer_cache.clear() tmp = self._download_cache if tmp is None: tmp = easy_install.tempfile.mkdtemp('get_dist') try: dist = self._fetch(avail, tmp, self._download_cache) if dist is None: raise easy_install.zc.buildout.UserError( "Couldn't download distribution %s." % avail) if dist.precedence == pkg_resources.EGG_DIST: # It's already an egg, just fetch it into the dest newloc = os.path.join( self._dest, os.path.basename(dist.location)) # The next 2 lines are new, this is the only bit that is different from the standard if egg_cache.is_from_egg_cache(dist.location): newloc = dist.location elif os.path.isdir(dist.location): # we got a directory. It must have been # obtained locally. Just copy it. shutil.copytree(dist.location, newloc) else: if self._always_unzip: should_unzip = True else: metadata = pkg_resources.EggMetadata( zipimport.zipimporter(dist.location) ) should_unzip = ( metadata.has_metadata('not-zip-safe') or not metadata.has_metadata('zip-safe') ) if should_unzip: easy_install.setuptools.archive_util.unpack_archive( dist.location, newloc) else: shutil.copyfile(dist.location, newloc) easy_install.redo_pyc(newloc) # Getting the dist from the environment causes the # distribution meta data to be read. Cloning isn't # good enough. dists = pkg_resources.Environment( [newloc], python=easy_install._get_version(self._executable), )[dist.project_name] else: # It's some other kind of dist. We'll let easy_install # deal with it: dists = self._call_easy_install( dist.location, ws, self._dest, dist) for dist in dists: easy_install.redo_pyc(dist.location) finally: if tmp != self._download_cache: shutil.rmtree(tmp) self._env.scan([self._dest]) dist = self._env.best_match(requirement, ws) easy_install.logger.info("Got %s.", dist) else: dists = [dist] for dist in dists: if (dist.has_metadata('dependency_links.txt') and not self._install_from_cache and self._use_dependency_links ): for link in dist.get_metadata_lines('dependency_links.txt'): link = link.strip() if link not in self._links: easy_install.logger.debug('Adding find link %r from %s', link, dist) self._links.append(link) self._index = easy_install._get_index(self._executable, self._index_url, self._links, self._allow_hosts, self._path) for dist in dists: # Check whether we picked a version and, if we did, report it: if not ( dist.precedence == pkg_resources.DEVELOP_DIST or (len(requirement.specs) == 1 and requirement.specs[0][0] == '==') ): easy_install.logger.debug('Picked: %s = %s', dist.project_name, dist.version) if not self._allow_picked_versions: raise easy_install.zc.buildout.UserError( 'Picked: %s = %s' % (dist.project_name, dist.version) ) return dists
def get_index(*args, **kwargs): index = _get_index(*args, **kwargs) index.opener = fake_urlopen return index