-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_enums.py
38 lines (32 loc) · 1.06 KB
/
create_enums.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
import importlib
import re
from proto.enums import ProtoEnumMeta
from google.ads.googleads import client
enums_module = importlib.import_module(
f"google.ads.googleads.{client._DEFAULT_VERSION}.enums"
)
version_package = importlib.import_module(
f"google.ads.googleads.{client._DEFAULT_VERSION}"
)
lines = []
for enum in enums_module.__all__:
enum_class = getattr(version_package, enum)
for attr in dir(enum_class):
attr_val = getattr(enum_class, attr)
if isinstance(attr_val, ProtoEnumMeta):
lines.append(
f" {enum}: type[{client._DEFAULT_VERSION}.{enum}.{attr_val.__name__}]"
)
break
with open("google-stubs/ads/googleads/client.pyi") as f:
client_pyi = f.read()
lines.insert(0, "# Autogenerated enums")
lines.append(" # End of autogenerated enums")
client_pyi = re.sub(
"# Autogenerated enums.+# End of autogenerated enums",
"\n".join(lines),
client_pyi,
flags=re.DOTALL,
)
with open("google-stubs/ads/googleads/client.pyi", mode="w") as f:
f.write(client_pyi)