From: Leo Yan <leo.yan@arm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Leo Yan <leo.yan@arm.com>
Subject: [PATCH] perf test: Replace optparse with argparse in attr.py
Date: Thu, 01 Oct 2026 16:52:20 +0100 [thread overview]
Message-ID: <20261001-perf_replace_optparse_with_argparse-v1-1-268b604f8e55@arm.com> (raw)
Depending on the Python and pylint versions, pylint can report that
optparse is deprecated and fail the lint check. Use argparse to avoid
this potential warning.
Preserve the existing options and defaults, and let argparse handle
help and unexpected positional arguments.
Tested with:
# ./perf test -v 'Perf attribute expectations test'
78: Perf attribute expectations test : Ok
Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/tests/shell/lib/attr.py | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/tools/perf/tests/shell/lib/attr.py b/tools/perf/tests/shell/lib/attr.py
index 7f3d5b64b00dd7de45baff4f7d9baff89e003147..68f06df9565a081174c788b964a5b051fdedf626 100644
--- a/tools/perf/tests/shell/lib/attr.py
+++ b/tools/perf/tests/shell/lib/attr.py
@@ -4,7 +4,7 @@ import configparser
import os
import sys
import glob
-import optparse
+import argparse
import platform
import tempfile
import logging
@@ -426,29 +426,20 @@ def setup_log(verbose):
ch.setFormatter(formatter)
log.addHandler(ch)
-USAGE = '''%s [OPTIONS]
- -d dir # tests dir
- -p path # perf binary
- -t test # single test
- -v # verbose level
-''' % sys.argv[0]
-
def main():
- parser = optparse.OptionParser(usage=USAGE)
-
- parser.add_option("-t", "--test",
- action="store", type="string", dest="test")
- parser.add_option("-d", "--test-dir",
- action="store", type="string", dest="test_dir")
- parser.add_option("-p", "--perf",
- action="store", type="string", dest="perf")
- parser.add_option("-v", "--verbose",
- default=0, action="count", dest="verbose")
-
- options, args = parser.parse_args()
- if args:
- parser.error('FAILED wrong arguments %s' % ' '.join(args))
- return -1
+ parser = argparse.ArgumentParser()
+
+ parser.add_argument("-t", "--test",
+ action="store", dest="test", help="single test")
+ parser.add_argument("-d", "--test-dir",
+ action="store", dest="test_dir", help="tests dir")
+ parser.add_argument("-p", "--perf",
+ action="store", dest="perf", help="perf binary")
+ parser.add_argument("-v", "--verbose",
+ default=0, action="count", dest="verbose",
+ help="verbose level")
+
+ options = parser.parse_args()
setup_log(options.verbose)
---
base-commit: 705da5b15ab89ba97b11eedbe507c2fd83d31cb9
change-id: 20261001-perf_replace_optparse_with_argparse-e7f51849a08c
Best regards,
--
Leo Yan <leo.yan@arm.com>
next reply other threads:[~2026-10-01 15:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 15:52 Leo Yan [this message]
2026-10-01 16:20 ` Ian Rogers
2026-10-02 7:52 ` Leo Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261001-perf_replace_optparse_with_argparse-v1-1-268b604f8e55@arm.com \
--to=leo.yan@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®