Skip to content

Commit

Permalink
Implement Mandatory and Optional fields as tree structures
Browse files Browse the repository at this point in the history
  • Loading branch information
palaciosjeremias committed Jul 29, 2021
1 parent 8d560c9 commit 51af91a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
19 changes: 9 additions & 10 deletions docs/DocGenerator/CodeParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import yaml
from Config import Config
from TestCaseParser import TestCaseParser
from Utils import remove_inexistent
from docstring_parser import parse
from comment_parser import comment_parser
import warnings

INTERNAL_FIELDS = ['Tests','Test Cases', 'Id', 'Group Id', 'Name']
INTERNAL_FIELDS = ['Id', 'Group Id', 'Name']
STOP_FIELDS = ['Tests','Test Cases']

class CodeParser:
def __init__(self):
Expand All @@ -27,14 +29,11 @@ def is_documentable_function(self, function):

def remove_ignored_fields(self, doc):
allowed_fields = self.conf.module_fields.mandatory + self.conf.module_fields.optional + INTERNAL_FIELDS
for field in list(doc):
if field not in allowed_fields:
del doc[field]
allowed_fields = self.conf.test_fields.mandatory + self.conf.test_fields.optional + INTERNAL_FIELDS
for test in list(doc['Tests']):
for field in list(test):
if field not in allowed_fields:
del test[field]
remove_inexistent(doc, allowed_fields, STOP_FIELDS)
if 'Tests' in doc:
allowed_fields = self.conf.test_fields.mandatory + self.conf.test_fields.optional + INTERNAL_FIELDS
for test in doc['Tests']:
remove_inexistent(test, allowed_fields, STOP_FIELDS)

def parse_comment(self, function):
docstring = ast.get_docstring(function)
Expand All @@ -45,7 +44,7 @@ def parse_comment(self, function):

except Exception as inst:
if hasattr(function, 'name'):
warnings.warn(f"Error parsing comment of function {function.name} from module {self.scan_file}")
warnings.warn(f"Error parsing comment of function '{function.name}'' from module {self.scan_file}")
else:
warnings.warn(f"Error parsing comment of module {self.scan_file}")
print(type(inst))
Expand Down
17 changes: 14 additions & 3 deletions docs/DocGenerator/Sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ def get_content(self, full_path):
raise Exception(f"Cannot load {full_path} file")

def validate_fields(self, required_fields, available_fields):
for field in required_fields:
if not check_existance(available_fields, field):
self.add_report(f"Mandatory field '{field}' is missing in file {self.scan_file}")
if isinstance(required_fields, dict):
for field in required_fields:
if not check_existance(available_fields, field):
self.add_report(f"Mandatory field '{field}' is missing in file {self.scan_file}")
elif isinstance(required_fields[field], dict) or isinstance(required_fields[field], list):
self.validate_fields(required_fields[field], available_fields)
elif isinstance(required_fields, list):
for field in required_fields:
if isinstance(field, dict) or isinstance(field, list):
self.validate_fields(field, available_fields)
else:
if not check_existance(available_fields, field):
self.add_report(f"Mandatory field '{field}' is missing in file {self.scan_file}")


def validate_module_fields(self, fields):
self.validate_fields(self.conf.module_fields.mandatory, fields)
Expand Down
12 changes: 6 additions & 6 deletions docs/DocGenerator/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def check_existance(source, key):
if key in source:
return True
elif isinstance(source, dict):

for item in source:
if check_existance(source[item], key):
return True
Expand All @@ -18,13 +17,14 @@ def check_existance(source, key):
else:
return False

def remove_inexistent(source, keys):
def remove_inexistent(source, check_list, stop_list=None):
for element in list(source):
if element not in keys:
if stop_list and element in stop_list:
break
if not check_existance(check_list, element):
del source[element]
else:
if isinstance(source[element], dict):
remove_inexistent(source[element], keys)
elif isinstance(source[element], dict):
remove_inexistent(source[element], check_list, stop_list)

def get_keys_dict(dic):
keys = []
Expand Down
10 changes: 5 additions & 5 deletions docs/DocGenerator/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Output fields:
Module:
Mandatory:
- Brief
- Metadata
- Modules
- Daemons
- Operating System
- Tiers
- Metadata:
- Modules
- Daemons
- Operating System
- Tiers
Optional:
- Tags
Test:
Expand Down

0 comments on commit 51af91a

Please sign in to comment.