Skip to content
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

bpo-14102: argparse: Add generate man page #1169

Closed
wants to merge 12 commits into from
Closed

bpo-14102: argparse: Add generate man page #1169

wants to merge 12 commits into from

Conversation

louisom
Copy link
Contributor

@louisom louisom commented Apr 18, 2017

No description provided.

Copy link
Contributor

@keszybz keszybz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice. It didn't actually run the code, but it should be possible to do something like python3 -c 'import mymodule; mymodule.parser().print_manpage() from the build system without any fuss.


.. method:: ArgumentParser.add_manpage_section(heading, description)

Adding new section to man page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Add a new section to the man page. This only has an effect if print_manpage is used."


Description of parameters:

* heading: title of the section, it will automatically convert to upper case
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the title of the section, it will be automatically converted to upper case"

Description of parameters:

* heading: title of the section, it will automatically convert to upper case
* description: description about this section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called content. What is the format of this text? Raw TROFF? This should be documented.

* heading: title of the section, it will automatically convert to upper case
* description: description about this section

Some example usage::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some


Some example usage::

>>> # Adding Copyright section
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Add a Copyright section"

Lib/argparse.py Outdated
# no help; start on same line and add a final newline
if not action.help:
tup = self._current_indent, '', action_header
action_header = '%*s%s' % tup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, why %-formatting here?

   action_header = '{:{}}{}'.format('', self._current_indent, action_header)

Lib/argparse.py Outdated
# short action name; start on the same line and pad two spaces
elif len(action_header) <= action_width:
tup = self._current_indent, '', action_width, action_header
action_header = '%*s%-*s ' % tup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action_header = '{:{}}{:>{}}'.format('', self._current_indent, action_header, action_width)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is better or not, letting this be a longer line.

This code is from argparse itself.

Lib/argparse.py Outdated
action_width = help_position - self._current_indent - 2
action_header = self._format_action_invocation(action)

# no help; start on same line and add a final newline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those comments should be moved under the if, and then the whole if-ifelse-else does not need to be divided by empty lines.

Lib/argparse.py Outdated
@@ -2345,6 +2491,11 @@ def format_help(self):
# determine help from format above
return formatter.format_help()

def format_manpage(self):
formatter = self._get_formatter()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spurious empty line.

Misc/NEWS Outdated
@@ -313,6 +313,8 @@ Extension Modules
Library
-------

- bpo-14102: argparse now can generate Unix man page. Patch by Louie Lu.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"UNIX man pages"

@codecov
Copy link

codecov bot commented Apr 19, 2017

Codecov Report

Merging #1169 into master will decrease coverage by 0.02%.
The diff coverage is 1.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1169      +/-   ##
==========================================
- Coverage   83.44%   83.42%   -0.03%     
==========================================
  Files        1367     1367              
  Lines      346017   346108      +91     
==========================================
+ Hits       288721   288727       +6     
- Misses      57296    57381      +85
Impacted Files Coverage Δ
Lib/argparse.py 77.91% <1.09%> (-5.9%) ⬇️
Lib/test/test_logging.py 94.98% <0%> (+0.04%) ⬆️
Lib/heapq.py 98.85% <0%> (+1.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6d344d...34a1ac7. Read the comment docs.

praiskup added a commit to praiskup/argparse-manpage that referenced this pull request Sep 24, 2017
praiskup added a commit to praiskup/argparse-manpage that referenced this pull request Sep 24, 2017
OPTIONS
optional arguments
-h, --help
show this help message and exit
Copy link
Member

@merwok merwok Feb 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this the real output? I would expect the command to print out the man page markup, so that it can be saved as a program.1 file and distributed by downstream packagers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the code does produce the markup as I expected!

It’s the example that’s missing something:

$ python myprogram.py --manpage | nroff -man
...

@csabella
Copy link
Contributor

csabella commented Jun 5, 2019

As this pull request has an 'unknown repository' for its branch, I'm going to close it. There is a lot of discussion for this issue on the bug tracker, so any replacement pull request should take all the open concerns into consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants