Skip to content

Commit fc09550

Browse files
[MLGO] Refactored verbosity flag in mlgo-utils to common location (#128541)
add common lib file to setup arguments for parser #107898 This is my first pull request to LLVM, so I would appreciate your feedback :) Fixes #107898. --------- Co-authored-by: Aiden Grossman <[email protected]>
1 parent 1824bb4 commit fc09550

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
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 flags
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+
flags.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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import logging
2929

3030
from mlgo.corpus import extract_ir_lib
31+
from mlgo.corpus import flags
3132

3233

3334
def parse_args_and_run():
@@ -111,15 +112,7 @@ def parse_args_and_run():
111112
default=".llvmbc",
112113
nargs="?",
113114
)
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-
)
115+
flags.add_verbosity_arguments(parser)
123116
args = parser.parse_args()
124117
main(args)
125118

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
9+
def add_verbosity_arguments(parser: ArgumentParser) -> None:
10+
"""Adds the arguments for verbosity to the ArgumentParser
11+
12+
Arguments:
13+
parser: The argument parser being modified with verbosity arguments.
14+
"""
15+
parser.add_argument(
16+
"--verbosity",
17+
type=str,
18+
help="The verbosity level to use for logging",
19+
default="INFO",
20+
nargs="?",
21+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
22+
)

0 commit comments

Comments
 (0)