-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLGO] Refactored verbosity flag in mlgo-utils to common location #128541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlgo Author: Ali Raeisdanaei (aliraeisdanaei) Changesadd common lib file to setup arguments for parser #107898 This is my first pull request to LLVM, so I would appreciate your feedback :) Full diff: https://github.com/llvm/llvm-project/pull/128541.diff 3 Files Affected:
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
index 90cf51cad75ed..5b56e49e5abee 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/combine_training_corpus.py
@@ -27,6 +27,7 @@
import logging
from mlgo.corpus import combine_training_corpus_lib
+from mlgo.corpus import parser_setup_lib
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"],
- )
+ parser_setup_lib.add_verbosity_arguments(parser)
args = parser.parse_args()
main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
index 5edb429241d0c..2b54d47b03d5d 100644
--- a/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/extract_ir.py
@@ -28,7 +28,7 @@
import logging
from mlgo.corpus import extract_ir_lib
-
+from mlgo.corpus import parser_setup_lib
def parse_args_and_run():
parser = argparse.ArgumentParser(
@@ -111,15 +111,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"],
- )
+ parser_setup_lib.add_verbosity_arguments(parser)
args = parser.parse_args()
main(args)
diff --git a/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py b/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py
new file mode 100644
index 0000000000000..238bae3cd1e46
--- /dev/null
+++ b/llvm/utils/mlgo-utils/mlgo/corpus/parser_setup_lib.py
@@ -0,0 +1,21 @@
+# 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"],
+ )
\ No newline at end of file
|
Hello @boomanaiden154 and @mtrofin, I noticed the comments on PR 107818, and I made the refactoring that was needed. I hope this is an easy merge. Thank you. |
✅ With the latest revision this PR passed the Python code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can you rename this to flags
or tool_flags
(open to other suggestions):
- we only use the
_lib
naming pattern when we have a tool and want to unittest it, so most of the tool logic is moved to the_lib
, leaving the tool itself be basically themain
- an advantage of your patch is that it encapsulates the dependency on a specific arg parsing library (argparse), so renaming it away from what it encapsulates and towards what it provides its users makes sense, imho.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you I can name my file to parser_flags
if you like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would mean they are flags for the parser :) Would flags
work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ye sure flags
its is
default="INFO", | ||
nargs="?", | ||
choices=["DEBUG", "INFO", "WARNING", "ERROR"], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing empty line (makes, or will make, git diff unhappy later)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure. I added the new line at the end of my file. I didn't know it was a thing thank you for teaching me. Let me know if it still does not look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
once remaining comment is addressed and build bots pass - good to go!
for the failing checks - see https://llvm.org/docs/CodingStandards.html#python-version-and-source-code-formatting. (in your case I think the fix can be done manually very easily, but it's worth getting the auto-formatting tools set up for later, too) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit, otherwise LGTM. Formatting needs to be fixed.
Co-authored-by: Aiden Grossman <[email protected]>
@aliraeisdanaei Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Thank you @mtrofin and @boomanaiden154. I had a really fun time making my first merge. Ye were the best :)))))) |
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.