def locate_at(source, dest): if dest is None or realpath(dest) == realpath(source): return source try: os.link(source, dest) except (AttributeError, OSError): shutil.copyfile(source, dest) return dest
def _obtain(self, requirement, source=None): """ Copy in and override the installer's obtain method to modify the following behavior: - allow us to differentiate between third-party and in-house packages when applying the prefer-final / prefer-dev logic """ # Look at zc.buildout source for comments on this logic index = self._index if index.obtain(requirement) is None: return None dists = [dist for dist in index[requirement.project_name] if ( dist in requirement and ( dist.location not in self._site_packages or self.allow_site_package_egg(dist.project_name)) and ( (not source) or (dist.precedence == pkg_resources.SOURCE_DIST)) ) ] # Filter for final/dev and use the result if it is non empty. version_comparitor = self.get_version_comparitor(requirement) filtered_dists = [dist for dist in dists if version_comparitor(dist.parsed_version)] if filtered_dists: log.debug(' filtered to:') [log.debug(' {0!r}'.format(i)) for i in filtered_dists] dists = filtered_dists # The rest of this logic is as-is from buildout best = [] bestv = () for dist in dists: distv = dist.parsed_version if distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) log.debug(' best picks are:') [log.debug(' {0!r}'.format(i)) for i in best] if not best: return None if len(best) == 1: return best[0] # TODO: buildout behavior we're not using? if self._download_cache: for dist in best: if (easy_install.realpath(os.path.dirname(dist.location)) == self._download_cache): return dist best.sort() dist = best[-1] log.debug('best is {0!r}'.format(dist)) return dist
def download_cache(self): if self.cache is not None: return realpath(os.path.join(self.directory, self.cache))
def _obtain(self, requirement, source=None): """ Copy in and override the installer's obtain method to modify the following behavior: - allow us to differentiate between third-party and in-house packages when applying the prefer-final / prefer-dev logic """ # Look at zc.buildout source for comments on this logic index = self._index if index.obtain(requirement) is None: return None dists = [ dist for dist in index[requirement.project_name] if (dist in requirement and ( dist.location not in self._site_packages or self.allow_site_package_egg(dist.project_name)) and ( (not source) or (dist.precedence == pkg_resources.SOURCE_DIST))) ] # Filter for final/dev and use the result if it is non empty. version_comparator = self.get_version_comparator(requirement) def parsed_version_for(dist): """ Sidestep some broken-ness in pkg_resource.Distribution.parsed_version fighting with __getattr__ """ return pkg_resources.parse_version(dist.version) filtered_dists = [ dist for dist in dists if version_comparator(parsed_version_for(dist)) ] if filtered_dists: log.debug(' --- filtered to:') [log.debug(' ---- {0!r}'.format(i)) for i in filtered_dists] dists = filtered_dists # The rest of this logic is as-is from buildout best = [] bestv = () for dist in dists: distv = dist.parsed_version if distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) log.debug(' --- best picks are:') [log.debug(' ---- {0!r}'.format(i)) for i in best] if not best: return None if len(best) == 1: return best[0] # TODO: buildout behavior we're not using? if self._download_cache: for dist in best: if easy_install.realpath(os.path.dirname( dist.location)) == self._download_cache: return dist best.sort() dist = best[-1] log.debug(' --- best is {0!r}'.format(dist)) return dist
def _obtain(self, requirement, source=None): """ Copy in and override the installer's obtain method to modify the following behavior: - allow us to differentiate between third-party and in-house packages when applying the prefer-final / prefer-dev logic """ # Look at zc.buildout source for comments on this logic index = self._index if index.obtain(requirement) is None: return None dists = [dist for dist in index[requirement.project_name] if ( dist in requirement and ( dist.location not in self._site_packages or self.allow_site_package_egg(dist.project_name)) and ( (not source) or (dist.precedence == pkg_resources.SOURCE_DIST)) ) ] # Here we pick between 'dev' or 'final' versions. # We want to use different logic depending on if this is a third-party # or in-house package: # In-house-packages: we usually want the latest dev version as keeping # on head revisions is sensible to stop code # going stale # Third-party: we usually want the latest final version to protect # ourselves from OSS developers exposing their # latest untested code to the intenet at large. # To overridde this logic the packager needs to specify an explicit # version pin in install_requires or similar for third-party packages, # or use the prefer-final setup flag for in-house packages. # If we prefer final dists, filter for final and use the # result if it is non empty. if manage.is_inhouse_package(requirement.project_name): if self._prefer_final: log.debug(' in-house package, prefer-final') version_comparitor = easy_install._final_version else: log.debug(' in-house package, prefer-dev') version_comparitor = self.is_dev_version else: log.debug(' third-party package, always prefer-final') version_comparitor = easy_install._final_version filtered_dists = [dist for dist in dists if version_comparitor(dist.parsed_version)] if filtered_dists: log.debug(' filtered to {0}'.format(filtered_dists)) dists = filtered_dists # The rest of this logic is as-is from buildout best = [] bestv = () for dist in dists: distv = dist.parsed_version if distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) log.debug(' best picks are {0}'.format(best)) if not best: return None if len(best) == 1: return best[0] if self._download_cache: for dist in best: if (easy_install.realpath(os.path.dirname(dist.location)) == self._download_cache): return dist best.sort() return best[-1]
def _obtain(self, requirement, source=None): # initialize out index for this project: index = self._index if index.obtain(requirement) is None: # Nothing is available. return None # Filter the available dists for the requirement and source flag. If # we are not supposed to include site-packages for the given egg, we # also filter those out. Even if include_site_packages is False and so # we have excluded site packages from the _env's paths (see # Installer.__init__), we need to do the filtering here because an # .egg-link, such as one for setuptools or zc.buildout installed by # zc.buildout.buildout.Buildout.bootstrap, can indirectly include a # path in our _site_packages. dists = [dist for dist in index[requirement.project_name] if ( dist in requirement and ( dist.location not in self._site_packages or self.allow_site_package_egg(dist.project_name)) and ( (not source) or (dist.precedence == pkg_resources.SOURCE_DIST)) ) ] # If we prefer final dists, filter for final and use the # result if it is non empty. if self._prefer_final: fdists = [dist for dist in dists if _final_version(dist.parsed_version) ] if fdists: # There are final dists, so only use those dists = fdists # Now find the best one: best = [] bestv = () for dist in dists: distv = dist.parsed_version if distv > bestv: best = [dist] bestv = distv elif distv == bestv: best.append(dist) if not best: return None if len(best) == 1: return best[0] if self._download_cache: for dist in best: if (realpath(os.path.dirname(dist.location)) == self._download_cache ): return dist # BEGIN LAVA MODIFICATIONS for dist in best: if dist.location.startswith('http://pypi.python.org/'): return dist # END LAVA MODIFICATIONS best.sort() return best[-1]