summaryrefslogtreecommitdiff
path: root/scripts/internal/print_wheels.py
blob: 3c966173cbebab9c6b7d72f335c8b622df45329e (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
#!/usr/bin/env python3

# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Nicely print wheels print in dist/ directory."""

import collections
import glob
import os

from psutil._common import print_color
from psutil._common import bytes2human


def main():
    def is64bit(name):
        return name.endswith(('x86_64.whl', 'amd64.whl'))

    groups = collections.defaultdict(list)
    for path in glob.glob('dist/*.whl'):
        name = os.path.basename(path)
        plat = name.split('-')[-1]
        pyimpl = name.split('-')[3]
        ispypy = 'pypy' in pyimpl
        if 'linux' in plat:
            if ispypy:
                groups['pypy_on_linux'].append(name)
            else:
                groups['linux'].append(name)
        elif 'win' in plat:
            if ispypy:
                groups['pypy_on_windows'].append(name)
            else:
                groups['windows'].append(name)
        elif 'macosx' in plat:
            if ispypy:
                groups['pypy_on_macos'].append(name)
            else:
                groups['macos'].append(name)
        else:
            assert 0, name

    tot_files = 0
    tot_size = 0
    templ = "%-54s %7s %7s %7s"
    for platf, names in groups.items():
        ppn = "%s (total = %s)" % (platf.replace('_', ' '), len(names))
        s = templ % (ppn, "size", "arch", "pyver")
        print_color('\n' + s, color=None, bold=True)
        for name in sorted(names):
            tot_files += 1
            path = os.path.join('dist', name)
            size = os.path.getsize(path)
            tot_size += size
            arch = '64' if is64bit(name) else '32'
            pyver = 'pypy' if name.split('-')[3].startswith('pypy') else 'py'
            pyver += name.split('-')[2][2:]
            s = templ % (name, bytes2human(size), arch, pyver)
            if 'pypy' in pyver:
                print_color(s, color='violet')
            else:
                print_color(s, color='brown')

    print_color("\ntotals: files=%s, size=%s" % (
        tot_files, bytes2human(tot_size)), bold=1)


if __name__ == '__main__':
    main()