Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Add prompt for bad nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjoeoui committed Oct 17, 2023
1 parent 44f995a commit b6b44e5
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions parse_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Get the current directory
current_directory = os.getcwd()

total_bad = 0

# Walk through all the folders and files in the current directory
for root, dirs, files in os.walk(current_directory):
# Iterate through the files
Expand Down Expand Up @@ -44,34 +46,49 @@
# Process the docstring using docstring_parser
parsed_docstring = parse(docstring)

if (
parsed_docstring.short_description
or parsed_docstring.long_description
):
# Build the JSON data
json_data = {
"description": parsed_docstring.long_description,
"parameters": [
{
"name": param.arg_name,
"type": param.type_name,
"description": param.description,
}
for param in parsed_docstring.params
],
"returns": [
{
"name": rtn.return_name,
"type": rtn.type_name,
"description": rtn.description,
}
for rtn in parsed_docstring.many_returns
],
}
if not parsed_docstring.long_description:
print(
f"ATTENTION: description not found for {function_name}"
)
total_bad += 1
if not parsed_docstring.params:
print(
f"ATTENTION: 'Parameters' not found for {function_name}"
)
total_bad += 1
if not parsed_docstring.many_returns:
print(f"ATTENTION: 'Returns' not found for {function_name}")
total_bad += 1

# Build the JSON data
json_data = {
"description": parsed_docstring.long_description,
"parameters": [
{
"name": param.arg_name,
"type": param.type_name,
"description": param.description,
}
for param in parsed_docstring.params
],
"returns": [
{
"name": rtn.return_name,
"type": rtn.type_name,
"description": rtn.description,
}
for rtn in parsed_docstring.many_returns
],
}

# Write the data to a JSON file in the same directory
output_file_path = os.path.join(root, "docstring.json")
with open(output_file_path, "w") as output_file:
json.dump(json_data, output_file, indent=2)
# Write the data to a JSON file in the same directory
output_file_path = os.path.join(root, "docstring.json")
with open(output_file_path, "w") as output_file:
json.dump(json_data, output_file, indent=2)

# sys.exit(0)
else:
print(f"ATTENTION: Docstring not found for {function_name}")
total_bad += 1

print(f"Summary: found {total_bad} problems with docstring formatting")

0 comments on commit b6b44e5

Please sign in to comment.