]> granicus.if.org Git - vim/commitdiff
patch 8.0.1451: difficult to set the python home directories properly v8.0.1451
authorBram Moolenaar <Bram@vim.org>
Wed, 31 Jan 2018 20:49:05 +0000 (21:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 31 Jan 2018 20:49:05 +0000 (21:49 +0100)
Problem:    It is difficult to set the python home directory properly for
            Python 2.7 and 3.5 since both use $PYTHONHOME.
Solution:   Add the 'pythonhome' and 'pythonthreehome' options. (Kazuki
            Sakamoto, closes #1266)

runtime/doc/options.txt
runtime/doc/quickref.txt
runtime/optwin.vim
src/if_python.c
src/if_python3.c
src/option.c
src/option.h
src/version.c

index f93308355990647dd6bc372fce3b1e59ae37115e..75e4f974168ac82e7f5fb64ed3e9e4cf3a7ff591 100644 (file)
@@ -5965,6 +5965,20 @@ A jump table for the options with a short description can be found at |Q_op|.
        DYNAMIC_PYTHON_DLL, which was specified at compile time.
        Environment variables are expanded |:set_env|.
        This option cannot be set from a |modeline| or in the |sandbox|, for
+       security reasons.
+
+                                               *'pythonhome'*
+'pythonhome'           string  (default "")
+                       global
+                       {not in Vi}
+                       {only available when compiled with the |+python/dyn|
+                       feature}
+       Specifies the name of the Python 2.x home directory. When 'pythonhome'
+       and the PYTHONHOME environment variable are not set, PYTHON_HOME,
+       which was specified at compile time, will be used for the Python 2.x
+       home directory.
+       Environment variables are expanded |:set_env|.
+       This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
 
                                                *'pythonthreedll'*
@@ -5977,6 +5991,20 @@ A jump table for the options with a short description can be found at |Q_op|.
        DYNAMIC_PYTHON3_DLL, which was specified at compile time.
        Environment variables are expanded |:set_env|.
        This option cannot be set from a |modeline| or in the |sandbox|, for
+       security reasons.
+
+                                               *'pythonthreehome'*
+'pythonthreehome'      string  (default "")
+                       global
+                       {not in Vi}
+                       {only available when compiled with the |+python3/dyn|
+                       feature}
+       Specifies the name of the Python 3 home directory. When
+       'pythonthreehome' and the PYTHONHOME environment variable are not set,
+       PYTHON3_HOME, which was specified at compile time, will be used for
+       the Python 3 home directory.
+       Environment variables are expanded |:set_env|.
+       This option cannot be set from a |modeline| or in the |sandbox|, for
        security reasons.
 
                                                *'pyxversion'* *'pyx'*
index 06ae663bfac1c568e5026a1d2844dab2f75fe85a..516a1daf56ca060173a3dcf8848ebda9aec44669 100644 (file)
@@ -839,7 +839,9 @@ Short explanation of each option:           *option-list*
 'prompt'         'prompt'  enable prompt in Ex mode
 'pumheight'      'ph'      maximum height of the popup menu
 'pythondll'                name of the Python 2 dynamic library
+'pythonhome'               name of the Python 2 home directory
 'pythonthreedll'           name of the Python 3 dynamic library
+'pythonthreehome'          name of the Python 3 home directory
 'pyxversion'     'pyx'     Python version used for pyx* commands
 'quoteescape'    'qe'      escape characters used in a string
 'readonly'       'ro'      disallow writing the buffer
index 74ebc9fd98c7820c8e3897c3d68ffbec21b7f181..a417295fdec086ffc84276f6635a00080eedb514 100644 (file)
@@ -1354,10 +1354,18 @@ if exists("&pythondll")
   call append("$", "pythondll\tname of the Python 2 dynamic library")
   call <SID>OptionG("pythondll", &pythondll)
 endif
+if exists("&pythonhome")
+  call append("$", "pythonhome\tname of the Python 2 home directory")
+  call <SID>OptionG("pythonhome", &pythonhome)
+endif
 if exists("&pythonthreedll")
   call append("$", "pythonthreedll\tname of the Python 3 dynamic library")
   call <SID>OptionG("pythonthreedll", &pythonthreedll)
 endif
+if exists("&pythonthreehome")
+  call append("$", "pythonthreehome\tname of the Python 3 home directory")
+  call <SID>OptionG("pythonthreehome", &pythonthreehome)
+endif
 if exists("&rubydll")
   call append("$", "rubydll\tname of the Ruby dynamic library")
   call <SID>OptionG("rubydll", &rubydll)
index f9fc5e1a5bb8c07d7a7369363186744b0e62f5a4..ab9c854b27e8566e368b5ee18f4016e59e985c75 100644 (file)
@@ -912,6 +912,8 @@ python_loaded(void)
 }
 #endif
 
+static char *py_home_buf = NULL;
+
     static int
 Python_Init(void)
 {
@@ -929,10 +931,15 @@ Python_Init(void)
        }
 #endif
 
+       if (*p_pyhome != NUL)
+       {
+           /* The string must not change later, make a copy in static memory. */
+           py_home_buf = (char *)vim_strsave(p_pyhome);
+           if (py_home_buf != NULL)
+               Py_SetPythonHome(py_home_buf);
+       }
 #ifdef PYTHON_HOME
-# ifdef DYNAMIC_PYTHON
-       if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
-# endif
+       else if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
            Py_SetPythonHome(PYTHON_HOME);
 #endif
 
index 7aa5f03e1dbcdbc1abd6ca5cd594f25bf566f793..02d913492cf279ae4046f3347f38aa260c73dbb0 100644 (file)
@@ -842,6 +842,8 @@ python3_loaded(void)
 }
 #endif
 
+static wchar_t *py_home_buf = NULL;
+
     static int
 Python3_Init(void)
 {
@@ -857,11 +859,18 @@ Python3_Init(void)
 
        init_structs();
 
+       if (*p_py3home != NUL)
+       {
+           size_t len = mbstowcs(NULL, (char *)p_py3home, 0) + 1;
 
+           /* The string must not change later, make a copy in static memory. */
+           py_home_buf = (wchar_t *)alloc(len * sizeof(wchar_t));
+           if (py_home_buf != NULL && mbstowcs(
+                           py_home_buf, (char *)p_py3home, len) != (size_t)-1)
+               Py_SetPythonHome(py_home_buf);
+       }
 #ifdef PYTHON3_HOME
-# ifdef DYNAMIC_PYTHON3
-       if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
-# endif
+       else if (mch_getenv((char_u *)"PYTHONHOME") == NULL)
            Py_SetPythonHome(PYTHON3_HOME);
 #endif
 
index 08fb789dad19b7c12330415ccc9ea7bd2bd25215..ce5436996826b85fae1a5fac926ec5e130ef448a 100644 (file)
@@ -2246,6 +2246,15 @@ static struct vimoption options[] =
 #else
                            (char_u *)NULL, PV_NONE,
                            {(char_u *)NULL, (char_u *)0L}
+#endif
+                           SCRIPTID_INIT},
+    {"pythonthreehome", NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
+#if defined(FEAT_PYTHON3)
+                           (char_u *)&p_py3home, PV_NONE,
+                           {(char_u *)"", (char_u *)0L}
+#else
+                           (char_u *)NULL, PV_NONE,
+                           {(char_u *)NULL, (char_u *)0L}
 #endif
                            SCRIPTID_INIT},
     {"pythondll",   NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
@@ -2255,6 +2264,15 @@ static struct vimoption options[] =
 #else
                            (char_u *)NULL, PV_NONE,
                            {(char_u *)NULL, (char_u *)0L}
+#endif
+                           SCRIPTID_INIT},
+    {"pythonhome",  NULL,   P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
+#if defined(FEAT_PYTHON)
+                           (char_u *)&p_pyhome, PV_NONE,
+                           {(char_u *)"", (char_u *)0L}
+#else
+                           (char_u *)NULL, PV_NONE,
+                           {(char_u *)NULL, (char_u *)0L}
 #endif
                            SCRIPTID_INIT},
     {"pyxversion", "pyx",   P_NUM|P_VI_DEF|P_SECURE,
index c9fa4d35fc69284520d1af4734187f1d3334b032..21be3a39f176ab069897dc3abe131ab205d58af0 100644 (file)
@@ -696,9 +696,15 @@ EXTERN char_u      *p_perldll;     /* 'perldll' */
 #if defined(DYNAMIC_PYTHON3)
 EXTERN char_u  *p_py3dll;      /* 'pythonthreedll' */
 #endif
+#ifdef FEAT_PYTHON3
+EXTERN char_u  *p_py3home;     /* 'pythonthreehome' */
+#endif
 #if defined(DYNAMIC_PYTHON)
 EXTERN char_u  *p_pydll;       /* 'pythondll' */
 #endif
+#ifdef FEAT_PYTHON
+EXTERN char_u  *p_pyhome;      /* 'pythonhome' */
+#endif
 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
 EXTERN long    p_pyx;          /* 'pyxversion' */
 #endif
index ea5dbefc003623ed7cb9f54a3b113416aa9c705b..e01f2be796edf1837bf209309614a75b69ecde1c 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1451,
 /**/
     1450,
 /**/