yql_python_udf.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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', '14', '0'])
  15. unit.onpeerdir(['yql/udfs/common/python/python_udf'])
  16. unit.onpeerdir(['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',
  24. 'yql/udfs/common/python/main'
  25. ] if not py3 else [
  26. 'library/python/runtime_py3',
  27. 'yql/udfs/common/python/main_py3'
  28. ])
  29. else:
  30. flavor = 'System'
  31. output_includes = [
  32. 'yql/udfs/common/python/python_udf/python_udf.h',
  33. 'ydb/library/yql/public/udf/udf_registrator.h',
  34. ]
  35. if add_libra_modules:
  36. output_includes.append('yql/udfs/quality/libra/module/module.h')
  37. path = name + '.yql_python_udf.cpp'
  38. libra_flag = '1' if add_libra_modules else '0'
  39. unit.onpython([
  40. 'build/scripts/gen_yql_python_udf.py',
  41. flavor, name, resource_name, path, libra_flag,
  42. 'OUT', path,
  43. 'OUTPUT_INCLUDES',
  44. ] + output_includes
  45. )