Skip to content

Commit

Permalink
MAINT: replace optparse usage with argparse (scipy#19030)
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
dschmitz89 committed Aug 10, 2023
1 parent 7e7d867 commit d98afea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 40 deletions.
15 changes: 8 additions & 7 deletions scipy/sparse/_generate_sparsetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
See sparsetools.cxx for more details.
"""
import optparse
import argparse
import os
from stat import ST_MTIME

Expand Down Expand Up @@ -352,12 +352,13 @@ def get_arglist(I_type, T_type):


def main():
p = optparse.OptionParser(usage=(__doc__ or '').strip())
p.add_option("--no-force", action="store_false",
dest="force", default=True)
p.add_option("-o", "--outdir", type=str,
help="Relative path to the output directory")
options, args = p.parse_args()
p = argparse.ArgumentParser(usage=(__doc__ or '').strip())

p.add_argument("--no-force", action="store_false",
dest="force", default=True)
p.add_argument("-o", "--outdir", type=str,
help="Relative path to the output directory")
options = p.parse_args()

names = []

Expand Down
20 changes: 9 additions & 11 deletions tools/authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""
# Author: Pauli Virtanen <pav@iki.fi>. This script is in the public domain.

import optparse
import argparse
import re
import sys
import os
Expand All @@ -26,18 +26,16 @@


def main():
p = optparse.OptionParser(__doc__.strip())
p.add_option("-d", "--debug", action="store_true",
help="print debug output")
p.add_option("-n", "--new", action="store_true",
help="print debug output")
options, args = p.parse_args()

if len(args) != 1:
p.error("invalid number of arguments")
p = argparse.ArgumentParser(__doc__.strip())
p.add_argument("range", help=argparse.SUPPRESS)
p.add_argument("-d", "--debug", action="store_true",
help="print debug output")
p.add_argument("-n", "--new", action="store_true",
help="print debug output")
options = p.parse_args()

try:
rev1, rev2 = args[0].split('..')
rev1, rev2 = options.range.split('..')
except ValueError:
p.error("argument is not a revision range")

Expand Down
40 changes: 18 additions & 22 deletions tools/ninjatracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import json
import os
import optparse
import argparse
import re
import sys

Expand Down Expand Up @@ -158,29 +158,25 @@ def log_to_dicts(log, pid, options):

def main(argv):
usage = __doc__
parser = optparse.OptionParser(usage)
parser.add_option('-a', '--showall', action='store_true', dest='showall',
default=False,
help='report on last build step for all outputs. Default '
'is to report just on the last (possibly incremental) '
'build')
parser.add_option('-g', '--granularity', type='int', default=50000,
dest='granularity',
help='minimum length time-trace event to embed in '
'microseconds. Default: %default')
parser.add_option('-e', '--embed-time-trace', action='store_true',
default=False, dest='embed_time_trace',
help='embed clang -ftime-trace json file found adjacent '
'to a target file')
(options, args) = parser.parse_args()

if len(args) == 0:
print('Must specify at least one .ninja_log file')
parser.print_help()
return 1
parser = argparse.ArgumentParser(usage)
parser.add_argument("logfiles", nargs="*", help=argparse.SUPPRESS)
parser.add_argument('-a', '--showall', action='store_true',
dest='showall', default=False,
help='report on last build step for all outputs. '
'Default is to report just on the last '
'(possibly incremental) build')
parser.add_argument('-g', '--granularity', type=int, default=50000,
dest='granularity',
help='minimum length time-trace event to embed in '
'microseconds. Default: 50000')
parser.add_argument('-e', '--embed-time-trace', action='store_true',
default=False, dest='embed_time_trace',
help='embed clang -ftime-trace json file found '
'adjacent to a target file')
options = parser.parse_args()

entries = []
for pid, log_file in enumerate(args):
for pid, log_file in enumerate(options.logfiles):
with open(log_file, 'r') as log:
entries += list(log_to_dicts(log, pid, vars(options)))
json.dump(entries, sys.stdout)
Expand Down

0 comments on commit d98afea

Please sign in to comment.