From 8366933f4db45c61ca30eb895c3f3b7c6a2f59d0 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Thu, 20 Oct 2022 16:15:41 +0200 Subject: [PATCH] Bring back sorted variables check --- tools/check_documentation.py | 21 ++++++++++++++++++--- tools/tfdoc.py | 5 +++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/check_documentation.py b/tools/check_documentation.py index 2a6dd8ecf..e1edda0eb 100755 --- a/tools/check_documentation.py +++ b/tools/check_documentation.py @@ -47,13 +47,28 @@ def _check_dir(dir_name, exclude_files=None, files=False, show_extra=False): state = State.SKIP else: try: - new_doc = tfdoc.create_doc(readme_path.parent, files, show_extra, - exclude_files, readme) + new_doc, _, variables, outputs = tfdoc.create_doc( + readme_path.parent, files, show_extra, exclude_files, readme) + variables = [v.name for v in variables] except SystemExit: state = state.SKIP else: if new_doc == result['doc']: state = State.OK + elif variables != sorted(variables): + state = state.FAIL + diff = "\n".join([ + f'----- {mod_name} variables -----', + f'variables should be in this order: ', + ', '.join(sorted(variables)), + ]) + elif outputs != sorted(outputs): + state = state.FAIL + diff = "\n".join([ + f'----- {mod_name} outputs -----', + f'outputs should be in this order: ', + ', '.join(sorted(outputs)), + ]) else: state = State.FAIL header = f'----- {mod_name} diff -----\n' @@ -73,7 +88,7 @@ def main(dirs, exclude_file=None, files=False, show_diffs=False, 'Cycle through modules and ensure READMEs are up-to-date.' print(f'files: {files}, extra: {show_extra}, diffs: {show_diffs}\n') errors = [] - state_labels = {State.FAIL: '✗', State.OK: '✓', State.SKIP: '?'} + state_labels = {State.FAIL: '✗', State.OK: '✓', State.SKIP: ' '} for dir_name in dirs: print(f'----- {dir_name} -----') for mod_name, state, diff in _check_dir(dir_name, exclude_file, files, diff --git a/tools/tfdoc.py b/tools/tfdoc.py index d7771fb58..aeb634086 100755 --- a/tools/tfdoc.py +++ b/tools/tfdoc.py @@ -358,7 +358,8 @@ def create_doc(module_path, files=False, show_extra=False, exclude_files=None, mod_outputs = list(parse_outputs(module_path, exclude_files)) except (IOError, OSError) as e: raise SystemExit(e) - return format_doc(mod_outputs, mod_variables, mod_files, show_extra) + doc = format_doc(mod_outputs, mod_variables, mod_files, show_extra) + return (doc, mod_files, mod_variables, mod_outputs) def get_readme(readme_path): @@ -400,7 +401,7 @@ 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) else: