New tfdoc version (#396)
* update tfdoc * rewrite check docs, refactor tfdoc replace, regenerate modules READMEs * remove dead code from check docs * do not fail on missing variable files in check docs * fix typos
This commit is contained in:
committed by
GitHub
parent
d2cbf800fc
commit
1ac3fe4460
@@ -16,87 +16,44 @@
|
||||
|
||||
import enum
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import click
|
||||
import tfdoc
|
||||
|
||||
|
||||
BASEDIR = pathlib.Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class DocState(enum.Enum):
|
||||
OK = 1
|
||||
FAIL = 2
|
||||
UNKNOWN = 3
|
||||
|
||||
def __str__(self):
|
||||
return {
|
||||
self.FAIL.value: '✗',
|
||||
self.OK.value: '✓',
|
||||
self.UNKNOWN.value: '?'
|
||||
}[self.value]
|
||||
State = enum.Enum('State', 'OK FAIL SKIP')
|
||||
|
||||
|
||||
def check_path(pathname):
|
||||
path = BASEDIR / pathname
|
||||
subpaths = sorted(list(path.iterdir()))
|
||||
for subpath in subpaths:
|
||||
errors = []
|
||||
if not subpath.is_dir():
|
||||
continue
|
||||
if subpath.stem.startswith('_'):
|
||||
continue
|
||||
|
||||
doc = subpath / 'README.md'
|
||||
if not doc.exists():
|
||||
errors.append(f'{doc} does not exist')
|
||||
|
||||
variables = tfdoc.get_variables(subpath)
|
||||
variable_names = [v.name for v in variables]
|
||||
for variable in variables:
|
||||
if not variable.description:
|
||||
errors.append(f'variable {variable.name} has no description')
|
||||
if sorted(variable_names) != variable_names:
|
||||
message = f'variable order should be: {sorted(variable_names)}'
|
||||
errors.append(message)
|
||||
|
||||
outputs = tfdoc.get_outputs(subpath)
|
||||
output_names = [v.name for v in outputs]
|
||||
for output in outputs:
|
||||
if not output.description:
|
||||
errors.append(f'output {output.name} has no description')
|
||||
if sorted(output_names) != output_names:
|
||||
message = f'output order should be: {sorted(output_names)}'
|
||||
errors.append(message)
|
||||
|
||||
state = tfdoc.check_state(subpath)
|
||||
if state is False:
|
||||
errors.append("documentation is out of date")
|
||||
elif state:
|
||||
pass
|
||||
def _check_dir(dir_name):
|
||||
dir_path = BASEDIR / dir_name
|
||||
for readme_path in dir_path.glob('**/README.md'):
|
||||
readme = readme_path.read_text()
|
||||
mod_name = str(readme_path.relative_to(dir_path).parent)
|
||||
result = tfdoc.get_doc(readme)
|
||||
if not result:
|
||||
state = State.SKIP
|
||||
else:
|
||||
yield DocState.UNKNOWN, subpath.stem, errors
|
||||
continue
|
||||
|
||||
yield DocState.FAIL if errors else DocState.OK, subpath.stem, errors
|
||||
try:
|
||||
new_doc = tfdoc.create_doc(readme_path.parent)
|
||||
except SystemExit:
|
||||
state = state.SKIP
|
||||
else:
|
||||
state = State.OK if new_doc == result['doc'] else State.FAIL
|
||||
yield mod_name, state
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('paths', type=str, nargs=-1)
|
||||
def main(paths):
|
||||
"Cycle through modules and ensure READMEs are up-to-date."
|
||||
error = False
|
||||
for path in paths:
|
||||
print(f'checking {path}')
|
||||
for state, name, errors in check_path(path):
|
||||
if state == DocState.FAIL:
|
||||
error = True
|
||||
print(f' [{state}] {name}')
|
||||
for error in errors:
|
||||
print(f' {error}')
|
||||
if error:
|
||||
print('errors were present')
|
||||
sys.exit(1)
|
||||
@click.argument('dirs', type=str, nargs=-1)
|
||||
def main(dirs):
|
||||
'Cycle through modules and ensure READMEs are up-to-date.'
|
||||
state_labels = {State.FAIL: '✗', State.OK: '✓', State.SKIP: '?'}
|
||||
for dir_name in dirs:
|
||||
print(f'----- {dir_name} -----')
|
||||
for mod_name, state in _check_dir(dir_name):
|
||||
print(f'[{state_labels[state]}] {mod_name}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user