Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Switch from Python optparse to argparse #1277

Open
Labels
cat.BackendIssue relates to things that the user won't seeinfo.SmallIssue has a quick fixtype.CodeQualityIssue relates to code quality
Milestone
@AesaraB

Description

@AesaraB

Point of concern

PEP 389 states the gradual depreciation of Python'soptparse argument parsing library.

grepping the codebase, MyPaint uses optparse in three files:

mypaint/gui/main.py

Lines 244 to 290 in00483b9

defparsed_cmdline_arguments(default_confpath,debug=False):
"""Parse command line arguments and return result
:return: (options, positional arguments)
"""
parser=OptionParser("usage: %prog [options] [FILE]")
parser.add_option(
"-c",
"--config",
metavar="DIR",
default=default_confpath,
help="use old-style merged config directory DIR, e.g. ~/.mypaint",
)
parser.add_option(
"-l",
"--logfile",
metavar="FILE",
default=None,
help="log console messages to FILE (rel. to config location)",
)
parser.add_option(
"-t",
"--trace",
action="store_true",
help="print all executed Python statements",
)
parser.add_option(
"-f",
"--fullscreen",
action="store_true",
help="start in fullscreen mode",
)
parser.add_option(
"-V",
"--version",
action="store_true",
help="print version information and exit",
)
ifdebug:
parser.add_option(
"-R",
"--run-and-quit",
action="store_true",
help="start the program and shut it down after 1 second",
)
returnparser.parse_args(sys.argv_unicode[1:])

fromoptparseimportOptionParser
parser=OptionParser("usage: %prog [options] [test1 test2 test3 ...]")
parser.add_option(
"-a","--all",action="store_true",default=False,help="run all tests"
)
parser.add_option(
"-l",
"--list",
action="store_true",
default=False,
help="list all available tests",
)
parser.add_option(
"-d",
"--debug",
action="store_true",
default=False,
help="print leak analysis (slow)",
)
parser.add_option(
"-e",
"--exit",
action="store_true",
default=False,
help="exit at first error",
)
parser.add_option(
"-r",
"--required",
type="int",
default=15,
help="iterations required to draw a conclusion (default: 15)",
)
parser.add_option(
"-m",
"--max-iterations",
type="int",
default=100,
help="maximum number of iterations (default: 100)",
)
options,tests=parser.parse_args()

fromoptparseimportOptionParser
parser=OptionParser("usage: %prog [options] [test1 test2 test3 ...]")
parser.add_option(
"-a","--all",action="store_true",default=False,help="run all tests"
)
parser.add_option(
"-l",
"--list",
action="store_true",
default=False,
help="list all available tests",
)
parser.add_option(
"-c",
"--count",
metavar="N",
type="int",
default=3,
help="number of repetitions (default: 3)",
)
parser.add_option(
"-p",
"--profile",
metavar="PREFIX",
help="dump cProfile info to PREFIX_TESTNAME_N.pstats",
)
parser.add_option(
"-s",
"--show-profile",
action="store_true",
default=False,
help="run cProfile, gprof2dot.py and show last result",
)
options,tests=parser.parse_args()

Suggested improvements

Replace optparse with argparse

Metadata

Metadata

Assignees

No one assigned

    Labels

    cat.BackendIssue relates to things that the user won't seeinfo.SmallIssue has a quick fixtype.CodeQualityIssue relates to code quality

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp