-
Notifications
You must be signed in to change notification settings - Fork 45
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
Improve argparser #87
Conversation
Codecov Report
@@ Coverage Diff @@
## master #87 +/- ##
==========================================
+ Coverage 98.87% 98.94% +0.06%
==========================================
Files 1 1
Lines 357 380 +23
==========================================
+ Hits 353 376 +23
Misses 4 4
Continue to review full report at Codecov.
|
@cdce8p Wow! Thank you. It's so easy to read! I didn't know that you can do this hack with
I like to commit to smaller units. That helps me in my review as well. Thanks. I don't always squash merge approved PRs, but there is nothing wrong with squash merging this PR. |
formatter_class=CustomHelpFormatter) | ||
|
||
common_options = parser.add_argument_group('Common options') | ||
format_options = parser.add_argument_group('Format options') |
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.
The argument_group title "Format options" looks a bit strange. Because option --format
is in "Common options".
But I don't have a good alternative either 😅
By the way, "Verify options" is a great naming 👍
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.
I agree, it's a bit strange. I can change the group names if you like, although I think it's good enough. The goal with Format options
was to group all additional format arguments that one might not need that often.
I just remembered that I missed implementing a few small checks. I'll add them later today. |
6b6d09e
to
53ebae0
Compare
Just pushed all remaining changes. In addition to extending args verification, I've also added some type hints for After this PR is finished, I would like to propose moving from a single source file to a package structure. |
[tool:isort] | ||
# https://github.com/timothycrosley/isort | ||
multi_line_output = 4 | ||
line_length = 72 | ||
known_first_party = | ||
piplicenses |
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.
@cdce8p Thank you for your great contribution. This is a very useful tool.
I have something to ask for future reference. Why do you want to overwrite the line_length
setting from 79 (as default) to 72? I'd like to hear if there is any reason to recommend 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.
To be honest, I don't really know. It's something I have picked up somewhere over time and it seems to work great. I guess an advantage would be that with only 72
characters not to many from
imports are on one line, see test_piplicenses.py
for example.
Regarding the default 79
: Personally I would recommend to change it. I tend to use 119
for my projects. That doesn't mean that every line should now be longer, but that in some limited cases it improves readability when you otherwise would be only a few characters over the limit. In fairness a line that approaches 119 would probably be best split up anyway, but it's our choice if it's really the best option, not of the style checker.
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.
To be honest, I don't really know. It's something I have picked up somewhere over time and it seems to work great. I guess an advantage would be that with only
72
characters not to manyfrom
imports are on one line, seetest_piplicenses.py
for example.
Okay, I understand. Indeed, it seems to be working well.
That doesn't mean that every line should now be longer, but that in some limited cases it improves readability when you otherwise would be only a few characters over the limit.
In limited cases, you're right. I'm following the Python community standard for now.
Yes, I agree with your proposal. We have a lot of unit test code. It will also help when changing to a package structure. The test code you added is one of them. |
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.
I checked this P-R.
It will be imported and shipped in the next release version 3.3.0. The work is scheduled for the weekend around 2021-01-23.
Thanks for the quick review. Would it be an idea to create a separate |
That's also where squash merge has the most benefits. Just to clarify, how the whole process would look like:
Some additional notes:
-- |
To express my personal opinion: I am against having a permanent Next, let's talk about the release plan. Improve argparser is a simple and beautiful advantage for many users. On the other hand, in the process of embarking on the move to the package structure, it is possible that some of the most recent issues that have arrived can be resolved. (e. g. #82 #81 ) It seems to me that this effort is worth working on the base branch as you suggest. For example, create a base branch such as I'm waiting for your opinion. |
That works for me. My intention behind the suggestion was simply to allow for a faster development pace. Implementing all changes would otherwise either require one huge PR, which would basically be unreviewable, or take months to complete. Having a separate branch thus allows for a faster turnaround once you approve a PR. I don't really have a name preference. Regarding the issues you mentioned, it's definitely worth keeping them in mind. I also mentioned some other topics in my last PR #86 which I would like to work on. Targeting |
While I was working on #88, I noticed some small issues. The last commit address these. |
@cdce8p Am I correct in understanding that your work on the Then I will start the next task. Please let me know if there is any miscommunication.
|
@raimon49 That is correct. This PR is complete. |
Co-authored-by: cdce8p <30130371+cdce8p@users.noreply.github.com> Squashed commit of the following: commit b7949b5 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Fri Jan 22 14:04:52 2021 +0100 Small bugfixes commit 8441671 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Tue Jan 19 20:44:22 2021 +0100 Update gitignore commit 53ebae0 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Tue Jan 19 20:00:13 2021 +0100 Add type hints for args commit ebc95e2 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Tue Jan 19 19:52:04 2021 +0100 Add isort config + reorder imports commit 3f08e86 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Tue Jan 19 19:50:15 2021 +0100 Add arg verify commit 2b885a1 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Tue Jan 19 00:39:06 2021 +0100 Bugfix display default values commit 72ddf16 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 23:54:10 2021 +0100 Use enums for arguments (from, order, format) commit 99ec862 Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 17:09:50 2021 +0100 Update readme commit 44cdf4e Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 16:48:56 2021 +0100 Add custom help text formatter commit 52055be Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 16:41:02 2021 +0100 Add argument groups commit 78b96bb Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 16:38:23 2021 +0100 Reorder arguments commit 0af008b Author: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon Jan 18 16:28:14 2021 +0100 Change code formatting - argparser * No code changes!
@raimon49 Something went wrong with the squash merge. Did you do it with Github? |
The following should work:
|
@cdce8p I worked on it. |
Looks like it worked. Thanks! |
@raimon49 Just one last thing: Do you want to release this as Edit: Nevermind, just saw that you updated the release as well. That should be enough. |
I have released 3.3.0 to PyPI based on commit 4ace27c. As far as I can see, there is no difference from the master branch that was forced to be pushed. $ git diff origin/master 4ace27c31978f42f77b979f90549277f94986ac3 I have determined that users who have the package installed will not be affected. So I decide that there is no need to release 3.3.1. |
Some improvements to the argument parser. This PR greatly improves the readability of the help command and introduces
Enums
for arguments.Current help text
Changes
\n
in help strings are now rendered correctlymax_help_position
to avoid unnecessary line breaksfrom
,order
andformat
from
,order
andformat
--
I've split these changes into multiple commits to make reviewing them a bit easier.
On a related note, what is your opinion to
squash merge
for PRs? Although it might seem counterintuitive at first, I think it makes the git log much easier to read and the Github integration is better. The squash commit message includes the PR number which will be automatically be linked (forgit blame
).