generated from jCloud/repository-template
refactor(cli): move sections list parsing to function
This commit is contained in:
1 file changed
+37
-18
@@ -18,11 +18,47 @@ from typing import Optional
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'VALID_SECTIONS',
|
'VALID_SECTIONS',
|
||||||
|
'parse_sections_list',
|
||||||
'generate'
|
'generate'
|
||||||
]
|
]
|
||||||
|
|
||||||
VALID_SECTIONS = list(PythonDefinitionDocumentationIncludeSections()._args.keys())
|
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(
|
def _generate(
|
||||||
project_directory: pathlib.Path,
|
project_directory: pathlib.Path,
|
||||||
output_directory: pathlib.Path,
|
output_directory: pathlib.Path,
|
||||||
@@ -86,24 +122,7 @@ def generate(
|
|||||||
Warning: Markdown tables are not CommonMark.
|
Warning: Markdown tables are not CommonMark.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if include_sections is None:
|
sections = parse_sections_list(include_sections, exclude_sections)
|
||||||
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()
|
|
||||||
|
|
||||||
_generate(
|
_generate(
|
||||||
project_directory,
|
project_directory,
|
||||||
|
|||||||
Reference in new issue
Block a user