Skip to content

Commit 260f217

Browse files
authored
Merge pull request #9594 from hkuno/pr/no_empty_desc_4.x
let user skip printing command description
2 parents c44ee0e + fb141c3 commit 260f217

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Features added
1919
3.10 or above
2020
* #9447: html theme: Expose the version of Sphinx in the form of tuple as a
2121
template variable ``sphinx_version_tuple``
22+
* #9594: manpage: Suppress the title of man page if description is empty
2223
* #9445: py domain: ``:py:property:`` directive supports ``:classmethod:``
2324
option to describe the class property
2425
* #9524: test: SphinxTestApp can take ``builddir`` as an argument

doc/usage/configuration.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,8 @@ These options influence manual page output.
23312331

23322332
*description*
23332333
Description of the manual page. This is used in the NAME section.
2334+
Can be an empty string if you do not want to automatically generate
2335+
the NAME section.
23342336

23352337
*authors*
23362338
A list of strings with authors, or a single string. Can be an empty

sphinx/writers/manpage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ def __init__(self, document: nodes.document, builder: Builder) -> None:
112112
# overwritten -- added quotes around all .TH arguments
113113
def header(self) -> str:
114114
tmpl = (".TH \"%(title_upper)s\" \"%(manual_section)s\""
115-
" \"%(date)s\" \"%(version)s\" \"%(manual_group)s\"\n"
116-
".SH NAME\n"
117-
"%(title)s \\- %(subtitle)s\n")
115+
" \"%(date)s\" \"%(version)s\" \"%(manual_group)s\"\n")
116+
if self._docinfo['subtitle']:
117+
tmpl += (".SH NAME\n"
118+
"%(title)s \\- %(subtitle)s\n")
118119
return tmpl % self._docinfo
119120

120121
def visit_start_of_file(self, node: Element) -> None:

tests/test_build_manpage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_all(app, status, warning):
2323
assert r'\fBprint \fP\fIi\fP\fB\en\fP' in content
2424
assert r'\fBmanpage\en\fP' in content
2525

26+
# heading (title + description)
27+
assert r'sphinxtests \- Sphinx <Tests> 0.6alpha1' in content
28+
2629
# term of definition list including nodes.strong
2730
assert '\n.B term1\n' in content
2831
assert '\nterm2 (\\fBstronged partially\\fP)\n' in content
@@ -35,6 +38,15 @@ def test_all(app, status, warning):
3538
assert 'Footnotes' not in content
3639

3740

41+
@pytest.mark.sphinx('man', testroot='basic',
42+
confoverrides={'man_pages': [('index', 'title', None, [], 1)]})
43+
def test_man_pages_empty_description(app, status, warning):
44+
app.builder.build_all()
45+
46+
content = (app.outdir / 'title.1').read_text()
47+
assert r'title \-' not in content
48+
49+
3850
@pytest.mark.sphinx('man', testroot='basic',
3951
confoverrides={'man_make_section_directory': True})
4052
def test_man_make_section_directory(app, status, warning):

0 commit comments

Comments
 (0)