Beispiel #1
0
  def find(self, requirement, platform=pkg_resources.get_platform(), py_version=None):
    """
      Query the location of a distribution that fulfills a requirement.

      Returns a tuple of:
        location = the location of the distribution (or None if none found.)
        repo = the repo in which it was found (or None if local or not found.)
    """
    if py_version is None:
      py_version = '%s.%s' % (sys.version_info[0], sys.version_info[1])

    env = pkg_resources.Environment()
    if isinstance(requirement, str):
      requirement = pkg_resources.Requirement.parse(requirement)
    # first check the local cache
    for dist in pkg_resources.find_distributions(self._cache):
      if dist in requirement and env.can_add(dist):
        return (dist.location, None)
    # if nothing found, go out to remotes
    for repo in self._pis:
      repo.find_packages(requirement)
      for package in repo[requirement.project_name]:
        if pkg_resources.compatible_platforms(package.platform, platform):
          if package.py_version is not None and package.py_version != py_version:
            continue
          if package not in requirement:
            continue
          return (package.location, repo)
    return (None, None)
Beispiel #2
0
 def fetch( self, requirement ):
     """
     fetch() serves as the install method to pkg_resources.working_set.resolve()
     """
     def find_alternative():
         """
         Some platforms (e.g. Solaris) support eggs compiled on older platforms
         """
         class LinkParser( HTMLParser.HTMLParser ):
             """
             Finds links in what should be an Apache-style directory index
             """
             def __init__( self ):
                 HTMLParser.HTMLParser.__init__( self )
                 self.links = []
             def handle_starttag( self, tag, attrs ):
                 if tag == 'a' and 'href' in dict( attrs ):
                     self.links.append( dict( attrs )['href'] )
         parser = LinkParser()
         try:
             parser.feed( urllib2.urlopen( self.url + '/' ).read() )
         except urllib2.HTTPError, e:
             if e.code == 404:
                 return None
         parser.close()
         for link in parser.links:
             file = urllib.unquote( link ).rsplit( '/', 1 )[-1]
             tmp_dist = pkg_resources.Distribution.from_filename( file )
             if tmp_dist.platform is not None and \
                     self.distribution.project_name == tmp_dist.project_name and \
                     self.distribution.version == tmp_dist.version and \
                     self.distribution.py_version == tmp_dist.py_version and \
                     pkg_resources.compatible_platforms( tmp_dist.platform, pkg_resources.get_platform() ):
                 return file
         return None
Beispiel #3
0
 def fetch( self, requirement ):
     """
     fetch() serves as the install method to pkg_resources.working_set.resolve()
     """
     def find_alternative():
         """
         Some platforms (e.g. Solaris) support eggs compiled on older platforms
         """
         class LinkParser( HTMLParser.HTMLParser ):
             """
             Finds links in what should be an Apache-style directory index
             """
             def __init__( self ):
                 HTMLParser.HTMLParser.__init__( self )
                 self.links = []
             def handle_starttag( self, tag, attrs ):
                 if tag == 'a' and 'href' in dict( attrs ):
                     self.links.append( dict( attrs )['href'] )
         parser = LinkParser()
         try:
             parser.feed( urllib2.urlopen( self.url + '/' ).read() )
         except urllib2.HTTPError, e:
             if e.code == 404:
                 return None
         parser.close()
         for link in parser.links:
             file = urllib.unquote( link ).rsplit( '/', 1 )[-1]
             tmp_dist = pkg_resources.Distribution.from_filename( file )
             if tmp_dist.platform is not None and \
                     self.distribution.project_name == tmp_dist.project_name and \
                     self.distribution.version == tmp_dist.version and \
                     self.distribution.py_version == tmp_dist.py_version and \
                     pkg_resources.compatible_platforms( tmp_dist.platform, pkg_resources.get_platform() ):
                 return file
         return None
Beispiel #4
0
  def find(self, requirement, platform=pkg_resources.get_platform()):
    """
      Query the location of a distribution that fulfills a requirement.

      Returns a tuple of:
        location = the location of the distribution (or None if none found.)
        repo = the repo in which it was found (or None if local or not found.)
    """
    if isinstance(requirement, str):
      requirement = pkg_resources.Requirement.parse(requirement)
    # first check the local cache
    for dist in pkg_resources.find_distributions(self._cache):
      if dist in requirement and pkg_resources.compatible_platforms(dist.platform, platform):
        return (dist.location, None)
    # if nothing found, go out to remotes
    for repo in self._pis:
      repo.find_packages(requirement)
      for package in repo[requirement.project_name]:
        if pkg_resources.compatible_platforms(package.platform, platform):
          return (package.location, repo)
    return (None, None)
Beispiel #5
0
 def compatible(package, platform):
   if package is None or platform is None or package == platform:
     return True
   MAJOR, MINOR, PLATFORM = range(1, 4)
   package_match = Platform.MACOSX_VERSION_STRING.match(package)
   platform_match = Platform.MACOSX_VERSION_STRING.match(platform)
   if not (package_match and platform_match):
     return compatible_platforms(package, platform)
   if package_match.group(MAJOR) != platform_match.group(MAJOR):
     return False
   if int(package_match.group(MINOR)) > int(platform_match.group(MINOR)):
     return False
   package_platform = package_match.group(PLATFORM)
   if package_platform not in Platform.MACOSX_PLATFORM_COMPATIBILITY:
     raise Platform.UnknownPlatformError(package_platform)
   sys_platform = platform_match.group(PLATFORM)
   if sys_platform not in Platform.MACOSX_PLATFORM_COMPATIBILITY:
     raise Platform.UnknownPlatformError(sys_platform)
   package_compatibility = set(Platform.MACOSX_PLATFORM_COMPATIBILITY[package_platform])
   system_compatibility = set(Platform.MACOSX_PLATFORM_COMPATIBILITY[sys_platform])
   return bool(package_compatibility.intersection(system_compatibility))
Beispiel #6
0
 def compatible(package, platform):
   if package is None or platform is None or package == platform:
     return True
   MAJOR, MINOR, PLATFORM = range(1,4)
   package_match = Platform.MACOSX_VERSION_STRING.match(package)
   platform_match = Platform.MACOSX_VERSION_STRING.match(platform)
   if not (package_match and platform_match):
     return pkg_resources.compatible_platforms(package, platform)
   if package_match.group(MAJOR) != platform_match.group(MAJOR):
     return False
   if int(package_match.group(MINOR)) > int(platform_match.group(MINOR)):
     return False
   package_platform = package_match.group(PLATFORM)
   if package_platform not in Platform.MACOSX_PLATFORM_COMPATIBILITY:
     raise Platform.UnknownPlatformError(package_platform)
   sys_platform = platform_match.group(PLATFORM)
   if sys_platform not in Platform.MACOSX_PLATFORM_COMPATIBILITY:
     raise Platform.UnknownPlatformError(sys_platform)
   package_compatibility = set(Platform.MACOSX_PLATFORM_COMPATIBILITY[package_platform])
   system_compatibility = set(Platform.MACOSX_PLATFORM_COMPATIBILITY[sys_platform])
   return bool(package_compatibility.intersection(system_compatibility))