-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Create an Argument
class and allow convertion of optdict into them
#5584
Create an Argument
class and allow convertion of optdict into them
#5584
Conversation
Pull Request Test Coverage Report for Build 2058346839
💛 - Coveralls |
If anybody could help me figure out why this fails on Windows that would be much appreciated! |
I think it's that subroutines can't be pickled on Windows. Any way we can avoid pickling |
I'll try and come up with something! |
c447d7b
to
b9b957a
Compare
I have fixed the issue with |
Argument
class and allow covertion of optdict into themArgument
class and allow convertion of optdict into them
b9b957a
to
3266477
Compare
Converting this to draft as I found issues with the current implementation. In retrospect I think it doesn't make sense to break this into smaller PRs, as we might run into problems after earlier parts have been merged. Therefore, I'll keep working on this until we can completely use |
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.
Do we really need new classes ? Or could we use argparse.Namespace
directly ? optparse is more complex so if we try to do a "small refactor" we'll keep the optparse complexity in our implementation even when using argparse.
One thing I had in mind for this refactor was separating parsing option / checking. Maybe creating NamedTuple or DataClasses and gives them to the checker pre-parsed instead of parsing the option inside each checker (in order to not have breaking change we could parse the option if the object is not given ?).
I think it is better to create new classes as it allows us to more easily work on this. If we start to inject into the pre-existing
I'm not sure what you mean here. I think the flow would be 1) register options on parser object, 2) parse options with parser object, 3) set namespace object as config namespace of linter object. |
This might be more difficult than I thought. I had a pretty good idea of how to not require The problem is that even |
I agree with 1) and 2) but I don't understand this part.
Couldn't we store the result of the parsing, i.e. an |
After the parsing is done (ideally in the
There is a difference between the Namespace and the storage of arguments. The namespace only stores the current value whereas the parser objects also stores stuff like default value and description. I think it's important that information is not lost after initial parsing of arguments is done, so we'll preferably need to save both the parser and the namespace. Currently I don't see a way to store the parser, as it seems everything within Run is pickled.. |
Ok I agree with that too.
Why ? Where could we use the default value and the description after the parsing is done ? |
We would need it to "reparse" for sub directories and for help messages. We would then need to recollect and reinstantiate all options for every subdirectory. That's not really good performance wise.., |
Can't we parse all the options for each directories first and store them ? (By the way the configuration by directory feature was removed from flake8 because it was bringing "90% of the bugs" we might want to reconsider that one) |
That might be possible, but that would definitely come later. However, I think I might have found a way to do it. We won't store information about the arguments this way, but I think we could design everything in such a way that that is not necessary. |
@Pierre-Sassoulas Would you consider using According to their README it has been download 200M+ times via Pypi and supports almost all python versions ( Some additional arguments for why I'm exploring fixing the |
Look like
Depends on what we want in PyLinter, right now it's doing almost everything. There's a problem with breaking change in downstream plugins to consider for sure, but let's put that aside for a minute If I understood what we're talking about and the current state of the code, PyLinter (each checker even) is parsing the options right now ? Parsing the options first before launching anything and especially the parallel run actually make more sense imo ? i.e. PyLinter could be the class that analyses a set of file given a set of parsed options and have less responsibilities. Alternatively we could include multiprocessing handling in PyLinter if we want PyLinter and not Run to be the entrypoint ? |
I'll start work on a PR implementing it for our
Since every
Note The problem is thus that at step 5 and step 7 we need to re-initialise an
We can't really do this as we need to parse the |
74b1499
to
d84b3dd
Compare
d84b3dd
to
a23c06b
Compare
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.
Look good already. I only skimmed because I'm not an expert in argparse custom parser and even less so in optparse so it's a hard review for me.
@Pierre-Sassoulas Do you want others to review this as well before merging? @jacobtylerwalls possibly? |
More reviews is always a good thing if we can afford the luxury :) |
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.
Terrific, thanks for moving this migration forward. A few questions, some for my own understanding.
Thanks for answering my questions. Is now a good time to edit the branch history? |
I guess so. I'll do a rebase. |
0e82e0b
to
ba01da1
Compare
@Pierre-Sassoulas Please rebase and merge if you're okay with this and the number of reviews 😄 |
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.
Great refactor @DanielNoord !
Type of Changes
Description
This is my first proposed step towards #5392.
We could build on this in a separate branch, as I intend not to make this interfere too much with any current code. That should keep merge conflicts low.
All of this is based on the documentation of
argparse
found here:https://docs.python.org/3/library/argparse.html
The idea of this PR is to showcase how we can transform our current
optdicts
into aArgument
class that we can then at some point start passing to theArgumentsManager
. I think that second part would be the next step, to make this in a MVP. After that we can start working on adding new checkers.I chose the logging module as it is a fairly easy module without only two options.
Don't hold back! Let me know what you think of this. All criticism is valuable!
Note: Ideally these commits wouldn't need to be squashed in a final merge. That makes cherry-picking later on much easier (see
2.0
branch inastroid
). So after final review I'll revisit the commit history.