2023-09-27 08:01:38 -06:00
|
|
|
import subprocess
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--check", action="store_true")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-09-28 01:55:47 -06:00
|
|
|
output = subprocess.check_output(["text-generation-launcher", "--help"]).decode(
|
|
|
|
"utf-8"
|
|
|
|
)
|
2023-10-04 04:57:21 -06:00
|
|
|
|
2023-09-28 09:30:36 -06:00
|
|
|
wrap_code_blocks_flag = "<!-- WRAP CODE BLOCKS -->"
|
2023-10-04 04:57:21 -06:00
|
|
|
final_doc = f"# Text-generation-launcher arguments\n\n{wrap_code_blocks_flag}\n\n"
|
|
|
|
|
|
|
|
lines = output.split("\n")
|
|
|
|
|
|
|
|
header = ""
|
|
|
|
block = []
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith(" -") or line.startswith(" -"):
|
2023-10-05 06:40:35 -06:00
|
|
|
rendered_block = "\n".join(block)
|
2023-10-04 04:57:21 -06:00
|
|
|
if header:
|
|
|
|
final_doc += f"## {header}\n```shell\n{rendered_block}\n```\n"
|
|
|
|
else:
|
|
|
|
final_doc += f"```shell\n{rendered_block}\n```\n"
|
|
|
|
block = []
|
|
|
|
tokens = line.split("<")
|
2023-10-05 06:40:35 -06:00
|
|
|
if len(tokens) > 1:
|
2023-10-04 04:57:21 -06:00
|
|
|
header = tokens[-1][:-1]
|
|
|
|
else:
|
|
|
|
header = line.split("--")[-1]
|
|
|
|
header = header.upper().replace("-", "_")
|
|
|
|
|
|
|
|
block.append(line)
|
|
|
|
|
2023-10-05 06:40:35 -06:00
|
|
|
rendered_block = "\n".join(block)
|
2023-10-04 04:57:21 -06:00
|
|
|
final_doc += f"## {header}\n```shell\n{rendered_block}\n```\n"
|
|
|
|
block = []
|
2023-09-27 08:01:38 -06:00
|
|
|
|
|
|
|
filename = "docs/source/basic_tutorials/launcher.md"
|
|
|
|
if args.check:
|
|
|
|
with open(filename, "r") as f:
|
|
|
|
doc = f.read()
|
|
|
|
if doc != final_doc:
|
|
|
|
tmp = "launcher.md"
|
|
|
|
with open(tmp, "w") as g:
|
|
|
|
g.write(final_doc)
|
2023-09-28 01:55:47 -06:00
|
|
|
diff = subprocess.run(
|
|
|
|
["diff", tmp, filename], capture_output=True
|
|
|
|
).stdout.decode("utf-8")
|
2023-09-27 08:01:38 -06:00
|
|
|
print(diff)
|
2023-09-28 01:55:47 -06:00
|
|
|
raise Exception(
|
|
|
|
"Doc is not up-to-date, run `python update_doc.py` in order to update it"
|
|
|
|
)
|
2023-09-27 08:01:38 -06:00
|
|
|
else:
|
|
|
|
with open(filename, "w") as f:
|
|
|
|
f.write(final_doc)
|
|
|
|
|
2023-09-28 01:55:47 -06:00
|
|
|
|
2023-09-27 08:01:38 -06:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|