Daniel Holth avatar Daniel Holth committed 5d9214a

pull compatibility check out of wheel.install

Comments (0)

Files changed (4)

 For lxml, an up to 3-minute "search for the newest version and compile"
 can become a less-than-1 second "unpack from wheel".
 
+To build an individual wheel, run ``python setup.py bdist_wheel``.  Note that
+``bdist_wheel`` only works with distribute (``import setuptools``); plain
+``distutils`` does not support pluggable commands like ``bdist_wheel``.  On
+the other hand ``pip`` always runs ``setup.py`` with setuptools enabled. 
+
 File Contents
 -------------
 
 from wheel.decorator import reify
 from wheel.util import urlsafe_b64encode, from_json,\
     urlsafe_b64decode, native, binary, generate_supported, \
-    HashingFile, compatibility_match
+    HashingFile
 from wheel import signatures
 from wheel.pkginfo import read_pkg_info_bytes
 from wheel.bdist_wheel import open_for_csv
             self.verify(vzf)
         return vzf
 
+    @reify
+    def parsed_wheel_info(self):
+        """Parse wheel metadata"""
+        return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
+
     def get_metadata(self):
         pass
 
 
     @property
     def arity(self):
-        '''The number of compatibility tags the wheel declares.'''
+        """The number of compatibility tags the wheel declares."""
         return len(list(self.compatibility_tags))
 
     def compatibility_rank(self, supported):
-        '''Rank the wheel against the supported ones.
+        """Rank the wheel against the supported ones.
 
         :param supported: A list of compatibility tags that the current
             Python implemenation can run.
-        '''
+        """
         preferences = []
         for tag in self.compatibility_tags:
             try:
                 pass
         return (min(preferences), self.arity)
 
-    @reify
-    def parsed_wheel_info(self):
-        """Parse wheel metadata"""
-        return read_pkg_info_bytes(self.zipfile.read(self.wheelinfo_name))
-
-    def supports_current_python(self):
-        for tags in generate_supported():
-            for dtags in self.compatibility_tags:
-                if compatibility_match(dtags, tags):
-                    return True
+    def supports_current_python(self, generate_supported=generate_supported):
+        supported = generate_supported()
+        for dtag in self.compatibility_tags:
+            if dtag in supported:
+                return True
         return False
 
     def install(self, force=False, overrides={}):
-        """Install the wheel into site-packages"""
+        """Install the wheel into site-packages.
+        """
 
         # Utility to get the target directory for a particular key
         def get_path(key):
         # We're now ready to start processing the actual install. The process
         # is as follows:
         #   1. Prechecks - is the wheel valid, is its declared architecture
-        #      OK, etc. [[Should probably have already been done]]
+        #      OK, etc. [[Responsibility of the caller]]
         #   2. Overwrite check - do any of the files to be installed already
         #      exist?
         #   3. Actual install - put the files in their target locations.
         #   4. Update RECORD - write a suitably modified RECORD file to
         #      reflect the actual installed paths.
-        self.check_version()
-        if not self.supports_current_python():
-            raise ValueError("Wheel was not built for this version of Python")
-
+        
         if not force:
             for k, v in name_trans.items():
                 target, filename, dest = v
                 if os.path.exists(dest):
-                    raise ValueError("Wheel file {} would overwrite an existing file. Use force is this is intended".format(k))
+                    raise ValueError("Wheel file {} would overwrite an existing file. Use force if this is intended".format(k))
 
         record_data = []
         for name, (target, filename, dest) in name_trans.items():

wheel/test/test_install.py

 # The root is PLATLIB
 # So, some in PLATLIB, and one in each of DATA, HEADERS and SCRIPTS.
 
+import wheel.util
 from wheel.install import WheelFile
 from tempfile import mkdtemp
 import shutil
 def test_install():
     whl = WheelFile(TESTWHEEL)
     tempdir = mkdtemp()
+    def generate_supported():
+        return list(wheel.util.generate_supported()) + [('py3', 'none', 'win32')]
+    assert whl.supports_current_python(generate_supported)
     try:
         locs = {}
         for key in ('purelib', 'platlib', 'scripts', 'headers', 'data'):
         
     return supported
 
-def compatibility_match(declared, tag):
-    dpyver, dabi, dplat = declared
-    pyver, abi, plat = tag
-
-    # Platform: declared 'any' or matches
-    if dplat != 'any' and dplat != plat:
-        return False
-    # ABI: declared 'none' or matches
-    if dabi != 'none' and dabi != abi:
-        return False
-
-    # Python version: Implementation must match unless declared as 'py'
-    # (generic), major version must match, and if declared as for a specific
-    # minor version this must match too.
-    if dpyver[:2] != 'py' and dpyver[:2] != pyver[:2]:
-        return False
-    if dpyver[2] != pyver[2]:
-        return False
-    if len(dpyver) > 3 and dpyver[3] != pyver[3]:
-        return False
-    return True
 
 class HashingFile(object):
     def __init__(self, fd, hashtype='sha256'):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.