refactor(cli): move sections list parsing to function

This commit is contained in:
jakob.scheid committed 2026-09-13 19:04:54 +02:00
1 parent 8644232a00
commit 089cf5f2ff
1 file changed
+37 -18
+37 -18
View File
@@ -18,11 +18,47 @@ from typing import Optional
__all__ = [
'VALID_SECTIONS',
'parse_sections_list',
'generate'
]
VALID_SECTIONS = list(PythonDefinitionDocumentationIncludeSections()._args.keys())
def parse_sections_list(include_sections: Optional[list[str]] = None, exclude_sections: list[str] = []) -> PythonDefinitionDocumentationIncludeSections:
'''
Returns a Python definition documentation sections list from the
sections list to be included and the sections list to be excluded.
These lists both consist of the sections as strings which contain
the section name.
:param include_sections: The list of sections to be included.
:type include_sections: Optional[list[str]]
:param exclude_sections: The list of sections to be excluded.
:type exclude_sections: list[str]
:return: The Python definition documentation sections object.
:rtype: PythonDefinitionDocumentationIncludeSections
'''
if include_sections is None:
include_sections = VALID_SECTIONS
for section in exclude_sections:
while section in include_sections:
del include_sections[include_sections.index(section)]
return PythonDefinitionDocumentationIncludeSections(
signature = 'signature' in include_sections,
returns = 'returns' in include_sections,
params = 'params' in include_sections,
exceptions = 'exceptions' in include_sections,
examples = 'examples' in include_sections,
docstring = 'docstring' in include_sections,
bases = 'bases' in include_sections,
decorators = 'decorators' in include_sections,
class_body = 'class_body' in include_sections
)
def _generate(
project_directory: pathlib.Path,
output_directory: pathlib.Path,
@@ -86,24 +122,7 @@ def generate(
Warning: Markdown tables are not CommonMark.
'''
if include_sections is None:
include_sections = VALID_SECTIONS
for section in exclude_sections:
while section in include_sections:
del include_sections[include_sections.index(section)]
sections = PythonDefinitionDocumentationIncludeSections(
signature = 'signature' in include_sections,
returns = 'returns' in include_sections,
params = 'params' in include_sections,
exceptions = 'exceptions' in include_sections,
examples = 'examples' in include_sections,
docstring = 'docstring' in include_sections,
bases = 'bases' in include_sections,
decorators = 'decorators' in include_sections,
class_body = 'class_body' in include_sections
) if include_sections else PythonDefinitionDocumentationIncludeSections()
sections = parse_sections_list(include_sections, exclude_sections)
_generate(
project_directory,