Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion erfa/core.py.templ
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ STATUS_CODES['{{ func.pyname }}'] = {{ stat.to_python() }}

def {{ func.pyname }}({{ func.args_by_inout('in|inout')|map(attribute='name')|join(', ') }}):
"""
{{ func.doc.title }}
{{ func.doc.first_sentence | indent(2)}}
{%- if func.args_by_inout('in|inout') %}

Parameters
Expand Down
23 changes: 7 additions & 16 deletions erfa_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class FunctionDoc:
def __init__(self, doc: str, pyname: str) -> None:
self.pyname: Final = pyname
if pyname == "ldn":
doc = doc.removeprefix("+")
elif pyname == "aticqn":
Expand Down Expand Up @@ -62,22 +63,12 @@ def _get_arg_doc_list(self, regex: str, n_spaces: int) -> set[str]:
return set(doc_list)

@property
def title(self):
# Used for the docstring title.
lines = [line.strip() for line in self.doc.split('\n')[4:10]]
# Always include the first line, then stop at either an empty
# line or at the end of a sentence.
description = lines[:1]
for line in lines[1:]:
if line == '':
break
if '. ' in line:
line = line[:line.index('. ')+1]
description.append(line)
if line.endswith('.'):
break

return '\n '.join(description)
def first_sentence(self) -> str:
if m := re.search(r"[- ]+\n\n (.+?\.)\s", self.doc, re.DOTALL):
return m.group(1)
raise RuntimeError(
f"cannot find the first sentence of {self.pyname} doc comment"
)


class Variable:
Expand Down
Loading