|
| 1 | +#!/usr/bin/env |
| 2 | +""" Remove test images from matplotlib wheel(s) |
| 3 | +""" |
| 4 | +from __future__ import print_function |
| 5 | + |
| 6 | +from os.path import join as pjoin, basename, abspath, isdir |
| 7 | +from shutil import rmtree |
| 8 | +from argparse import ArgumentParser |
| 9 | + |
| 10 | +from subprocess import check_call, check_output |
| 11 | + |
| 12 | +IMAGE_PATH = pjoin('matplotlib', 'tests', 'baseline_images') |
| 13 | + |
| 14 | +from delocate.wheeltools import InWheelCtx |
| 15 | + |
| 16 | + |
| 17 | +def get_needed(lib_fname): |
| 18 | + res = check_output(['patchelf', '--print-needed'] + [lib_fname]) |
| 19 | + return [name.strip() for name in res.decode('latin1').splitlines()] |
| 20 | + |
| 21 | + |
| 22 | +def rm_needed(lib_name, lib_fname): |
| 23 | + check_call(['patchelf', '--remove-needed', lib_name, lib_fname]) |
| 24 | + |
| 25 | + |
| 26 | +def rm_images(whl_fname, out_fname, verbose=False): |
| 27 | + whl_fname = abspath(whl_fname) |
| 28 | + out_fname = abspath(out_fname) |
| 29 | + with InWheelCtx(whl_fname) as ctx: |
| 30 | + if not isdir(IMAGE_PATH): |
| 31 | + if verbose: |
| 32 | + print('No {} in {}'.format(IMAGE_PATH, whl_fname)) |
| 33 | + return |
| 34 | + rmtree(IMAGE_PATH) |
| 35 | + # Write the wheel |
| 36 | + ctx.out_wheel = out_fname |
| 37 | + |
| 38 | + |
| 39 | +def get_parser(): |
| 40 | + parser = ArgumentParser() |
| 41 | + parser.add_argument('whl_fnames', nargs='+') |
| 42 | + parser.add_argument('--verbose', action='store_true') |
| 43 | + parser.add_argument('--out-path') |
| 44 | + return parser |
| 45 | + |
| 46 | + |
| 47 | +def main(): |
| 48 | + args = get_parser().parse_args() |
| 49 | + for whl_fname in args.whl_fnames: |
| 50 | + out_fname = (pjoin(args.out_path, basename(whl_fname)) if args.out_path |
| 51 | + else whl_fname) |
| 52 | + if args.verbose: |
| 53 | + print('Removing test images from {}'.format(whl_fname)) |
| 54 | + rm_images(whl_fname, out_fname, verbose=args.verbose) |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == "__main__": |
| 58 | + main() |
0 commit comments