aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/gen_py_reg.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/gen_py_reg.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/gen_py_reg.py')
-rw-r--r--build/scripts/gen_py_reg.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/build/scripts/gen_py_reg.py b/build/scripts/gen_py_reg.py
new file mode 100644
index 0000000000..1560135ae8
--- /dev/null
+++ b/build/scripts/gen_py_reg.py
@@ -0,0 +1,32 @@
+import sys
+
+template = '''
+extern "C" void PyImport_AppendInittab(const char* name, void (*fn)(void));
+extern "C" void {1}();
+
+namespace {
+ struct TRegistrar {
+ inline TRegistrar() {
+ PyImport_AppendInittab("{0}", {1});
+ }
+ } REG;
+}
+'''
+
+
+def mangle(name):
+ if '.' not in name:
+ return name
+ return ''.join('{}{}'.format(len(s), s) for s in name.split('.'))
+
+if __name__ == '__main__':
+ if len(sys.argv) != 3:
+ print >>sys.stderr, 'Usage: <path/to/gen_py_reg.py> <python_module_name> <output_file>'
+ print >>sys.stderr, 'Passed: ' + ' '.join(sys.argv)
+ sys.exit(1)
+
+ with open(sys.argv[2], 'w') as f:
+ modname = sys.argv[1]
+ initname = 'init' + mangle(modname)
+ code = template.replace('{0}', modname).replace('{1}', initname)
+ f.write(code)