summaryrefslogtreecommitdiff
path: root/.emacs.d.back/.python-environments/default/lib/python3.7/site-packages/wheel/cli/__init__.py
blob: 95740bfb650514f6b17005b4bc8220858ebdfdf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Wheel command-line utility.
"""

from __future__ import print_function

import argparse
import os
import sys


def require_pkgresources(name):
    try:
        import pkg_resources  # noqa: F401
    except ImportError:
        raise RuntimeError("'{0}' needs pkg_resources (part of setuptools).".format(name))


class WheelError(Exception):
    pass


def unpack_f(args):
    from .unpack import unpack
    unpack(args.wheelfile, args.dest)


def pack_f(args):
    from .pack import pack
    pack(args.directory, args.dest_dir, args.build_number)


def convert_f(args):
    from .convert import convert
    convert(args.files, args.dest_dir, args.verbose)


def version_f(args):
    from .. import __version__
    print("wheel %s" % __version__)


def parser():
    p = argparse.ArgumentParser()
    s = p.add_subparsers(help="commands")

    unpack_parser = s.add_parser('unpack', help='Unpack wheel')
    unpack_parser.add_argument('--dest', '-d', help='Destination directory',
                               default='.')
    unpack_parser.add_argument('wheelfile', help='Wheel file')
    unpack_parser.set_defaults(func=unpack_f)

    repack_parser = s.add_parser('pack', help='Repack wheel')
    repack_parser.add_argument('directory', help='Root directory of the unpacked wheel')
    repack_parser.add_argument('--dest-dir', '-d', default=os.path.curdir,
                               help="Directory to store the wheel (default %(default)s)")
    repack_parser.add_argument('--build-number', help="Build tag to use in the wheel name")
    repack_parser.set_defaults(func=pack_f)

    convert_parser = s.add_parser('convert', help='Convert egg or wininst to wheel')
    convert_parser.add_argument('files', nargs='*', help='Files to convert')
    convert_parser.add_argument('--dest-dir', '-d', default=os.path.curdir,
                                help="Directory to store wheels (default %(default)s)")
    convert_parser.add_argument('--verbose', '-v', action='store_true')
    convert_parser.set_defaults(func=convert_f)

    version_parser = s.add_parser('version', help='Print version and exit')
    version_parser.set_defaults(func=version_f)

    help_parser = s.add_parser('help', help='Show this help')
    help_parser.set_defaults(func=lambda args: p.print_help())

    return p


def main():
    p = parser()
    args = p.parse_args()
    if not hasattr(args, 'func'):
        p.print_help()
    else:
        try:
            args.func(args)
            return 0
        except WheelError as e:
            print(e, file=sys.stderr)

    return 1