diff --git a/erfa/core.py.templ b/erfa/core.py.templ index e4d2410..d00c4b8 100644 --- a/erfa/core.py.templ +++ b/erfa/core.py.templ @@ -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 diff --git a/erfa_generator.py b/erfa_generator.py index db6145c..0b12dcd 100644 --- a/erfa_generator.py +++ b/erfa_generator.py @@ -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": @@ -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: