aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsay <say@yandex-team.ru>2022-05-04 13:34:25 +0300
committersay <say@yandex-team.ru>2022-05-04 13:34:25 +0300
commit692098a9726abf54da61f833036c8965e28e1f18 (patch)
tree245ba2921460cf2737ad558b22878b19196d1ca0
parent1af8bb8789fdb0ca2927ff097537916a7f297bb1 (diff)
downloadydb-692098a9726abf54da61f833036c8965e28e1f18.tar.gz
DEVTOOLSSUPPORT-18626: In venv directly call Py_BytesMain()
The arcadia main function (library/python/runtime_py3/main/main.c::pymain) calls Py_InitializeFromConfig() before going to the vanilla python Py_Main(). Py_InitializeFromConfig() overrides sys.prefix and sys.exec_prefix by default values ('/var/empty') and then import __res module (and importer.pxi as a part of it). importer.pxi::_init_venv() set a proper value to sys.prefix and sys.exec_prefix attributes. Py_Main() in turn also calls Py_InitializeFromConfig() and reset the sys attributes to their default values again. I don't know why it was not a problem in python 3.9 but in 3.10 it is. ref:0466de641f92d66c4f992ae12c02d8d58db397f6
-rw-r--r--library/python/runtime_py3/main/main.c4
-rw-r--r--library/python/runtime_py3/main/venv.cpp6
2 files changed, 10 insertions, 0 deletions
diff --git a/library/python/runtime_py3/main/main.c b/library/python/runtime_py3/main/main.c
index 3159800615..c2c90a3cf6 100644
--- a/library/python/runtime_py3/main/main.c
+++ b/library/python/runtime_py3/main/main.c
@@ -7,6 +7,7 @@
void Py_InitArgcArgv(int argc, wchar_t **argv);
char* GetPyMain();
+int IsYaIdeVenv();
static const char* env_entry_point = "Y_PYTHON_ENTRY_POINT";
static const char* env_bytes_warning = "Y_PYTHON_BYTES_WARNING";
@@ -74,6 +75,9 @@ static int RunModule(const char *modname)
}
static int pymain(int argc, char** argv) {
+ if (IsYaIdeVenv()) {
+ return Py_BytesMain(argc, argv);
+ }
PyStatus status = _PyRuntime_Initialize();
if (PyStatus_Exception(status)) {
Py_ExitStatusException(status);
diff --git a/library/python/runtime_py3/main/venv.cpp b/library/python/runtime_py3/main/venv.cpp
new file mode 100644
index 0000000000..b26611b918
--- /dev/null
+++ b/library/python/runtime_py3/main/venv.cpp
@@ -0,0 +1,6 @@
+#include <library/cpp/resource/resource.h>
+
+extern "C" int IsYaIdeVenv() {
+ TString dummy;
+ return NResource::FindExact("YA_IDE_VENV", &dummy);
+}