[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 <agrossman154@yahoo.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import argparse
|
||||
import logging
|
||||
|
||||
from mlgo.corpus import combine_training_corpus_lib
|
||||
from mlgo.corpus import flags
|
||||
|
||||
|
||||
def parse_args_and_run():
|
||||
@@ -36,15 +37,7 @@ def parse_args_and_run():
|
||||
parser.add_argument(
|
||||
"--root_dir", type=str, help="The root dir of module paths to combine."
|
||||
)
|
||||
# TODO(#107898): Refactor this into a common location.
|
||||
parser.add_argument(
|
||||
"--verbosity",
|
||||
type=str,
|
||||
help="The verbosity level to use for logging",
|
||||
default="INFO",
|
||||
nargs="?",
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
|
||||
)
|
||||
flags.add_verbosity_arguments(parser)
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import json
|
||||
import logging
|
||||
|
||||
from mlgo.corpus import extract_ir_lib
|
||||
from mlgo.corpus import flags
|
||||
|
||||
|
||||
def parse_args_and_run():
|
||||
@@ -111,15 +112,7 @@ def parse_args_and_run():
|
||||
default=".llvmbc",
|
||||
nargs="?",
|
||||
)
|
||||
# TODO(#107898): Refactor this into a common location.
|
||||
parser.add_argument(
|
||||
"--verbosity",
|
||||
type=str,
|
||||
help="The verbosity level to use for logging",
|
||||
default="INFO",
|
||||
nargs="?",
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
|
||||
)
|
||||
flags.add_verbosity_arguments(parser)
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
|
||||
|
||||
22
llvm/utils/mlgo-utils/mlgo/corpus/flags.py
Normal file
22
llvm/utils/mlgo-utils/mlgo/corpus/flags.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
# See https://llvm.org/LICENSE.txt for license information.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
"""Library functions for setting up common parser arguments"""
|
||||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
|
||||
def add_verbosity_arguments(parser: ArgumentParser) -> None:
|
||||
"""Adds the arguments for verbosity to the ArgumentParser
|
||||
|
||||
Arguments:
|
||||
parser: The argument parser being modified with verbosity arguments.
|
||||
"""
|
||||
parser.add_argument(
|
||||
"--verbosity",
|
||||
type=str,
|
||||
help="The verbosity level to use for logging",
|
||||
default="INFO",
|
||||
nargs="?",
|
||||
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
|
||||
)
|
||||
Reference in New Issue
Block a user