Skip to content

Commit 651fbfe

Browse files
add common lib file to setup arguments for parser #107898
1 parent a0be17d commit 651fbfe

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import logging
2828

2929
from mlgo.corpus import combine_training_corpus_lib
30+
from mlgo.corpus import parser_setup_lib
3031

3132

3233
def parse_args_and_run():
@@ -36,15 +37,7 @@ def parse_args_and_run():
3637
parser.add_argument(
3738
"--root_dir", type=str, help="The root dir of module paths to combine."
3839
)
39-
# TODO(#107898): Refactor this into a common location.
40-
parser.add_argument(
41-
"--verbosity",
42-
type=str,
43-
help="The verbosity level to use for logging",
44-
default="INFO",
45-
nargs="?",
46-
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
47-
)
40+
parser_setup_lib.add_verbosity_arguments(parser)
4841
args = parser.parse_args()
4942
main(args)
5043

llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import logging
2929

3030
from mlgo.corpus import extract_ir_lib
31-
31+
from mlgo.corpus import parser_setup_lib
3232

3333
def parse_args_and_run():
3434
parser = argparse.ArgumentParser(
@@ -111,15 +111,7 @@ def parse_args_and_run():
111111
default=".llvmbc",
112112
nargs="?",
113113
)
114-
# TODO(#107898): Refactor this into a common location.
115-
parser.add_argument(
116-
"--verbosity",
117-
type=str,
118-
help="The verbosity level to use for logging",
119-
default="INFO",
120-
nargs="?",
121-
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
122-
)
114+
parser_setup_lib.add_verbosity_arguments(parser)
123115
args = parser.parse_args()
124116
main(args)
125117

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
"""Library functions for setting up common parser arguments"""
5+
6+
from argparse import ArgumentParser
7+
8+
def add_verbosity_arguments(parser: ArgumentParser) -> None:
9+
"""Adds the arguments for verbosity to the ArgumentParser
10+
11+
Arguments:
12+
parser -- the argument parser being modified with verbosity arguments
13+
"""
14+
parser.add_argument(
15+
"--verbosity",
16+
type=str,
17+
help="The verbosity level to use for logging",
18+
default="INFO",
19+
nargs="?",
20+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
21+
)

0 commit comments

Comments
 (0)