aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/gen_yql_python_udf.py
blob: 4f7d450d395d9e8070c62d5789130adc5191bb77 (plain) (blame)
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
54
55
56
import sys

TEMPLATE = """
#include <@YQL_PYTHON_DIR@/python_udf/python_udf.h>

#include <@YQL_BASE_DIR@/public/udf/udf_registrator.h>

#if @WITH_LIBRA@
#include <yql/udfs/quality/libra/module/module.h>
#endif

using namespace NKikimr::NUdf;

#ifdef BUILD_UDF

#if @WITH_LIBRA@
LIBRA_MODULE(TLibraModule, "Libra@MODULE_NAME@");
#endif

extern "C" UDF_API void Register(IRegistrator& registrator, ui32 flags) {
    RegisterYqlPythonUdf(registrator, flags, TStringBuf("@MODULE_NAME@"), TStringBuf("@PACKAGE_NAME@"), EPythonFlavor::@FLAVOR@);
#if @WITH_LIBRA@
    RegisterHelper<TLibraModule>(registrator);
#endif
}

extern "C" UDF_API ui32 AbiVersion() {
    return CurrentAbiVersion();
}

extern "C" UDF_API void SetBackTraceCallback(TBackTraceCallback callback) {
    SetBackTraceCallbackImpl(callback);
}

#endif
"""


def main():
    assert len(sys.argv) == 8
    flavor, module_name, package_name, path, libra_flag, yql_base_dir, yql_python_dir = sys.argv[1:]
    with open(path, 'w') as f:
        f.write(
            TEMPLATE.strip()
            .replace('@MODULE_NAME@', module_name)
            .replace('@PACKAGE_NAME@', package_name)
            .replace('@FLAVOR@', flavor)
            .replace('@WITH_LIBRA@', libra_flag)
            .replace('@YQL_BASE_DIR@', yql_base_dir)
            .replace('@YQL_PYTHON_DIR@', yql_python_dir)
        )
        f.write('\n')


if __name__ == "__main__":
    main()