Daniel Holth avatar Daniel Holth committed 8cc9318

fix wheel keygen

Comments (0)

Files changed (3)

+0.10.2
+======
+- Fix keygen
+
 0.10.1
 ======
 - Preserve attributes on install.
     signature_reqs.append('dirspec')
 
 setup(name='wheel',
-      version='0.10.1',
+      version='0.10.2',
       description='A built-package format for Python.',
       long_description=README + '\n\n' +  CHANGES,
       classifiers=[

wheel/tool/__init__.py

 import os
 import hashlib
 import sys
-import wheel.signatures
 import json
 from glob import iglob
 from pkg_resources import Distribution, Requirement
+from .. import signatures
 from ..util import urlsafe_b64decode, urlsafe_b64encode, native, binary
 from ..wininst2wheel import bdist_wininst2wheel
 from ..egg2wheel import egg2wheel
 
 import argparse
 
-def keygen():
-    """Generate a public/private key pair."""
+# For testability
+def get_keyring():    
     try:
         from ..signatures import keys
         import keyring
     except ImportError:
         raise Exception("Install wheel[signatures] (keyring, dirspec) for signatures")
-    ed25519ll = wheel.signatures.get_ed25519ll()
+    return keys.WheelKeys, keyring
 
-    wk = wheel.keys.WheelKeys().load()
+def keygen(get_keyring=get_keyring):
+    """Generate a public/private key pair."""
+    WheelKeys, keyring = get_keyring()
+    
+    ed25519ll = signatures.get_ed25519ll()
+
+    wk = WheelKeys().load()
     
     keypair = ed25519ll.crypto_sign_keypair()
     vk = native(urlsafe_b64encode(keypair.vk))
     wk.trust('+', vk)
     wk.save()
 
-def sign(wheelfile, replace=False):
+def sign(wheelfile, replace=False, get_keyring=get_keyring):
     """Sign a wheel"""
-    try:
-        from ..signatures import keys
-        import keyring
-    except ImportError:
-        raise Exception("Install wheel[signatures] (keyring, dirspec) for signatures")
-    ed25519ll = wheel.signatures.get_ed25519ll()
+    WheelKeys, keyring = get_keyring()
+
+    ed25519ll = signatures.get_ed25519ll()
     
-    wf = wheel.install.WheelFile(wheelfile, append=True)
-    wk = keys.WheelKeys().load()
+    wf = WheelFile(wheelfile, append=True)
+    wk = WheelKeys().load()
     
     name = wf.parsed_filename.group('name')
     sign_with = wk.signers(name)[0]
         raise NotImplementedError("Wheel is already signed")
     record_data = wf.zipfile.read(record_name)
     payload = {"hash":"sha256="+native(urlsafe_b64encode(hashlib.sha256(record_data).digest()))}
-    sig = wheel.signatures.sign(payload, keypair)
+    sig = signatures.sign(payload, keypair)
     wf.zipfile.writestr(sig_name, json.dumps(sig, sort_keys=True))
     wf.zipfile.close()
 
 def verify(wheelfile):
     """Verify a wheel."""
     import pprint
-    wf = wheel.install.WheelFile(wheelfile)
+    wf = install.WheelFile(wheelfile)
     sig_name = wf.distinfo_name + '/RECORD.jws'
     sig = json.loads(native(wf.zipfile.open(sig_name).read()))
     sys.stdout.write("Signatures are internally consistent.\n%s\n" % (
-                     pprint.pformat(wheel.signatures.verify(sig),)))
+                     pprint.pformat(signatures.verify(sig),)))
 
 def unpack(wheelfile, dest='.'):
     """Unpack a wheel.
     :param wheelfile: The path to the wheel.
     :param dest: Destination directory (default to current directory).
     """
-    wf = wheel.install.WheelFile(wheelfile)
+    wf = WheelFile(wheelfile)
     namever = wf.parsed_filename.group('namever')
     destination = os.path.join(dest, namever)
     sys.stdout.write("Unpacking to: %s\n" % (destination))
     for d in wheel_dirs:
         for w in os.listdir(d):
             if w.endswith('.whl'):
-                wf = wheel.install.WheelFile(os.path.join(d, w))
+                wf = WheelFile(os.path.join(d, w))
                 if wf.supports_current_python():
                     all_wheels.append(wf)
 
         if req.endswith('.whl'):
             # Explicitly specified wheel filename
             if os.path.exists(req):
-                wf = wheel.install.WheelFile(req)
+                wf = WheelFile(req)
                 if wf.supports_current_python() or force:
                     to_install.append(wf)
                 else:
                     msg = ("{} is not compatible with this Python. "
-                           "--force to install anyway.".format(wheelfile))
+                           "--force to install anyway.".format(req))
                     raise Exception(msg)
             else:
                 # We could search on wheel_dirs, but it's probably OK to
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.