Daniel Holth avatar Daniel Holth committed 90f98f3

use distutils installation schemes instead of sysconfig.get_paths

Comments (0)

Files changed (5)

     signature_reqs.append('dirspec')
 
 setup(name='wheel',
-      version='0.12.0',
+      version='0.13.0',
       description='A built-package format for Python.',
       long_description=README + '\n\n' +  CHANGES,
       classifiers=[
 import hashlib
 import csv
 
-try:
-    import sysconfig
-except ImportError:
-    import distutils.sysconfig as sysconfig
 import shutil
 
 try:
 from wheel import signatures
 from wheel.pkginfo import read_pkg_info_bytes
 from wheel.util import open_for_csv
+
 from .pep425tags import get_supported
+from .paths import get_install_paths
 
 # The next major version after this version of the 'wheel' tool:
 VERSION_TOO_HIGH = (1, 0)
     WHEEL_INFO = "WHEEL"
     RECORD = "RECORD"
 
-    def __init__(self, 
-                 filename, 
-                 fp=None, 
-                 append=False, 
+    def __init__(self,
+                 filename,
+                 fp=None,
+                 append=False,
                  context=get_supported):
         """
         :param fp: A seekable file-like object or None to open(filename).
         if tuple(map(int, version.split('.'))) >= VERSION_TOO_HIGH:
             raise ValueError("Wheel version is too high")
 
+    @reify
+    def install_paths(self):
+        """
+        Consult distutils to get the install paths for our dist.  A dict with
+        ('purelib', 'platlib', 'headers', 'scripts', 'data').
+        
+        We use the name from our filename as the dist name, which means headers
+        could be installed in the wrong place if the filesystem-escaped name
+        is different than the Name.  Who cares? 
+        """
+        name = self.parsed_filename.group('name')
+        return get_install_paths(name)
+
     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):
-            return overrides.get(key) or sysconfig.get_path(key)
+            return overrides.get(key) or self.install_paths[key]
 
         # The base target location is either purelib or platlib
         if self.parsed_wheel_info['Root-Is-Purelib'] == 'true':
             headers, payload = signatures.verify(sig)
             if payload['hash'] != "sha256=" + native(record_digest):
                 msg = "RECORD.sig claimed RECORD hash {0} != computed hash {1}."
-                raise BadWheelFile(msg.format(payload['hash'], 
+                raise BadWheelFile(msg.format(payload['hash'],
                                               native(record_digest)))
         
         reader = csv.reader((native(r) for r in record.splitlines()))
     an expected sha256 hash. Note that each file must be completly read in 
     order for its hash to be checked."""
     
-    def __init__(self, file, mode="r", 
-                 compression=zipfile.ZIP_STORED, 
+    def __init__(self, file, mode="r",
+                 compression=zipfile.ZIP_STORED,
                  allowZip64=False):
         zipfile.ZipFile.__init__(self, file, mode, compression, allowZip64)
 
+"""
+Installation paths.
+
+Map the .data/ subdirectory names to install paths.
+"""
+
+from distutils.command.install import install, SCHEME_KEYS
+
+def get_install_paths(name):
+    """
+    Return the (distutils) install paths for the named dist.
+    
+    A dict with ('purelib', 'platlib', 'headers', 'scripts', 'data') keys.
+    """
+     # can't import up top due to monkeypatching
+    from distutils.dist import Distribution
+
+    paths = {}
+    d = Distribution({'name':name})
+    i = install(d)
+    i.finalize_options()
+    for key in SCHEME_KEYS:
+        paths[key] = getattr(i, 'install_'+key)
+    return paths

wheel/test/test_paths.py

+import wheel.paths
+from distutils.command.install import SCHEME_KEYS
+
+def test_path():
+    d = wheel.paths.get_install_paths('wheel')
+    assert len(d) == len(SCHEME_KEYS)

wheel/test/test_tool.py

+from .. import tool
+
+def test_keygen():    
+    def get_keyring():
+        WheelKeys, keyring = tool.get_keyring()
+        
+        class WheelKeysTest(WheelKeys):
+            def save(self):
+                pass
+        
+        class keyringTest:
+            backend = keyring.backend
+            @classmethod
+            def get_keyring(cls):
+                class keyringTest2:
+                    pw = None
+                    def set_password(self, a, b, c):
+                        self.pw = c
+                    def get_password(self, a, b):
+                        return self.pw
+                    
+                return keyringTest2()
+        
+        return WheelKeysTest, keyringTest
+    
+    tool.keygen(get_keyring=get_keyring)
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.