yql_python_udf.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from _common import sort_by_keywords
  2. import ymake
  3. def get_or_default(kv, name, default):
  4. if name in kv:
  5. return kv[name][0]
  6. return default
  7. def onregister_yql_python_udf(unit, *args):
  8. flat, kv = sort_by_keywords({'NAME': 1, 'RESOURCE_NAME': 1, 'ADD_LIBRA_MODULES': 1}, args)
  9. assert len(flat) == 0
  10. name = get_or_default(kv, 'NAME', 'CustomPython')
  11. resource_name = get_or_default(kv, 'RESOURCE_NAME', name)
  12. add_libra_modules = get_or_default(kv, 'ADD_LIBRA_MODULES', 'no') == 'yes'
  13. use_arcadia_python = unit.get('USE_ARCADIA_PYTHON') == 'yes'
  14. py3 = unit.get('PYTHON3') == 'yes'
  15. if unit.get('OPENSOURCE'):
  16. if add_libra_modules:
  17. ymake.report_configure_error('Libra modules are not supported in opensource python UDFs')
  18. add_libra_modules = False
  19. yql_python_dir = unit.get('YQL_PYTHON_DIR')
  20. if not yql_python_dir:
  21. yql_python_dir = 'yql/essentials/udfs/common/python'
  22. unit.onyql_abi_version(['2', '27', '0'])
  23. unit.onpeerdir(['yql/essentials/udfs/common/python/python_udf'])
  24. unit.onpeerdir(['yql/essentials/public/udf'])
  25. if add_libra_modules:
  26. unit.onpeerdir(['quality/user_sessions/libra_arc/noyql'])
  27. unit.onpeerdir(['yql/udfs/quality/libra/module'])
  28. if use_arcadia_python:
  29. flavor = 'Arcadia'
  30. unit.onpeerdir(
  31. ['library/python/runtime', '/'.join([yql_python_dir, '/main'])]
  32. if not py3
  33. else ['library/python/runtime_py3', 'yql/essentials/udfs/common/python/main_py3']
  34. )
  35. else:
  36. flavor = 'System'
  37. output_includes = [
  38. 'yql/essentials/udfs/common/python/python_udf/python_udf.h',
  39. 'yql/essentials/public/udf/udf_registrator.h',
  40. ]
  41. if add_libra_modules:
  42. output_includes.append('yql/udfs/quality/libra/module/module.h')
  43. path = name + '.yql_python_udf.cpp'
  44. libra_flag = '1' if add_libra_modules else '0'
  45. unit.onrun_python3(
  46. [
  47. 'build/scripts/gen_yql_python_udf.py',
  48. flavor,
  49. name,
  50. resource_name,
  51. path,
  52. libra_flag,
  53. 'OUT',
  54. path,
  55. 'OUTPUT_INCLUDES',
  56. ]
  57. + output_includes
  58. )