Commits

Anonymous committed 545719c

Made .egg support optional, off by default. Added platform check for links.

Comments (0)

Files changed (1)

 import logging
 import ConfigParser
 
+"""
+NOTES
+
+platform check for egg links:
+
+pkg_resources.Distribution.from_location(url, basename).platform
+pkg_resources.compatible_platforms(_, pkg_resources.get_supported_platform())
+
+"""
+
 class InstallationError(Exception):
     """General exception during installation"""
 
             "Use multiple --install-option options to pass multiple options to setup.py install.  "
             "If you are using an option with a directory path, be sure to use absolute path."
             )
+        self.parser.add_option(
+            '--eggs', '--allow-eggs',
+            action='store_true',
+            dest='allow_eggs',
+            default=False,
+            help='Allow installation from built eggs')
+        self.parser.add_option(
+            '--prefer-eggs',
+            action='store_true',
+            dest='prefer_eggs',
+            default=False,
+            help='Prefer installation from built eggs, when available. '
+            'Implies --allow-eggs')
 
     def run(self, options, args):
         if not options.build_dir:
         options.src_dir = os.path.abspath(options.src_dir)
         install_options = options.install_options or []
         index_urls = [options.index_url] + options.extra_index_urls
+        if options.prefer_eggs:
+            options.allow_eggs = True
         finder = PackageFinder(
             find_links=options.find_links,
-            index_urls=index_urls)
+            index_urls=index_urls,
+            allow_eggs=options.allow_eggs,
+            prefer_eggs=options.prefer_eggs)
         requirement_set = RequirementSet(
             build_dir=options.build_dir,
             src_dir=options.src_dir,
 
     failure_limit = 3
 
-    def __init__(self, find_links, index_urls):
+    def __init__(self, find_links, index_urls, allow_eggs=False,
+                 prefer_eggs=False):
         self.find_links = find_links
         self.index_urls = index_urls
+        self.allow_eggs = allow_eggs
+        self.prefer_eggs = prefer_eggs
         self.dependency_links = []
         self.cache = PageCache()
         # These are boring links that have already been logged somehow:
         self.logged_links = set()
+        self.allowed_extensions = ('.tar.gz', '.tar.bz2', '.tar', '.tgz',
+                                   '.zip')
+        if self.allow_eggs:
+            self.allowed_extensions = self.allowed_extensions + ('.egg',)
 
     def add_dependency_links(self, links):
         ## FIXME: this shouldn't be global list this, it should only
         self.dependency_links.extend(links)
 
     def find_requirement(self, req, upgrade):
+        # FIXME arch check here for eggs?
         url_name = req.url_name
         # Check that we have the url_name correctly spelled:
         main_index_url = Link(posixpath.join(self.index_urls[0], url_name))
                 logger.info("Ignoring link %s, version %s doesn't match %s"
                             % (link, version, ','.join([''.join(s) for s in req.req.specs])))
                 continue
+            dist = pkg_resources.Distribution.from_location(
+                link.url, link.filename)
+            if dist.platform and not pkg_resources.compatible_platforms(
+                dist.platform, pkg_resources.get_supported_platform()):
+                logger.info("Ignoring link %s, platform %s doesn't match %s"
+                            % (link, dist.platform,
+                               pkg_resources.get_supported_platform()))
+                continue
             applicable_versions.append((link, version))
         existing_applicable = bool([link for link, version in applicable_versions if link is Inf])
         if not upgrade and existing_applicable:
                         % (req.satisfied_by.version, ', '.join([version for link, version in applicable_versions[1:]]) or 'none'))
             return None
         if len(applicable_versions) > 1:
+            # FIXME prefer_eggs check here
             logger.info('Using version %s (newest of versions: %s)' %
                         (applicable_versions[0][1], ', '.join([version for link, version in applicable_versions])))
         return applicable_versions[0][0]
     _py_version_re = re.compile(r'-py([123]\.[0-9])$')
 
     def _package_versions(self, links, search_name):
+        # FIXME need to check architecture for built eggs
+        # here or egg_info_matches
         seen_links = {}
         for link in links:
             if link.url in seen_links:
                     # Special double-extension case:
                     egg_info = egg_info[:-4]
                     ext = '.tar' + ext
-                if ext not in ('.tar.gz', '.tar.bz2', '.tar', '.tgz', '.zip', '.egg'):
+                    
+                if ext not in self.allowed_extensions:
                     if link not in self.logged_links:
                         logger.debug('Skipping link %s; unknown archive format: %s' % (link, ext))
                         self.logged_links.add(link)