diff options
author | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:00:23 +0300 |
---|---|---|
committer | imunkin <imunkin@yandex-team.com> | 2024-11-08 10:12:13 +0300 |
commit | a784a2f943d6e15caa6241e2e96d80aac6dbf375 (patch) | |
tree | 05f1e5366c916b988a8afb75bdab8ddeee0f6e6d /yql/essentials/udfs/common/python/main_py3 | |
parent | d70137a7b530ccaa52834274913bbb5a3d1ca06e (diff) | |
download | ydb-a784a2f943d6e15caa6241e2e96d80aac6dbf375.tar.gz |
Move yql/udfs/common/ to /yql/essentials YQL-19206
Except the following directories:
* clickhouse/client
* datetime
* knn
* roaring
commit_hash:c7da95636144d28db109d6b17ddc762e9bacb59f
Diffstat (limited to 'yql/essentials/udfs/common/python/main_py3')
4 files changed, 84 insertions, 0 deletions
diff --git a/yql/essentials/udfs/common/python/main_py3/__main__.pyx b/yql/essentials/udfs/common/python/main_py3/__main__.pyx new file mode 100644 index 00000000000..6f4ca943584 --- /dev/null +++ b/yql/essentials/udfs/common/python/main_py3/__main__.pyx @@ -0,0 +1,50 @@ +import os +import runpy +import importlib + +import __res + + +cdef env_entry_point = 'Y_PYTHON_ENTRY_POINT' + + +cdef extern from 'main.h': + pass + + +def find_pymain(): + py_main = __res.find('PY_MAIN') + + if isinstance(py_main, bytes): + py_main = py_main.decode('utf8') + + if isinstance(py_main, unicode): + return py_main + + return None + + +def run_main(): + entry_point = os.environ.pop(env_entry_point, None) + + if entry_point is None: + entry_point = find_pymain() + + if entry_point is None: + raise RuntimeError('No entry point found') + + module_name, colon, func_name = entry_point.partition(':') + + if not colon: + runpy._run_module_as_main(module_name, alter_argv=False) + return + + if not module_name: + module_name = 'library.python.runtime_py3.entry_points' + + module = importlib.import_module(module_name) + func = getattr(module, func_name) + func() + + +run_main() diff --git a/yql/essentials/udfs/common/python/main_py3/include/main.h b/yql/essentials/udfs/common/python/main_py3/include/main.h new file mode 100644 index 00000000000..c96402004e3 --- /dev/null +++ b/yql/essentials/udfs/common/python/main_py3/include/main.h @@ -0,0 +1,12 @@ +#pragma once +#include <util/system/compiler.h> + +#ifdef __cplusplus +extern "C" { +#endif +Y_PUBLIC +int RunPython(int argc, char** argv); +#ifdef __cplusplus +} +#endif + diff --git a/yql/essentials/udfs/common/python/main_py3/main.cpp b/yql/essentials/udfs/common/python/main_py3/main.cpp new file mode 100644 index 00000000000..edc3c89ca5b --- /dev/null +++ b/yql/essentials/udfs/common/python/main_py3/main.cpp @@ -0,0 +1,9 @@ +#include "main.h" + +extern "C" +int RunPythonImpl(int argc, char** argv); + +extern "C" +int RunPython(int argc, char** argv) { + return RunPythonImpl(argc, argv); +} diff --git a/yql/essentials/udfs/common/python/main_py3/ya.make b/yql/essentials/udfs/common/python/main_py3/ya.make new file mode 100644 index 00000000000..cc13fb77e4c --- /dev/null +++ b/yql/essentials/udfs/common/python/main_py3/ya.make @@ -0,0 +1,13 @@ +LIBRARY() + +USE_PYTHON3() + +ADDINCL( + yql/essentials/udfs/common/python/main_py3/include +) + +SRCS(GLOBAL main.cpp) + +BUILDWITH_CYTHON_C(__main__.pyx --embed=RunPythonImpl) + +END() |