Commits

Vinay Sajip  committed aa93f06

Improved local version handling and added ABI derivation.

  • Participants
  • Parent commits fac3c6b

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, read_exports, tempdir)
+                   cached_property, get_cache_base, read_exports)
 
 
 logger = logging.getLogger(__name__)
 if ABI and ABI.startswith('cpython-'):
     ABI = ABI.replace('cpython-', 'cp')
 else:
-    ABI = 'none'
+    def _derive_abi():
+        parts = ['cp', VER_SUFFIX]
+        if sysconfig.get_config_var('Py_DEBUG'):
+            parts.append('d')
+        if sysconfig.get_config_var('WITH_PYMALLOC'):
+            parts.append('m')
+        if sysconfig.get_config_var('Py_UNICODE_SIZE') == 4:
+            parts.append('u')
+        return ''.join(parts)
+    ABI = _derive_abi()
+    del _derive_abi
 
 FILENAME_RE = re.compile(r'''
 (?P<nm>[^-]+)
             if m:
                 info = m.groupdict('')
                 self.name = info['nm']
-                self.version = info['vn']
+                # Reinstate the local version separator
+                self.version = info['vn'].replace('_', '-')
                 self.buildver = info['bn']
                 self._filename = self.filename
             else:
         pyver = '.'.join(self.pyver)
         abi = '.'.join(self.abi)
         arch = '.'.join(self.arch)
-        version = self.version
-        if '-' in version:
-            # lose any local component
-            version = version.split('-', 1)[0]
+        # replace - with _ as a local version separator
+        version = self.version.replace('-', '_')
         return '%s-%s%s-%s-%s-%s.whl' % (self.name, version, buildver,
                                          pyver, abi, arch)
 

File tests/test_wheel.py

 from compat import unittest
 
 from distlib import DistlibException
-from distlib.compat import ZipFile
+from distlib.compat import ZipFile, sysconfig
 from distlib.database import DistributionPath, InstalledDistribution
 from distlib.manifest import Manifest
 from distlib.metadata import Metadata, METADATA_FILENAME
         del sys.modules['minimext']
         self.assertRaises(ImportError, __import__, 'minimext')
 
+    def test_local_version(self):
+        w = Wheel('dummy-0.1_1.2')
+        self.assertEqual(w.filename, 'dummy-0.1_1.2-%s'
+                                     '-none-any.whl' % PYVER)
+        self.assertEqual(w.name, 'dummy')
+        self.assertEqual(w.version, '0.1-1.2')
+        self.assertFalse(w.exists)
+        w.version = '0.1-1.3'
+        self.assertEqual(w.filename, 'dummy-0.1_1.3-%s'
+                                     '-none-any.whl' % PYVER)
+
+    def test_abi(self):
+        pyver = sysconfig.get_config_var('py_version_nodot')
+        if not pyver:
+            pyver = '%s%s' % sys.version_info[:2]
+        parts = ['cp', pyver]
+        if sysconfig.get_config_var('Py_DEBUG'):
+            parts.append('d')
+        if sysconfig.get_config_var('WITH_PYMALLOC'):
+            parts.append('m')
+        if sysconfig.get_config_var('Py_UNICODE_SIZE') == 4:
+            parts.append('u')
+        self.assertEqual(''.join(parts), ABI)
+
     @unittest.skipIf('SKIP_SLOW' in os.environ, 'Skipping slow test')
     @unittest.skipUnless(PIP_AVAILABLE, 'pip is needed for this test')
     def test_build_and_install_pure(self):