This repository was archived by the owner on Jan 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcode_gen.py
More file actions
52 lines (44 loc) · 1.33 KB
/
code_gen.py
File metadata and controls
52 lines (44 loc) · 1.33 KB
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
import os
import sys
sys.path.append(os.path.abspath(os.path.dirname(sys.argv[1])))
exec(f"import {os.path.basename(sys.argv[1]).split('.')[0]} as api")
sys.stdout = open(sys.argv[2], "w")
print(
"""// Auto-generated file
// #######################################################
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! DO NOT EDIT, USE ../scripts/code_gen.py TO UPDATE !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// #######################################################
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#ifdef DEF_PY11_ENUMS
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
#endif
namespace SHARPY {
"""
)
prev = 0
for cat, lst in api.api_categories.items():
print(f"enum {cat}Id : int {{")
for x in lst:
x = x + f" = {prev}" if x == lst[0] else x
print(f" {x.upper()},")
prev = f"{cat.upper()}_LAST"
print(f" {prev}")
print("};\n")
print(
"""#ifdef DEF_PY11_ENUMS
static void def_enums(py::module_ & m)
{"""
)
for cat, lst in api.api_categories.items():
print(f' py::enum_<{cat}Id>(m, "{cat}Id")')
for x in lst:
print(f' .value("{x.upper()}", {x.upper()})')
print(" .export_values();\n")
print("}\n#endif\n} // namespace SHARPY")
# Close the file
sys.stdout.close()