yql_python_udf.py 1.8 KB

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