forked from DIRACGrid/diracx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-client.py
executable file
·44 lines (33 loc) · 1.13 KB
/
generate-client.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
#!/usr/bin/env python
import subprocess
import tempfile
from pathlib import Path
from fastapi.testclient import TestClient
import diracx.routers
def main():
c = TestClient(diracx.routers.app)
r = c.get("/openapi.json")
r.raise_for_status()
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
openapi_spec = tmpdir / "openapi.json"
openapi_spec.write_text(r.text)
output_folder = Path(__file__).parent / "src" / "diracx"
cmd = [
"autorest",
"--python",
f"--input-file={openapi_spec}",
"--models-mode=msrest",
"--namespace=client",
f"--output-folder={output_folder}",
]
# This is required to be able to work offline
cmd += ["--use=@autorest/[email protected]"]
subprocess.run(cmd, check=True)
cmd = ["pre-commit", "run", "--all-files"]
print("Running pre-commit...")
subprocess.run(cmd, check=False, cwd=Path(__file__).parent)
print("Re-running pre-commit...")
subprocess.run(cmd, check=True, cwd=Path(__file__).parent)
if __name__ == "__main__":
main()