-
Notifications
You must be signed in to change notification settings - Fork 34
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
Move argparse code into separate argparse modules #379
Conversation
@spbnick Am I on the right path? is there something I am missing? |
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.
Looks pretty good! Thank you, Shivam!
I only have a couple inline comments. Please proceed to the other modules after addressing them.
Please also observe commit guidelines in the PR I just posted.
Thank you 🙂
I am sorry the commits are all over the place. It will be a hard task but could you review it please @spbnick? I am also checking if I missed anything. |
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.
Nice work, @shivam-Purohit!
I have a few requests inline, and please don't hesitate to ask questions, if anything is not clear, or you need help ❤️
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.
Apart from the inline comments, please pay attention to the errors that the CI checks show, and the commit guidelines.
|
Yes, because it's closely related to |
@spbnick I tried all related changes in one commit. I am getting flake8 and pylinter errors. I will fix all that once all the changes are done. I am also checking for any code errors I made. I have one suggestion if we could add pre-commit check feature for the commits? That will ensure a proper code even before committing. |
Of course! I have pre-commit hook set up in my local repo. However, I'm not sure how to best distribute such a script. If you have an idea, please post a PR. You can take the commands to run from the GitHub test workflow, in the repo. |
I will surely try that cause this way was really tiring. I have a bunch of more ideas in my mind I will message in the slack. |
@spbnick
The action function uses the original argparse
while the other argumentparser uses the kcidb/argparse. We were using kcidb.misc.argumentparser earlier but now if we use something like kcidb.argparse.ArgumentParser it confuses it with the original argparse. And returns error no attribute found ArgumentParser in argparse. |
ERROR STATEMENT
|
Sorry, I wasn't able to reproduce your problem. Please push the exact code you have problem with to this PR and specify how to reproduce the issue. |
This is the ArgumentParser we defined in kcidb/db/argparse where constructor takes driver_types.
This might be the reason for the error? |
I doubt it. I have a hunch about what's going on, and I appreciate you trying to figure it out. However, if you want my help, please explain exactly how I can reproduce your problem, with the code in your PR. Thank you! |
@spbnick The way to reproduce will be then you will have to separate argparse in kcidb and kcidb/db. In db we are calling kcidb.argparse and in kcidb,argparse we are import that db.argparse.ArgumentParser. That may be the reason of circular import.
PS: unless I finish this I cannot work on other as it is not allowing me to change branches ( i have build folder that is not committed) |
Could you push the exact code you have the problem with to this (or another) PR, and give me the exact command to execute to reproduce this? If this is still a problem, let's have a video call tomorrow, and go over this. Reach out to me on Slack and tell me the possible times for a call, if you'd like to do that.
Even though VS code could be making switching branches difficult, you could always clone the repository in another directory and work on another branch there. |
@spbnick Can you review? |
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.
This is starting to take shape!
I left a bunch of comments/requests inline. Apart from them, please make sure your commits are in order, i.e. change-atomic and described appropriately, before review. This change seems to fit a single commit.
Thank you ❤️
I don't know why the rebase changes my code (move back in time) it should be keeping the code the same and only merge commit into one. I will redo the changes and add separate commitsfor driver_types |
EDIT: i solved it the db.QueryArgumentParser was missing some command line options. You can look at the pr I also did the Pattern.Stringdoc change. this is the error I was getting in the pytest. I could not trace the error. Could you help me with that @spbnick
|
@spbnick I did it through the second method you told me on call. Can you review it? |
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.
This is looking much better now! Thank you, Shivam!
Most of the inline comments are cosmetic, but there's one concerning a problem with logging-related symbols which would need another separate commit, and another regarding the completeness of driver_types
change.
kcidb/argparse.py
Outdated
k: v | ||
for k, v in sorted(LOGGING_LEVEL_MAP.items(), | ||
key=lambda i: i[1], reverse=True) | ||
} |
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.
These LOGGING_*
symbols shouldn't be here, and they definitely shouldn't me simply copied here. They should be defined in one place only, to avoid desynchronization. I see that both the kcidb.misc
and kcidb.argparse
modules use those. To avoid both this copying and a circular import, we need to move all symbols starting with LOGGING_
or logging_
to their own module called kcidb.logging
(in kcidb/logging.py
file).
After moving the symbols should naturally lose their LOGGING_
/logging_
prefixes, so e.g. kcidb.misc.LOGGING_LEVEL_MAP
becomes kcidb.logging.LEVEL_MAP
, and kcidb.misc.logging_setup
becomes kcidb.logging.setup
, and so on.
This change would better be done before extracting the argparse modules, in a separate commit.
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.
Please use the LOGGING_*
symbols from kcidb.misc
, instead of copying them here.
@spbnick I forgot to add common in the argparse description I will add a commit |
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, Shivam. I only have a bunch of minor requests. Otherwise this looks great.
Also, please "resolve conversation" for the requests that you implemented. Otherwise we'll be getting lost in them 🙈
Thanks!
kcidb/argparse.py
Outdated
k: v | ||
for k, v in sorted(LOGGING_LEVEL_MAP.items(), | ||
key=lambda i: i[1], reverse=True) | ||
} |
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.
Please use the LOGGING_*
symbols from kcidb.misc
, instead of copying them here.
@spbnick I have made the changes. |
Great!
Doesn't really matter, as they're unrelated. Pick the order that's easier and creates less churn. |
@spbnick how bout this? |
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, Shivam! We're almost there!
I found one more piece of unnecessarily-copied code, and three last stray changes, that need reverting.
To catch stray changes like that you could use a diff tool (e.g. diff
itself, vimdiff
, or something with a GUI). Get the file before your code move, and compare it to the file where you moved the code. E.g. like this:
vimdiff <(git show HEAD^^:kcidb/orm/__init__.py) kcidb/orm/argparse.py
|
||
|
||
# Check light assertions only, if True | ||
LIGHT_ASSERTS = not os.environ.get("KCIDB_HEAVY_ASSERTS", "") |
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.
This should also stay in kcidb.misc
, not get copied here. Import it from there and use like other modules do. E.g. kcidb.oo
.
Generally, you should avoid duplicating code and definitions.
""" | ||
parser.add_argument( | ||
"pattern_strings", | ||
nargs='*', |
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.
Please revert this change of double quotes to single quotes:
nargs='*', | |
nargs="*", |
It's unrelated to this commit.
default=[], | ||
metavar="PATTERN", | ||
help="Object-matching pattern. " | ||
"See pattern documentation with --pattern-help." |
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.
Same here, please revert this formatting change, and restore the comma on the end, in this commit:
"See pattern documentation with --pattern-help." | |
"See pattern documentation with --pattern-help.", |
Please avoid making unrelated changes, especially when moving code around. It complicates reviews.
parser.add_argument( | ||
"--pattern-help", | ||
action=PatternHelpAction, | ||
help="Print pattern string documentation and exit." |
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.
Similarly here:
help="Print pattern string documentation and exit." | |
help="Print pattern string documentation and exit.", |
Added module argparse to separate the functions and classes using the command-line argument parsing.
closes #367