Changeset 134

Show
Ignore:
Timestamp:
08/06/06 17:54:22 (5 years ago)
Author:
mk
Message:

Look for source archives on PyPI first during package retrieval via setuptools.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/mk/cheesecake/cheesecake_index.py

    r132 r134  
    13541354            self.log.info("*** End setuptools output") 
    13551355 
    1356         error = None 
    1357         try: 
    1358             # Temporarily set the log verbosity to INFO so we can capture setuptools info messages. 
    1359             old_threshold = log.set_threshold(log.INFO) 
    1360             pkgindex = PackageIndex() 
    1361             old_stdout = sys.stdout 
    1362             sys.stdout = StdoutRedirector() 
    1363             output = pkgindex.fetch(Requirement.parse(self.name), 
    1364                                     self.sandbox, 
    1365                                     force_scan=True, 
    1366                                     source=False) 
    1367         except DistutilsError, e: 
    1368             error = e 
     1356        def fetch_package(mode): 
     1357            """Fetch package from PyPI. 
     1358 
     1359            Mode can be one of: 
     1360              * 'pypi_source': get source package from PyPI 
     1361              * 'pypi_any': get source/egg package from PyPI 
     1362              * 'any': get package from PyPI or local filesystem 
     1363 
     1364            Returns tuple (status, output), where `status` is True 
     1365            if fetch was successful and False if it failed. `output` 
     1366            is PackageIndex.fetch() return value. 
     1367            """ 
     1368            if 'pypi' in mode: 
     1369                pkgindex = PackageIndex(search_path=[]) 
     1370            else: 
     1371                pkgindex = PackageIndex() 
     1372 
     1373            if mode == 'pypi_source': 
     1374                source = True 
     1375            else: 
     1376                source = False 
     1377 
     1378            try: 
     1379                output = pkgindex.fetch(Requirement.parse(self.name), 
     1380                                        self.sandbox, 
     1381                                        force_scan=True, 
     1382                                        source=source) 
     1383                return True, output 
     1384            except DistutilsError, e: 
     1385                return False, e 
     1386 
     1387        # Temporarily set the log verbosity to INFO so we can capture setuptools 
     1388        # info messages. 
     1389        old_threshold = log.set_threshold(log.INFO) 
     1390        old_stdout = sys.stdout 
     1391        sys.stdout = StdoutRedirector() 
     1392 
     1393        # Try to get source package from PyPI first, then egg from PyPI, and if 
     1394        # that fails search in locally installed packages. 
     1395        for mode, info in [('pypi_source', "source package on PyPI"), 
     1396                           ('pypi_any', "egg on PyPI"), 
     1397                           ('any', "locally installed package")]: 
     1398            msg = "Looking for %s... " % info 
     1399            status, output = fetch_package(mode) 
     1400            if status and output: 
     1401                self.log.info(msg + "found!") 
     1402                break 
     1403            self.log.info(msg + "failed.") 
    13691404 
    13701405        # Bring back old stdout. 
     
    13731408        log.set_threshold(old_threshold) 
    13741409 
    1375         if error: 
    1376             drop_setuptools_info(captured_stdout, error) 
    1377             self.raise_exception("Error: setuptools returned an error: %s\n" % str(error).splitlines()[0]) 
    1378  
     1410        # If all runs failed, we must raise an error. 
     1411        if not status: 
     1412            drop_setuptools_info(captured_stdout, output) 
     1413            self.raise_exception("Error: setuptools returned an error: %s\n" % str(output).splitlines()[0]) 
     1414 
     1415        # If fetch returned nothing, package wasn't found. 
    13791416        if output is None: 
    13801417            drop_setuptools_info(captured_stdout)