Commits

Vinay Sajip  committed 968fd1f

Bump wheel version to 1.1; support wrapping legacy script declarations.

  • Participants
  • Parent commits 5a94b14

Comments (0)

Files changed (2)

File distlib/wheel.py

 from .database import InstalledDistribution
 from .metadata import Metadata, METADATA_FILENAME
 from .util import (FileOperator, convert_path, CSVReader, CSVWriter,
-                   cached_property, get_cache_base)
+                   cached_property, get_cache_base, read_exports)
 
 
 logger = logging.getLogger(__name__)
     Class to build and install from Wheel files (PEP 427).
     """
 
-    wheel_version = (1, 0)
+    wheel_version = (1, 1)
     hash_kind = 'sha256'
 
     def __init__(self, filename=None, sign=False, verify=False):
             else:
                 libdir = paths['platlib']
 
-            # Try to get pydist.json so we can see if there are
-            # any commands to generate. If this fails (e.g. because
-            # of a legacy wheel), log a warning but don't give up.
-            try:
-                with zf.open(metadata_name) as bwf:
-                    wf = wrapper(bwf)
-                    metadict = json.load(wf)
-            except Exception:
-                logger.warning('Unable to read JSON metadata, so unable to '
-                               'generate scripts')
-                metadict = {}
             records = {}
             with zf.open(record_name) as bf:
                 with CSVReader(stream=bf) as reader:
                     dist = None
                 else:
                     # Generate scripts
-                    commands = metadict.get('commands')
+
+                    # Try to get pydist.json so we can see if there are
+                    # any commands to generate. If this fails (e.g. because
+                    # of a legacy wheel), log a warning but don't give up.
+                    commands = None
+                    file_version = self.info['Wheel-Version']
+                    if file_version == '1.0':
+                        # Use legacy info
+                        ep = posixpath.join(info_dir, 'entry_points.txt')
+                        try:
+                            with zf.open(ep) as bwf:
+                                epdata = read_exports(bwf)
+                            commands = {}
+                            for key in ('console', 'gui'):
+                                k = '%s_scripts' % key
+                                if k in epdata:
+                                    commands['wrap_%s' % key] = d = {}
+                                    for v in epdata[k].values():
+                                        s = '%s:%s' % (v.prefix, v.suffix)
+                                        if v.flags:
+                                            s += ' %s' % v.flags
+                                        d[v.name] = s
+                        except Exception:
+                            logger.warning('Unable to read legacy script '
+                                           'metadata, so cannot generate '
+                                           'scripts')
+                    else:
+                        try:
+                            with zf.open(metadata_name) as bwf:
+                                wf = wrapper(bwf)
+                                commands = json.load(wf).get('commands')
+                        except Exception:
+                            logger.warning('Unable to read JSON metadata, so '
+                                           'cannot generate scripts')
                     if commands:
                         console_scripts = commands.get('wrap_console', {})
                         gui_scripts = commands.get('wrap_gui', {})

File tests/test_wheel.py

 
         for name, values in cases:
             w = Wheel(name)
-            self.assertEqual(w.wheel_version, (1, 0))
+            self.assertEqual(w.wheel_version, (1, 1))
             self.assertEqual(w.filename, name)
             for attr, value in zip(attrs, values):
                 self.assertEqual(getattr(w, attr), value)
         ENDING = '-%s-none-any.whl' % PYVER
         for name, values in cases:
             w = Wheel(name)
-            self.assertEqual(w.wheel_version, (1, 0))
+            self.assertEqual(w.wheel_version, (1, 1))
             self.assertTrue(w.filename.endswith(ENDING))
             for attr, value in zip(attrs, values):
                 self.assertEqual(getattr(w, attr), value)