You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

4 years ago
  1. """
  2. Wheel command-line utility.
  3. """
  4. from __future__ import print_function
  5. import argparse
  6. import os
  7. import sys
  8. def require_pkgresources(name):
  9. try:
  10. import pkg_resources # noqa: F401
  11. except ImportError:
  12. raise RuntimeError("'{0}' needs pkg_resources (part of setuptools).".format(name))
  13. class WheelError(Exception):
  14. pass
  15. def unpack_f(args):
  16. from .unpack import unpack
  17. unpack(args.wheelfile, args.dest)
  18. def pack_f(args):
  19. from .pack import pack
  20. pack(args.directory, args.dest_dir)
  21. def convert_f(args):
  22. from .convert import convert
  23. convert(args.files, args.dest_dir, args.verbose)
  24. def version_f(args):
  25. from .. import __version__
  26. print("wheel %s" % __version__)
  27. def parser():
  28. p = argparse.ArgumentParser()
  29. s = p.add_subparsers(help="commands")
  30. unpack_parser = s.add_parser('unpack', help='Unpack wheel')
  31. unpack_parser.add_argument('--dest', '-d', help='Destination directory',
  32. default='.')
  33. unpack_parser.add_argument('wheelfile', help='Wheel file')
  34. unpack_parser.set_defaults(func=unpack_f)
  35. repack_parser = s.add_parser('pack', help='Repack wheel')
  36. repack_parser.add_argument('directory', help='Root directory of the unpacked wheel')
  37. repack_parser.add_argument('--dest-dir', '-d', default=os.path.curdir,
  38. help="Directory to store the wheel (default %(default)s)")
  39. repack_parser.set_defaults(func=pack_f)
  40. convert_parser = s.add_parser('convert', help='Convert egg or wininst to wheel')
  41. convert_parser.add_argument('files', nargs='*', help='Files to convert')
  42. convert_parser.add_argument('--dest-dir', '-d', default=os.path.curdir,
  43. help="Directory to store wheels (default %(default)s)")
  44. convert_parser.add_argument('--verbose', '-v', action='store_true')
  45. convert_parser.set_defaults(func=convert_f)
  46. version_parser = s.add_parser('version', help='Print version and exit')
  47. version_parser.set_defaults(func=version_f)
  48. help_parser = s.add_parser('help', help='Show this help')
  49. help_parser.set_defaults(func=lambda args: p.print_help())
  50. return p
  51. def main():
  52. p = parser()
  53. args = p.parse_args()
  54. if not hasattr(args, 'func'):
  55. p.print_help()
  56. else:
  57. try:
  58. args.func(args)
  59. return 0
  60. except WheelError as e:
  61. print(e, file=sys.stderr)
  62. return 1