From 3290ead1b20633b5f77f114bd9b33ad85e28f7fc Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 11 Nov 2022 18:13:58 +0100 Subject: improve and rename print_wheels.py script Signed-off-by: Giampaolo Rodola --- MANIFEST.in | 2 +- Makefile | 10 +-- scripts/internal/print_dist.py | 130 +++++++++++++++++++++++++++++++++++++++ scripts/internal/print_wheels.py | 105 ------------------------------- 4 files changed, 136 insertions(+), 111 deletions(-) create mode 100755 scripts/internal/print_dist.py delete mode 100755 scripts/internal/print_wheels.py diff --git a/MANIFEST.in b/MANIFEST.in index e19c7e2d..13ed1c17 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -141,10 +141,10 @@ include scripts/internal/git_pre_commit.py include scripts/internal/print_access_denied.py include scripts/internal/print_announce.py include scripts/internal/print_api_speed.py +include scripts/internal/print_dist.py include scripts/internal/print_downloads.py include scripts/internal/print_hashes.py include scripts/internal/print_timeline.py -include scripts/internal/print_wheels.py include scripts/internal/purge_installation.py include scripts/internal/winmake.py include scripts/iotop.py diff --git a/Makefile b/Makefile index 930325dd..5088cb72 100644 --- a/Makefile +++ b/Makefile @@ -234,14 +234,14 @@ install-git-hooks: ## Install GIT pre-commit hook. download-wheels-github: ## Download latest wheels hosted on github. $(PYTHON) scripts/internal/download_wheels_github.py --tokenfile=~/.github.token - ${MAKE} print-wheels + ${MAKE} print-dist download-wheels-appveyor: ## Download latest wheels hosted on appveyor. $(PYTHON) scripts/internal/download_wheels_appveyor.py - ${MAKE} print-wheels + ${MAKE} print-dist -print-wheels: ## Print downloaded wheels - $(PYTHON) scripts/internal/print_wheels.py +print-dist: ## Print downloaded wheels / tar.gs + $(PYTHON) scripts/internal/print_dist.py # =================================================================== # Distribution @@ -275,7 +275,7 @@ pre-release: ## Check if we're ready to produce a new release. ${MAKE} download-wheels-github ${MAKE} download-wheels-appveyor ${MAKE} print-hashes - ${MAKE} print-wheels + ${MAKE} print-dist $(PYTHON) -m twine check --strict dist/* $(PYTHON) -c \ "from psutil import __version__ as ver; \ diff --git a/scripts/internal/print_dist.py b/scripts/internal/print_dist.py new file mode 100755 index 00000000..1e8e5562 --- /dev/null +++ b/scripts/internal/print_dist.py @@ -0,0 +1,130 @@ +#!/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. + +"""List and pretty print tarball & wheel files in the dist/ directory.""" + +import argparse +import collections +import os + +from psutil._common import bytes2human +from psutil._common import print_color + + +class Wheel: + + def __init__(self, path): + self._path = path + self._name = os.path.basename(path) + + def __repr__(self): + return "<%s(name=%s, plat=%s, arch=%s, pyver=%s)>" % ( + self.__class__.__name__, self.name, self.platform(), self.arch(), + self.pyver()) + + __str__ = __repr__ + + @property + def name(self): + return self._name + + def platform(self): + plat = self.name.split('-')[-1] + pyimpl = self.name.split('-')[3] + ispypy = 'pypy' in pyimpl + if 'linux' in plat: + if ispypy: + return 'pypy_on_linux' + else: + return 'linux' + elif 'win' in plat: + if ispypy: + return 'pypy_on_windows' + else: + return 'windows' + elif 'macosx' in plat: + if ispypy: + return 'pypy_on_macos' + else: + return 'macos' + else: + raise ValueError("unknown platform %r" % self.name) + + def arch(self): + if self.name.endswith(('x86_64.whl', 'amd64.whl')): + return '64' + if self.name.endswith(("i686.whl", "win32.whl")): + return '32' + if self.name.endswith("arm64.whl"): + return 'arm64' + return '?' + + def pyver(self): + pyver = 'pypy' if self.name.split('-')[3].startswith('pypy') else 'py' + pyver += self.name.split('-')[2][2:] + return pyver + + def size(self): + return os.path.getsize(self._path) + + +class Tarball(Wheel): + + def platform(self): + return "source" + + def arch(self): + return "-" + + def pyver(self): + return "-" + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('dir', nargs="?", default="dist", + help='directory containing tar.gz or wheel files') + args = parser.parse_args() + + if not os.path.isdir(args.dir): + raise NotADirectoryError(args.dir) + groups = collections.defaultdict(list) + + ls = sorted(os.listdir(args.dir), + key=lambda x: x.endswith("tar.gz")) + for name in ls: + path = os.path.join(args.dir, name) + if path.endswith(".whl"): + pkg = Wheel(path) + elif path.endswith(".tar.gz"): + pkg = Tarball(path) + else: + raise ValueError("invalid package %r", path) + groups[pkg.platform()].append(pkg) + + tot_files = 0 + tot_size = 0 + templ = "%-100s %7s %7s %7s" + for platf, pkgs in groups.items(): + ppn = "%s (%s)" % (platf, len(pkgs)) + s = templ % (ppn, "size", "arch", "pyver") + print_color('\n' + s, color=None, bold=True) + for pkg in sorted(pkgs, key=lambda x: x.name): + tot_files += 1 + tot_size += pkg.size() + s = templ % (" " + pkg.name, bytes2human(pkg.size()), pkg.arch(), + pkg.pyver()) + if 'pypy' in pkg.pyver(): + print_color(s, color='violet') + else: + print_color(s, color='brown') + + print_color("\n\ntotals: files=%s, size=%s" % ( + tot_files, bytes2human(tot_size)), bold=True) + + +if __name__ == '__main__': + main() diff --git a/scripts/internal/print_wheels.py b/scripts/internal/print_wheels.py deleted file mode 100755 index 6b19909b..00000000 --- a/scripts/internal/print_wheels.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/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 argparse -import collections -import glob -import os - -from psutil._common import bytes2human -from psutil._common import print_color - - -class Wheel: - - def __init__(self, path): - self._path = path - self._name = os.path.basename(path) - - def __repr__(self): - return "" % ( - self.name, self.platform(), self.arch(), self.pyver()) - - __str__ = __repr__ - - @property - def name(self): - return self._name - - def platform(self): - plat = self.name.split('-')[-1] - pyimpl = self.name.split('-')[3] - ispypy = 'pypy' in pyimpl - if 'linux' in plat: - if ispypy: - return 'pypy_on_linux' - else: - return 'linux' - elif 'win' in plat: - if ispypy: - return 'pypy_on_windows' - else: - return 'windows' - elif 'macosx' in plat: - if ispypy: - return 'pypy_on_macos' - else: - return 'macos' - else: - raise ValueError("unknown platform %r" % self.name) - - def arch(self): - if self.name.endswith(('x86_64.whl', 'amd64.whl')): - return '64' - return '32' - - def pyver(self): - pyver = 'pypy' if self.name.split('-')[3].startswith('pypy') else 'py' - pyver += self.name.split('-')[2][2:] - return pyver - - def size(self): - return os.path.getsize(self._path) - - -def main(): - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('dir', nargs="?", default="dist", - help='directory containing tar.gz or wheel files') - args = parser.parse_args() - - if not os.path.isdir(args.dir): - raise NotADirectoryError(args.dir) - groups = collections.defaultdict(list) - for path in glob.glob('%s/*.whl' % args.dir): - wheel = Wheel(path) - groups[wheel.platform()].append(wheel) - - tot_files = 0 - tot_size = 0 - templ = "%-100s %7s %7s %7s" - for platf, wheels in groups.items(): - ppn = "%s (total = %s)" % (platf, len(wheels)) - s = templ % (ppn, "size", "arch", "pyver") - print_color('\n' + s, color=None, bold=True) - for wheel in sorted(wheels, key=lambda x: x.name): - tot_files += 1 - tot_size += wheel.size() - s = templ % (wheel.name, bytes2human(wheel.size()), wheel.arch(), - wheel.pyver()) - if 'pypy' in wheel.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=True) - - -if __name__ == '__main__': - main() -- cgit v1.2.1