diff --git a/doc/utils/check-styles.py b/doc/utils/check-styles.py index 603f312e9d..45876ea738 100755 --- a/doc/utils/check-styles.py +++ b/doc/utils/check-styles.py @@ -60,6 +60,7 @@ reader = {} region = {} total = 0 +index_pattern = re.compile(r"^.. index:: (compute|fix|pair_style|angle_style|bond_style|dihedral_style|improper_style|kspace_style)\s+([a-zA-Z0-9/_]+)$") style_pattern = re.compile(r"(.+)Style\((.+),(.+)\)") upper = re.compile("[A-Z]+") gpu = re.compile("(.+)/gpu$") @@ -70,6 +71,26 @@ omp = re.compile("(.+)/omp$") opt = re.compile("(.+)/opt$") removed = re.compile("(.*)Deprecated$") +def load_index_entries_in_file(path): + entries = [] + with open(path, 'r') as reader: + for line in reader: + m = index_pattern.match(line) + if m: + command_type = m.group(1) + style = m.group(2) + entries.append((command_type, style)) + return entries + +def load_index_entries(): + index = {'compute': set(), 'fix': set(), 'pair_style': set(), 'angle_style': set(), + 'bond_style': set(), 'dihedral_style': set(), 'improper_style': set(), 'kspace_style': set()} + rst_files = glob(os.path.join(doc_dir, '*.rst')) + for f in rst_files: + for command_type, style in load_index_entries_in_file(f): + index[command_type].add(style) + return index + def register_style(styles, name, info): if name in styles: for key, value in info.items(): @@ -112,6 +133,24 @@ def check_style(filename, dirname, pattern, styles, name, suffix=False, skip=set counter += 1 return counter +def check_style_index(name, styles, index): + counter = 0 + for style in styles: + if style not in index and not styles[style]['removed']: + print(f"{name} index entry {style} is missing") + counter += 1 + + for suffix in styles[style]: + if suffix == 'removed': continue + if suffix == 'kokkos': + suffix_style = f"{style}/kk" + else: + suffix_style = f"{style}/{suffix}" + if styles[style][suffix] and suffix_style not in index: + print(f"{name} index entry {suffix_style} is missing") + counter += 1 + return counter + for header in headers: if verbose: print("Checking ", header) with open(header) as f: @@ -207,6 +246,13 @@ Total number of styles (including suffixes): %d""" \ len(fix), len(improper), len(integrate), len(kspace), \ len(minimize), len(pair), len(reader), len(region), total)) +index = load_index_entries() + +total_index = 0 +for command_type, entries in index.items(): + total_index += len(entries) + +print("Total number of style index entries:", total_index) counter = 0 @@ -244,5 +290,18 @@ counter += check_style('Commands_kspace.rst', doc_dir, ":doc:`(.+)