yql_python_udf.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_base_dir = unit.get('YQL_BASE_DIR')
  20. yql_python_dir = unit.get('YQL_PYTHON_DIR')
  21. if not yql_python_dir:
  22. yql_python_dir = '/'.join([yql_base_dir, 'udfs/common/python'])
  23. unit.onyql_abi_version(['2', '27', '0'])
  24. unit.onpeerdir(['/'.join([yql_base_dir, '/udfs/common/python/python_udf'])])
  25. unit.onpeerdir(['yql/essentials/public/udf'])
  26. if add_libra_modules:
  27. unit.onpeerdir(['quality/user_sessions/libra_arc/noyql'])
  28. unit.onpeerdir(['yql/udfs/quality/libra/module'])
  29. if use_arcadia_python:
  30. flavor = 'Arcadia'
  31. unit.onpeerdir(
  32. ['library/python/runtime', '/'.join([yql_python_dir, '/main'])]
  33. if not py3
  34. else ['library/python/runtime_py3', '/'.join([yql_base_dir, '/udfs/common/python/main_py3'])]
  35. )
  36. else:
  37. flavor = 'System'
  38. output_includes = [
  39. '/'.join([yql_base_dir, '/udfs/common/python/python_udf/python_udf.h']),
  40. 'yql/essentials/public/udf/udf_registrator.h',
  41. ]
  42. if add_libra_modules:
  43. output_includes.append('yql/udfs/quality/libra/module/module.h')
  44. path = name + '.yql_python_udf.cpp'
  45. libra_flag = '1' if add_libra_modules else '0'
  46. unit.onrun_python3(
  47. [
  48. 'build/scripts/gen_yql_python_udf.py',
  49. flavor,
  50. name,
  51. resource_name,
  52. path,
  53. libra_flag,
  54. yql_base_dir,
  55. 'OUT',
  56. path,
  57. 'OUTPUT_INCLUDES',
  58. ]
  59. + output_includes
  60. )