Skip to content

Commit

Permalink
Replaced direct writes to sys.stdout/stderr with print() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 30, 2017
1 parent fe2ed11 commit d120bf9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Unreleased
==========
- Fixed displaying of errors on Python 3

0.30.0
======
- Added py-limited-api {cp32|cp33|cp34|...} flag to produce cpNN.abi3.{arch}
Expand Down
6 changes: 4 additions & 2 deletions wheel/egg2wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ def main():
for pat in args.eggs:
for egg in iglob(pat):
if args.verbose:
sys.stdout.write("{0}... ".format(egg))
print("{}... ".format(egg))
sys.stdout.flush()

egg2wheel(egg, args.dest_dir)
if args.verbose:
sys.stdout.write("OK\n")
print("OK")


if __name__ == "__main__":
Expand Down
5 changes: 4 additions & 1 deletion wheel/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
# XXX see patched pip to install

from __future__ import print_function

import csv
import hashlib
import os.path
Expand Down Expand Up @@ -417,8 +419,9 @@ def verify(self, zipfile=None):
hash = row[1]
if not hash:
if filename not in (record_name, sig_name):
sys.stderr.write("%s has no hash!\n" % filename)
print("%s has no hash!" % filename, file=sys.stderr)
continue

algo, data = row[1].split('=', 1)
assert algo == "sha256", "Unsupported hash algorithm"
zipfile.set_expected_hash(filename, urlsafe_b64decode(binary(data)))
Expand Down
30 changes: 16 additions & 14 deletions wheel/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Wheel command-line utility.
"""

from __future__ import print_function

import argparse
import hashlib
import json
Expand Down Expand Up @@ -52,14 +54,14 @@ def keygen(get_keyring=get_keyring):
sk = native(urlsafe_b64encode(keypair.sk))
kr = keyring.get_keyring()
kr.set_password("wheel", vk, sk)
sys.stdout.write("Created Ed25519 keypair with vk={0}\n".format(vk))
sys.stdout.write("in {0!r}\n".format(kr))
print("Created Ed25519 keypair with vk={}".format(vk))
print("in {!r}".format(kr))

sk2 = kr.get_password('wheel', vk)
if sk2 != sk:
raise WheelError("Keyring is broken. Could not retrieve secret key.")

sys.stdout.write("Trusting {0} to sign and verify all packages.\n".format(vk))
print("Trusting {} to sign and verify all packages.".format(vk))
wk.add_signer('+', vk)
wk.trust('+', vk)
wk.save()
Expand All @@ -76,7 +78,7 @@ def sign(wheelfile, replace=False, get_keyring=get_keyring):

name = wf.parsed_filename.group('name')
sign_with = wk.signers(name)[0]
sys.stdout.write("Signing {0} with {1}\n".format(name, sign_with[1]))
print("Signing {} with {}".format(name, sign_with[1]))

vk = sign_with[1]
kr = keyring.get_keyring()
Expand Down Expand Up @@ -126,9 +128,8 @@ def verify(wheelfile):
raise WheelError('The wheel is not signed (RECORD.jws not found at end of the archive).')

verified = signatures.verify(sig)
sys.stderr.write("Signatures are internally consistent.\n")
sys.stdout.write(json.dumps(verified, indent=2))
sys.stdout.write('\n')
print("Signatures are internally consistent.", file=sys.stderr)
print(json.dumps(verified, indent=2))


def unpack(wheelfile, dest='.'):
Expand All @@ -143,7 +144,7 @@ def unpack(wheelfile, dest='.'):
wf = WheelFile(wheelfile)
namever = wf.parsed_filename.group('namever')
destination = os.path.join(dest, namever)
sys.stderr.write("Unpacking to: %s\n" % (destination))
print("Unpacking to: %s" % (destination), file=sys.stderr)
wf.zipfile.extractall(destination)
wf.zipfile.close()

Expand Down Expand Up @@ -221,14 +222,14 @@ def install(requirements, requirements_file=None,

# We now have a list of wheels to install
if list_files:
sys.stdout.write("Installing:\n")
print("Installing:")

if dry_run:
return

for wf in to_install:
if list_files:
sys.stdout.write(" {0}\n".format(wf.filename))
print(" {}".format(wf.filename))
continue
wf.install(force=force)
wf.zipfile.close()
Expand Down Expand Up @@ -267,11 +268,11 @@ def convert(installers, dest_dir, verbose):
else:
conv = bdist_wininst2wheel
if verbose:
sys.stdout.write("{0}... ".format(installer))
print("{}... ".format(installer))
sys.stdout.flush()
conv(installer, dest_dir)
if verbose:
sys.stdout.write("OK\n")
print("OK")


def parser():
Expand Down Expand Up @@ -349,7 +350,7 @@ def convert_f(args):

def version_f(args):
from .. import __version__
sys.stdout.write("wheel %s\n" % __version__)
print("wheel %s" % __version__)
version_parser = s.add_parser('version', help='Print version and exit')
version_parser.set_defaults(func=version_f)

Expand All @@ -372,5 +373,6 @@ def main():
args.func(args)
return 0
except WheelError as e:
sys.stderr.write(e.message + "\n")
print(e, file=sys.stderr)

return 1
6 changes: 4 additions & 2 deletions wheel/wininst2wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ def main():
for pat in args.installers:
for installer in iglob(pat):
if args.verbose:
sys.stdout.write("{0}... ".format(installer))
print("{}... ".format(installer))
sys.stdout.flush()

bdist_wininst2wheel(installer, args.dest_dir)
if args.verbose:
sys.stdout.write("OK\n")
print("OK")


if __name__ == "__main__":
Expand Down

0 comments on commit d120bf9

Please sign in to comment.