-
Notifications
You must be signed in to change notification settings - Fork 5
/
bicep-typeless.py
53 lines (42 loc) · 1.5 KB
/
bicep-typeless.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
48
49
50
51
52
53
import os
import shutil
"""
The partner center does note allow bicep v2 at the mainTemplate level. Unfortunately,
if we want to type check our parameters, then we need to propagate this type checking from
mainTemplate all the way down. This script simply strips all type checking.
"""
def run() -> None:
biceps = os.listdir("bicep")
if os.path.exists("bicep-typeless"):
shutil.rmtree("bicep-typeless")
shutil.copytree("bicep", "bicep-typeless")
for fil in biceps:
if fil.endswith(".bicep"):
process_bicep(f"bicep/{fil}", f"bicep-typeless/{fil}")
def process_param(line: str) -> str:
toks = line.split()
if toks[2].endswith("_t"):
toks[2] = "object"
return " ".join(toks) + "\n"
def process_func(line: str) -> str:
toks = line.split()
for i in range(len(toks)):
if toks[i].endswith("_t"):
toks[i] = "object"
if toks[i].endswith("_t)"):
toks[i] = "object)"
return " ".join(toks) + "\n"
def process_bicep(input_path: str, output_path: str) -> None:
with open(input_path) as fr:
lines = fr.readlines()
with open(output_path, "w") as fw:
for line in lines:
if line.startswith("param") or line.startswith("output"):
fw.write(process_param(line))
elif line.startswith("import"):
continue
elif line.startswith("func "):
fw.write(process_func(line))
else:
fw.write(line)
run()