Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file level docstring in aggregators #34

Merged
merged 1 commit into from
Aug 16, 2023
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
9 changes: 9 additions & 0 deletions devtale/aggregators/php.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ def __init__(self):

def document(self, documentation, code):
documented_code = code
documented_code = self._document_file(documentation, documented_code)
documented_code = self._document_functions(documentation, documented_code)
documented_code = self._document_classes(documentation, documented_code)
return documented_code

def _document_file(self, documentation, code):
file_description = documentation["file_docstring"]
docstring = self._format_docstring(file_description, 0)

code = docstring + "\n" + code

return code

def _document_functions(self, documentation, code):
for method_data in documentation["methods"]:
method_name = method_data["method_name"]
Expand Down
9 changes: 9 additions & 0 deletions devtale/aggregators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self):
pass

def document(self, documentation, code):
code = self._add_file_level_docstring(code, documentation)
code_w_placeholders = self._add_placeholders(code)
code_definitions = self._get_code_definitions(code_w_placeholders)
documented_code = code
Expand Down Expand Up @@ -55,6 +56,14 @@ def document(self, documentation, code):

return documented_code

def _add_file_level_docstring(self, code: str, documentation):
file_description = documentation["file_docstring"]
docstring = f'"""{file_description}\n"""\n'

code = docstring + "\n" + code

return code

def _add_placeholders(self, code: str):
code_tree = ast.parse(code)
placeholder_adder = Placeholder()
Expand Down