-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
GH-57015: Add argparse FlexiHelpFormatter #22129
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
base: main
Are you sure you want to change the base?
Conversation
d82ce68 to
da19cdd
Compare
Unfortunately, argparse's proposed FlexiHelpFormatter does not yet exist, see python/cpython#22129.
96c0799 to
008764b
Compare
Rebase to force CI retest. The "addres sanitizer" test is failing with a timeout, on test_multiprocessing_fork.WithProcessesTestQueue(). It is not likely that this branch contributed to that failure. https://github.com/python/cpython/pull/22129/checks?check_run_id=3033564406
a3ac677 to
a21117a
Compare
savannahostrowski
left a comment
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.
Hey there - I just saw this has been opened for awhile but I think this is a great formatter addition. I have a couple of comment but I've played around with this quite a bit and it looks pretty solid!
Doc/library/argparse.rst
Outdated
| -h, --help show this help message and exit | ||
|
|
||
|
|
||
| .. versionadded:: 3.13 |
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.
| .. versionadded:: 3.13 | |
| .. versionadded:: 3.15 |
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.
Commit 8e20754.
Doc/library/argparse.rst
Outdated
|
|
||
| .. class:: RawDescriptionHelpFormatter | ||
| RawTextHelpFormatter | ||
| FlexiHelpFormatter |
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 don't think that FlexiHelpFormatter is descriptive enough. I'd suggest something like:
| FlexiHelpFormatter | |
| ParagraphHelpFormatter |
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.
Changed to ParagraphHelpFormatter in 2b30019.
Lib/argparse.py
Outdated
| lines = self._para_reformat(text, width) | ||
| return "\n".join(lines) |
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.
| lines = self._para_reformat(text, width) | |
| return "\n".join(lines) | |
| lines = self._para_reformat(text, width - len(indent)) | |
| return "\n".join(indent + line for line in lines) |
As is, this eats any form of indentation that the user might have specified, which I think we want to preserve.
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.
Commit 2a53ad4.
Doc/library/argparse.rst
Outdated
| one. If you wish to preserve multiple blank lines, add spaces between the | ||
| newlines. | ||
|
|
||
| :class:`FlexiHelpFormatter` wraps description and help text like the default |
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.
We should also make it more clear that consecutive non-blank lines at the same indentation without supported bullet markers are merged into one paragraph. Users should add blank lines if they want to preserve formatting.
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.
Addressed in ec6d2d7.
Doc/library/argparse.rst
Outdated
| formatter, while preserving paragraphs and supporting bulleted lists. Bullet | ||
| list items are marked by the use of the "*", "-", "+", or ">" characters, or a | ||
| single non-whitespace character followed by a ".":: |
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.
| formatter, while preserving paragraphs and supporting bulleted lists. Bullet | |
| list items are marked by the use of the "*", "-", "+", or ">" characters, or a | |
| single non-whitespace character followed by a ".":: | |
| formatter, while preserving paragraphs and supporting bulleted lists. Bullet | |
| list items are recognized by markers such as "*", "-", "+", or ">" characters, or | |
| by alphanumeric sequences followed by "." or ")" (e.g. 1., a), iv.):: |
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.
Sorry, I nuked the last part of your change. I thought it was mine, and has trouble reading it.
Doc/library/argparse.rst
Outdated
| ... * See? | ||
| ... """) | ||
| >>> parser.print_help() | ||
| usage: PROG [-h] option |
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.
| usage: PROG [-h] option | |
| usage: PROG [-h] argument |
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.
Commit ae7c70f.
Doc/library/argparse.rst
Outdated
| wrap: | ||
| * See? | ||
|
|
||
| optional arguments: |
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.
| optional arguments: | |
| 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.
Commit f64e966.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
Co-authored-by: Savannah Ostrowski <savannah@python.org>
It led to headaches in unittest.
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! @savannahostrowski: please review the changes made to this pull request. |
This adds the FlexiHelpFormatter class to argparse.
It supports wrapping text, while preserving paragraphs. Bullet lists are supported.
There are a number of differences, relative to the latest patch in the issue report:
Tests and documentation are included.
https://pypi.org/project/argparse-formatter/
https://bugs.python.org/issue12806