-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_api_setup.py
47 lines (33 loc) · 1.34 KB
/
generate_api_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import subprocess
# Specification path
INPUT_SPEC = "specific-provisioner/interface-specification.yml"
# Code output path
PATH_FOLDER = "specific-provisioner/src/"
# Path of the main program related to the API
PATH_MAIN = f"{PATH_FOLDER}/main.py"
# Path of the models program related to the API
PATH_MODELS = f"{PATH_FOLDER}/models.py"
init_message = f"""
SETTING PARAMETERS:
Specification_Path = {INPUT_SPEC}
Output_folder_Path = {PATH_FOLDER}
"""
print(init_message)
# Securely generating API code structure using subprocess
subprocess.run(["fastapi-codegen", "--input", INPUT_SPEC, "--output", PATH_FOLDER], check=True)
print("Generating the API code structure.........")
print("______________________________________________________________________________\n")
# Install pre-commit hooks
print("Installing 'pre-commit'.......")
cwd1 = os.getcwd()
os.chdir(f"{cwd1}/specific-provisioner")
subprocess.run(["pre-commit", "install"], check=True)
print("______________________________________________________________________________\n")
# Add noqa for autogenerated code
print("Adding 'noqa' for autogenerated code......")
cwd2 = os.getcwd()
os.chdir(f"{cwd2}/src")
subprocess.run(["ruff", ".", "--add-noqa"], check=True)
print("______________________________________________________________________________\n")
print("\n\n SETUP COMPLETED!\n")