"""Update list of supported functions in the doc.""" import argparse from concrete.numpy.tracing import Tracer def main(file_to_update): """Update list of supported functions in file_to_update""" f_names = sorted(f.__name__.replace("_", "\\_") for f in Tracer.SUPPORTED_NUMPY_OPERATORS) supported_func = [ f"[np.{f}](https://numpy.org/doc/stable/reference/generated/numpy.{f}.html)" for f in f_names ] with open(file_to_update, "r", encoding="utf-8") as file: lines = file.readlines() newlines = [] keep_line = True for line in lines: if line.startswith( "" ): keep_line = False newlines.append(line) newlines.append( "\n" ) elif line.startswith( "" ): pass elif line.startswith( "" ): keep_line = True # Inject the supported functions newlines.extend(f"* {f}\n" for f in supported_func) newlines.append(line) else: assert "gen_supported_ufuncs.py" not in line, ( f"Error: not expected to have 'gen_supported_ufuncs.py' at line {line} " f"of {file_to_update}" ) if keep_line: newlines.append(line) if args.check: with open(file_to_update, "r", encoding="utf-8") as file: oldlines = file.readlines() assert ( oldlines == newlines ), "List of supported functions is not up to date. Please run `make supported_functions`." else: with open(file_to_update, "w", encoding="utf-8") as file: file.writelines(newlines) if __name__ == "__main__": parser = argparse.ArgumentParser(description="Update list of supported functions in the doc") parser.add_argument("--check", action="store_true", help="flag to enable just checking mode") parser.add_argument("file_to_update", type=str, help=".md file to update") args = parser.parse_args() main(args.file_to_update)