Switch to namedtuple

This commit is contained in:
Julio Castillo
2022-10-20 16:26:09 +02:00
parent 8366933f4d
commit 5bd195aa8f
2 changed files with 11 additions and 9 deletions

View File

@@ -47,13 +47,14 @@ def _check_dir(dir_name, exclude_files=None, files=False, show_extra=False):
state = State.SKIP
else:
try:
new_doc, _, variables, outputs = tfdoc.create_doc(
readme_path.parent, files, show_extra, exclude_files, readme)
variables = [v.name for v in variables]
new_doc = tfdoc.create_doc(readme_path.parent, files, show_extra,
exclude_files, readme)
variables = [v.name for v in new_doc.variables]
outputs = [v.name for v in new_doc.outputs]
except SystemExit:
state = state.SKIP
else:
if new_doc == result['doc']:
if new_doc.content == result['doc']:
state = State.OK
elif variables != sorted(variables):
state = state.FAIL
@@ -72,7 +73,8 @@ def _check_dir(dir_name, exclude_files=None, files=False, show_extra=False):
else:
state = State.FAIL
header = f'----- {mod_name} diff -----\n'
ndiff = difflib.ndiff(result['doc'].split('\n'), new_doc.split('\n'))
ndiff = difflib.ndiff(result['doc'].split('\n'),
new_doc.content.split('\n'))
diff = '\n'.join([header] + list(ndiff))
yield mod_name, state, diff

View File

@@ -99,13 +99,13 @@ VAR_RE = re.compile(r'''(?smx)
VAR_RE_TYPE = re.compile(r'([\(\{\}\)])')
VAR_TEMPLATE = ('default', 'description', 'type', 'nullable')
Document = collections.namedtuple('Document', 'content files variables outputs')
File = collections.namedtuple('File', 'name description modules resources')
Output = collections.namedtuple(
'Output', 'name description sensitive consumers file line')
Variable = collections.namedtuple(
'Variable',
'name description type default required nullable source file line')
# parsing functions
@@ -359,7 +359,7 @@ def create_doc(module_path, files=False, show_extra=False, exclude_files=None,
except (IOError, OSError) as e:
raise SystemExit(e)
doc = format_doc(mod_outputs, mod_variables, mod_files, show_extra)
return (doc, mod_files, mod_variables, mod_outputs)
return Document(doc, mod_files, mod_variables, mod_outputs)
def get_readme(readme_path):
@@ -401,9 +401,9 @@ def main(module_path=None, exclude_file=None, files=False, replace=True,
'Program entry point.'
readme_path = os.path.join(module_path, 'README.md')
readme = get_readme(readme_path)
doc, *_ = create_doc(module_path, files, show_extra, exclude_file, readme)
doc = create_doc(module_path, files, show_extra, exclude_file, readme)
if replace:
replace_doc(readme_path, doc, readme)
replace_doc(readme_path, doc.content, readme)
else:
print(doc)