gen_yql_python_udf.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import sys
  2. TEMPLATE = """
  3. #include <@YQL_BASE_DIR@/udfs/common/python/python_udf/python_udf.h>
  4. #include <yql/essentials/public/udf/udf_registrator.h>
  5. #if @WITH_LIBRA@
  6. #include <yql/udfs/quality/libra/module/module.h>
  7. #endif
  8. using namespace NKikimr::NUdf;
  9. #ifdef BUILD_UDF
  10. #if @WITH_LIBRA@
  11. LIBRA_MODULE(TLibraModule, "Libra@MODULE_NAME@");
  12. #endif
  13. extern "C" UDF_API void Register(IRegistrator& registrator, ui32 flags) {
  14. RegisterYqlPythonUdf(registrator, flags, TStringBuf("@MODULE_NAME@"), TStringBuf("@PACKAGE_NAME@"), EPythonFlavor::@FLAVOR@);
  15. #if @WITH_LIBRA@
  16. RegisterHelper<TLibraModule>(registrator);
  17. #endif
  18. }
  19. extern "C" UDF_API ui32 AbiVersion() {
  20. return CurrentAbiVersion();
  21. }
  22. extern "C" UDF_API void SetBackTraceCallback(TBackTraceCallback callback) {
  23. SetBackTraceCallbackImpl(callback);
  24. }
  25. #endif
  26. """
  27. def main():
  28. assert len(sys.argv) == 7
  29. flavor, module_name, package_name, path, libra_flag, yql_base_dir = sys.argv[1:]
  30. with open(path, 'w') as f:
  31. f.write(
  32. TEMPLATE.strip()
  33. .replace('@MODULE_NAME@', module_name)
  34. .replace('@PACKAGE_NAME@', package_name)
  35. .replace('@FLAVOR@', flavor)
  36. .replace('@WITH_LIBRA@', libra_flag)
  37. .replace('@YQL_BASE_DIR@', yql_base_dir)
  38. )
  39. f.write('\n')
  40. if __name__ == "__main__":
  41. main()