diff options
author | Mike Taves <mwtoews@gmail.com> | 2020-03-05 00:00:16 +1300 |
---|---|---|
committer | Mike Taves <mwtoews@gmail.com> | 2020-03-09 13:44:26 +1300 |
commit | a7af9cc2578cdc128e662d163552fcb22da3c496 (patch) | |
tree | ed501fdc41b17325929f86e050914bbdcd0e885b /tools/c_coverage/c_coverage_report.py | |
parent | 6894bbc6d396b87464cbc21516d239d5f94f13b7 (diff) | |
download | numpy-a7af9cc2578cdc128e662d163552fcb22da3c496.tar.gz |
MAINT: replace optparse with argparse for 'doc' and 'tools' scripts
Diffstat (limited to 'tools/c_coverage/c_coverage_report.py')
-rwxr-xr-x | tools/c_coverage/c_coverage_report.py | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/tools/c_coverage/c_coverage_report.py b/tools/c_coverage/c_coverage_report.py index 28425054f..3b47523c5 100755 --- a/tools/c_coverage/c_coverage_report.py +++ b/tools/c_coverage/c_coverage_report.py @@ -4,7 +4,6 @@ A script to create C code-coverage reports based on the output of valgrind's callgrind tool. """ -import optparse import os import re import sys @@ -143,39 +142,43 @@ def collect_stats(files, fd, pattern): if __name__ == '__main__': - parser = optparse.OptionParser( - usage="[options] callgrind_file(s)") - parser.add_option( - '-d', '--directory', dest='directory', - default='coverage', - help='Destination directory for output [default: coverage]') - parser.add_option( - '-p', '--pattern', dest='pattern', - default='numpy', - help='Regex pattern to match against source file paths [default: numpy]') - parser.add_option( - '-f', '--format', dest='format', default=[], - action='append', type='choice', choices=('text', 'html'), - help="Output format(s) to generate, may be 'text' or 'html' [default: both]") - (options, args) = parser.parse_args() + import argparse + + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + 'callgrind_file', nargs='+', + help='One or more callgrind files') + parser.add_argument( + '-d', '--directory', default='coverage', + help='Destination directory for output (default: %(default)s)') + parser.add_argument( + '-p', '--pattern', default='numpy', + help='Regex pattern to match against source file paths ' + '(default: %(default)s)') + parser.add_argument( + '-f', '--format', action='append', default=[], + choices=['text', 'html'], + help="Output format(s) to generate. " + "If option not provided, both will be generated.") + args = parser.parse_args() files = SourceFiles() - for log_file in args: + for log_file in args.callgrind_file: log_fd = open(log_file, 'r') - collect_stats(files, log_fd, options.pattern) + collect_stats(files, log_fd, args.pattern) log_fd.close() - if not os.path.exists(options.directory): - os.makedirs(options.directory) + if not os.path.exists(args.directory): + os.makedirs(args.directory) - if options.format == []: + if args.format == []: formats = ['text', 'html'] else: - formats = options.format + formats = args.format if 'text' in formats: - files.write_text(options.directory) + files.write_text(args.directory) if 'html' in formats: if not has_pygments: print("Pygments 0.11 or later is required to generate HTML") sys.exit(1) - files.write_html(options.directory) + files.write_html(args.directory) |