If not isinstancespec requirement scheme

This preview shows page 10 - 12 out of 18 pages.

"""if not isinstance(spec, Requirement):scheme = URL_SCHEME(spec)if scheme:# It's a url, download it to tmpdirfound = self._download_url(scheme.group(1), spec, tmpdir)base, fragment = egg_info_for_url(spec)if base.endswith('.py'):found = self.gen_setup(found, fragment, tmpdir)return foundelif os.path.exists(spec):# Existing file or directory, just return itreturn specelse:spec = parse_requirement_arg(spec)return getattr(self.fetch_distribution(spec, tmpdir), 'location', None)def fetch_distribution( # noqa: C901 # is too complex (14) # FIXMEself, requirement, tmpdir, force_scan=False, source=False,develop_ok=False, local_index=None):"""Obtain a distribution suitable for fulfilling `requirement``requirement` must be a ``pkg_resources.Requirement`` instance.If necessary, or if the `force_scan` flag is set, the requirement issearched for in the (online) package index as well as the locallyinstalled packages. If a distribution matching `requirement` is found,the returned distribution's ``location`` is the value you would havegotten from calling the ``download()`` method with the matchingdistribution's URL or filename. If no matching distribution is found,``None`` is returned.If the `source` flag is set, only source distributions and sourcecheckout links will be considered. Unless the `develop_ok` flag isset, development and system eggs (i.e., those using the ``.egg-info``format) will be ignored."""# process a Requirementself.info("Searching for %s", requirement)skipped = {}dist = Nonedef find(req, env=None):if env is None:env = self# Find a matching distribution; may be called more than oncefor dist in env[req.key]:if dist.precedence == DEVELOP_DIST and not develop_ok:if dist not in skipped:self.warn("Skipping development or system egg: %s", dist,)skipped[dist] = 1continuetest = (dist in req
and (dist.precedence <= SOURCE_DIST or not source))if test:loc = self.download(dist.location, tmpdir)dist.download_location = locif os.path.exists(dist.download_location):return distif force_scan:self.prescan()self.find_packages(requirement)dist = find(requirement)if not dist and local_index is not None:dist = find(requirement, local_index)if dist is None:if self.to_scan is not None:self.prescan()dist = find(requirement)if dist is None and not force_scan:self.find_packages(requirement)dist = find(requirement)if dist is None:self.warn("No local packages or working download links found for %s%s",(source and "a source distribution of " or ""),requirement,)else:self.info("Best match: %s", dist)return dist.clone(location=dist.download_location)def fetch(self, requirement, tmpdir, force_scan=False, source=False):"""Obtain a file suitable for fulfilling `requirement`DEPRECATED; use the ``fetch_distribution()`` method now instead. Forbackward compatibility, this routine is identical but returns the``location`` of the downloaded distribution instead of a distributionobject."""dist = self.fetch_distribution(requirement, tmpdir, force_scan, source)if dist is not None:return dist.locationreturn Nonedef gen_setup(self, filename, fragment, tmpdir):match = EGG_FRAGMENT.match(fragment)dists = match and [d for d ininterpret_distro_name(filename, match.group(1), None) if d.version] or []if len(dists) == 1: # unambiguous ``#egg`` fragmentbasename = os.path.basename(filename)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 18 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
CharlesD.Allison
Tags

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture