]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/PyModule: put mgr_module_path before Py_GetPath() 40753/head
authorKefu Chai <kchai@redhat.com>
Tue, 30 Mar 2021 18:32:38 +0000 (02:32 +0800)
committerNathan Cutler <ncutler@suse.com>
Wed, 28 Apr 2021 07:12:35 +0000 (09:12 +0200)
pip comes with _vendor/progress. so there is chance to import the vendored
version of "progress" module instead of the "progress" mgr module, and
fail to import the latter.

in this change, the order of paths are rearranged so the configured
`mgr_module_path` is put before the return value of `Py_GetPath()`.

Fixes: https://tracker.ceph.com/issues/50058
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 8638f526a9d04c3dfd758073980d709165070336)

Conflicts:
src/mgr/PyModule.cc
- nautilus has a preprocessor directive "#if PY_MAJOR_VERSION >= 3"
  which is not there in master
- since we still need to support python2, apply the same change to
  the #else branch at line 351

src/mgr/PyModule.cc

index 8c8859ae5a0c96217836d0ece6d5c76571fdd0f3..7a3787f8e08fb0e9af6781881ba1c6432b432d88 100644 (file)
@@ -340,15 +340,15 @@ int PyModule::load(PyThreadState *pMainThreadState)
       PySys_SetArgv(1, (char**)argv);
 #endif
       // Configure sys.path to include mgr_module_path
-      string paths = (":" + g_conf().get_val<std::string>("mgr_module_path") +
-                     ":" + get_site_packages());
+      string paths = (g_conf().get_val<std::string>("mgr_module_path") + ":" +
+                      get_site_packages() + ':');
 #if PY_MAJOR_VERSION >= 3
-      wstring sys_path(Py_GetPath() + wstring(begin(paths), end(paths)));
+      wstring sys_path(wstring(begin(paths), end(paths)) + Py_GetPath());
       PySys_SetPath(const_cast<wchar_t*>(sys_path.c_str()));
       dout(10) << "Computed sys.path '"
               << string(begin(sys_path), end(sys_path)) << "'" << dendl;
 #else
-      string sys_path(Py_GetPath() + paths);
+      string sys_path(paths + Py_GetPath());
       PySys_SetPath(const_cast<char*>(sys_path.c_str()));
       dout(10) << "Computed sys.path '" << sys_path << "'" << dendl;
 #endif