Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/python/intern/bpy_interface.c')
-rw-r--r--source/blender/python/intern/bpy_interface.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index d72c2ccfcff..0b11ac639c7 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -80,6 +80,7 @@
/* Logging types to use anywhere in the Python modules. */
CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_CONTEXT, "bpy.context");
+CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_INTERFACE, "bpy.interface");
CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna");
/* for internal use, when starting and ending python scripts */
@@ -304,7 +305,6 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
{
#ifndef WITH_PYTHON_MODULE
PyThreadState *py_tstate = NULL;
- const char *py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL);
/* Needed for Python's initialization for portable Python installations.
* We could use #Py_SetPath, but this overrides Python's internal logic
@@ -321,8 +321,21 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
/* must run before python initializes */
PyImport_ExtendInittab(bpy_internal_modules);
- /* allow to use our own included python */
- PyC_SetHomePath(py_path_bundle);
+ /* Allow to use our own included Python. `py_path_bundle` may be NULL. */
+ {
+ const char *py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL);
+ if (py_path_bundle != NULL) {
+ PyC_SetHomePath(py_path_bundle);
+ }
+ else {
+ /* Common enough to use the system Python on Linux/Unix, warn on other systems. */
+# if defined(__APPLE__) || defined(_WIN32)
+ fprintf(stderr,
+ "Bundled Python not found and is expected on this platform "
+ "(the 'install' target may have not been built)\n");
+# endif
+ }
+ }
/* Without this the `sys.stdout` may be set to 'ascii'
* (it is on my system at least), where printing unicode values will raise
@@ -343,17 +356,16 @@ void BPY_python_start(bContext *C, int argc, const char **argv)
/* Initialize Python (also acquires lock). */
Py_Initialize();
- // PySys_SetArgv(argc, argv); /* broken in py3, not a huge deal */
- /* sigh, why do python guys not have a (char **) version anymore? */
+ /* We could convert to #wchar_t then pass to #PySys_SetArgv (or use #PyConfig in Python 3.8+).
+ * However this risks introducing subtle changes in encoding that are hard to track down.
+ *
+ * So rely on #PyC_UnicodeFromByte since it's a tried & true way of getting paths
+ * that include non `utf-8` compatible characters, see: T20021. */
{
- int i;
PyObject *py_argv = PyList_New(argc);
- for (i = 0; i < argc; i++) {
- /* should fix bug T20021 - utf path name problems, by replacing
- * PyUnicode_FromString, with this one */
+ for (int i = 0; i < argc; i++) {
PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
}
-
PySys_SetObject("argv", py_argv);
Py_DECREF(py_argv);
}