promptflow
60 строк · 2.1 Кб
1import argparse
2from pathlib import Path
3from jinja2 import Environment, FileSystemLoader
4
5from ghactions_driver.readme_parse import readme_parser
6from ghactions_driver.readme_step import ReadmeStepsManage
7
8
9def comment_pytest(full_text: str):
10# separate full_text into lines, group them by start with pytest or not
11full_text_lines = full_text.split("\n")
12full_text_pytest = []
13full_text_no_pytest = []
14for line in full_text_lines:
15if line.strip().startswith("python -m unittest"):
16full_text_pytest.append(line)
17else:
18full_text_no_pytest.append(line)
19return "\n".join(full_text_no_pytest), "\n".join(full_text_pytest)
20
21
22def write_readme_shell(readme_path: str, output_folder: str):
23full_text = readme_parser(readme_path)
24full_text, full_text_pytest = comment_pytest(full_text)
25Path(ReadmeStepsManage.git_base_dir())
26bash_script_path = (
27Path(ReadmeStepsManage.git_base_dir()) / output_folder / "bash_script.sh"
28)
29bash_script_backup = (
30Path(ReadmeStepsManage.git_base_dir()) / output_folder / "bash_script_pytest.sh"
31)
32template_env = Environment(
33loader=FileSystemLoader(
34Path(ReadmeStepsManage.git_base_dir())
35/ "scripts/readme/ghactions_driver/bash_script"
36)
37)
38bash_script_template = template_env.get_template("bash_script.sh.jinja2")
39with open(bash_script_path, "w") as f:
40f.write(bash_script_template.render({"command": full_text}))
41if full_text_pytest != "":
42with open(bash_script_backup, "w") as f:
43f.write(bash_script_template.render({"command": full_text_pytest}))
44
45
46if __name__ == "__main__":
47# setup argparse
48parser = argparse.ArgumentParser()
49parser.add_argument(
50"-f",
51"--readme-file",
52help="Input README.md example 'examples/flows/standard/basic/README.md'",
53)
54parser.add_argument(
55"-o",
56"--output-folder",
57help="Output folder for bash_script.sh example 'examples/flows/standard/basic/'",
58)
59args = parser.parse_args()
60write_readme_shell(args.readme_file, args.output_folder)
61