Skip to content

Commit 7eea69d

Browse files
committed
0.4.3 Update
Added the possibility of making a short module description by beginning some lines in the module comment with :synopsis:. If these lines are found, they are added to a separate category knows as "Synopsis". If they are not, old behavior is triggered
1 parent 70c8d09 commit 7eea69d

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = 'sphinxfortran_ng'
3-
version = '0.4.2'
3+
version = '0.4.3'
44
authors = [{name = "Lorenzo Crippa", email="[email protected]"}]
55
description = "An improved version of the sphinx-fortran python module"
66
readme = "README.md"

src/sphinxfortran_ng/fortran_autodoc.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def scan(self):
341341
modsrc = self.get_blocksrc(block)
342342

343343
# Get module description
344-
block['desc'] = self.get_comment(modsrc, aslist=True)
344+
block['desc'],block['synopsis'] = self.get_comment(modsrc, aslist=True)
345345

346346
# Scan types and routines
347347
for subblock in block['body']:
@@ -392,7 +392,7 @@ def scan_container(self, block, insrc=None):
392392
subsrc = self.get_blocksrc(block, insrc)
393393

394394
# Comment
395-
block['desc'] = self.get_comment(subsrc, aslist=True)
395+
block['desc'],block['synopsis'] = self.get_comment(subsrc, aslist=True)
396396

397397
# Scan comments to find descriptions
398398
if block['desc'] and block['block'] in [
@@ -671,6 +671,7 @@ def get_comment(
671671
- OR ``scomment,ilast``: if ``getilast is True``
672672
"""
673673
scomment = []
674+
synopsis = []
674675
if src:
675676
in_a_breaked_line = src[0].strip().endswith('&')
676677
for iline in range(iline, len(src)):
@@ -713,15 +714,18 @@ def get_comment(
713714
prefix = self._re_space_prefix_match(comment).group(1)
714715
if comment.startswith(prefix):
715716
comment = comment[len(prefix):]
716-
717-
# Save comment
718-
scomment.append(comment)
717+
# Is it the synopsis?
718+
if comment.lstrip().startswith(':synopsis:'):
719+
synopsis.append(comment.replace(':synopsis:',''))
720+
else:
721+
scomment.append(comment)
719722

720723
if not aslist:
721724
scomment = self.format_lines(scomment, nlc=' ')
725+
synopsis = self.format_lines(synopsis, nlc=' ')
722726
if getilast:
723727
return scomment, iline
724-
return scomment
728+
return scomment, synopsis
725729

726730
def get_synopsis(self, block, nmax=3):
727731
"""Get the first ``nmax`` non empty lines of the function, type or module comment as 1 line.
@@ -730,17 +734,22 @@ def get_synopsis(self, block, nmax=3):
730734
If description if empty, it returns an empty string.
731735
"""
732736
sd = []
733-
for line in block['desc']:
734-
line = line.strip()
735-
if not line:
736-
if not sd:
737-
continue
738-
break
739-
sd.append(line)
740-
if len(sd) > nmax:
741-
if sd[-1].endswith('.'):
742-
sd[-1] += '..'
743-
break
737+
if block['synopsis']:
738+
for line in block['synopsis']:
739+
line = line.strip()
740+
sd.append(line)
741+
else:
742+
for line in block['desc']:
743+
line = line.strip()
744+
if not line:
745+
if not sd:
746+
continue
747+
break
748+
sd.append(line)
749+
if len(sd) > nmax:
750+
if sd[-1].endswith('.'):
751+
sd[-1] += '..'
752+
break
744753
if not sd:
745754
return ''
746755
sd = ' '.join(sd)
@@ -1643,6 +1652,15 @@ def format_variables(self, block, indent=0, ownSection=False):
16431652
elif variables and ownSection: variables += '\n\n'
16441653
return variables
16451654

1655+
def format_synopsis(self, block, indent=0):
1656+
"""Format the description of an object"""
1657+
synopsis = ''
1658+
if block['synopsis']:
1659+
synopsis = self.format_subsection('Synopsis', indent=indent)
1660+
synopsis += self.format_lines(
1661+
block['synopsis'], indent=indent, strip=True) + '\n'
1662+
return synopsis
1663+
16461664
def format_description(self, block, indent=0):
16471665
"""Format the description of an object"""
16481666
description = ''
@@ -1682,6 +1700,9 @@ def format_module(self, block, indent=0):
16821700
'module', modname, indent=indent, options=dict(
16831701
synopsis=self.get_synopsis(block).strip() or None))
16841702

1703+
# Description
1704+
synopsis = self.format_synopsis(block, indent=indent)
1705+
16851706
# Description
16861707
description = self.format_description(block, indent=indent)
16871708

@@ -1703,7 +1724,7 @@ def format_module(self, block, indent=0):
17031724
if self.hide_output:
17041725
return declaration
17051726
else:
1706-
return declaration + description + quickaccess + \
1727+
return declaration + synopsis + description + quickaccess + \
17071728
use + types + variables + routines
17081729

17091730
def format_srcfile(

0 commit comments

Comments
 (0)