]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: drop python2 support 34635/head
authorKefu Chai <kchai@redhat.com>
Mon, 20 Apr 2020 10:29:49 +0000 (18:29 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 20 Apr 2020 15:39:20 +0000 (23:39 +0800)
just stop checking for `PY_MAJOR_VERSION`, since we've moved to python3.
no need to be python2 compatible.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/PyModule.cc
src/mgr/PyModule.h
src/mgr/PyModuleRegistry.cc

index 6ebf2b9ad2be02fab2c27cc86f81da7feca4ac77..3f3fbbd53d5fd6ec9b434aa7afbb3cbfaa1af80a 100644 (file)
@@ -121,7 +121,6 @@ namespace {
     {nullptr, nullptr, 0, nullptr}
   };
 
-#if PY_MAJOR_VERSION >= 3
   static PyModuleDef ceph_logger_module = {
     PyModuleDef_HEAD_INIT,
     "ceph_logger",
@@ -129,7 +128,6 @@ namespace {
     -1,
     log_methods,
   };
-#endif
 }
 
 PyModuleConfig::PyModuleConfig() = default;  
@@ -252,7 +250,6 @@ std::string PyModule::get_site_packages()
   return site_packages.str();
 }
 
-#if PY_MAJOR_VERSION >= 3
 PyObject* PyModule::init_ceph_logger()
 {
   auto py_logger = PyModule_Create(&ceph_logger_module);
@@ -260,25 +257,12 @@ PyObject* PyModule::init_ceph_logger()
   PySys_SetObject("stdout", py_logger);
   return py_logger;
 }
-#else
-void PyModule::init_ceph_logger()
-{
-  auto py_logger = Py_InitModule("ceph_logger", log_methods);
-  PySys_SetObject(const_cast<char*>("stderr"), py_logger);
-  PySys_SetObject(const_cast<char*>("stdout"), py_logger);
-}
-#endif
 
-#if PY_MAJOR_VERSION >= 3
 PyObject* PyModule::init_ceph_module()
-#else
-void PyModule::init_ceph_module()
-#endif
 {
   static PyMethodDef module_methods[] = {
     {nullptr, nullptr, 0, nullptr}
   };
-#if PY_MAJOR_VERSION >= 3
   static PyModuleDef ceph_module_def = {
     PyModuleDef_HEAD_INIT,
     "ceph_module",
@@ -291,9 +275,6 @@ void PyModule::init_ceph_module()
     nullptr
   };
   PyObject *ceph_module = PyModule_Create(&ceph_module_def);
-#else
-  PyObject *ceph_module = Py_InitModule("ceph_module", module_methods);
-#endif
   ceph_assert(ceph_module != nullptr);
   std::map<const char*, PyTypeObject*> classes{
     {{"BaseMgrModule", &BaseMgrModuleType},
@@ -311,9 +292,7 @@ void PyModule::init_ceph_module()
 
     PyModule_AddObject(ceph_module, name, (PyObject *)type);
   }
-#if PY_MAJOR_VERSION >= 3
   return ceph_module;
-#endif
 }
 
 int PyModule::load(PyThreadState *pMainThreadState)
@@ -333,26 +312,15 @@ int PyModule::load(PyThreadState *pMainThreadState)
       pMyThreadState.set(thread_state);
       // Some python modules do not cope with an unpopulated argv, so lets
       // fake one.  This step also picks up site-packages into sys.path.
-#if PY_MAJOR_VERSION >= 3
       const wchar_t *argv[] = {L"ceph-mgr"};
       PySys_SetArgv(1, (wchar_t**)argv);
-#else
-      const char *argv[] = {"ceph-mgr"};
-      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());
-#if PY_MAJOR_VERSION >= 3
       wstring sys_path(Py_GetPath() + wstring(begin(paths), end(paths)));
       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);
-      PySys_SetPath(const_cast<char*>(sys_path.c_str()));
-      dout(10) << "Computed sys.path '" << sys_path << "'" << dendl;
-#endif
     }
   }
   // Environment is all good, import the external module
index 6d555a81a2deb1c06a91f768d3b506ad4f6392c0..72a3ef491fa27666b737dfdfff67a5e8fd61bb30 100644 (file)
@@ -109,13 +109,8 @@ public:
     const std::string& value);
 
   int load(PyThreadState *pMainThreadState);
-#if PY_MAJOR_VERSION >= 3
   static PyObject* init_ceph_logger();
   static PyObject* init_ceph_module();
-#else
-  static void init_ceph_logger();
-  static void init_ceph_module();
-#endif
 
   void set_enabled(const bool enabled_)
   {
index 660774004a6a05525fe1e9fe2a603253a55506f1..440f7c8bafc1e817e9b6ae532fe8a71d1180dcb3 100644 (file)
@@ -41,13 +41,9 @@ void PyModuleRegistry::init()
   std::lock_guard locker(lock);
 
   // Set up global python interpreter
-#if PY_MAJOR_VERSION >= 3
 #define WCHAR(s) L ## #s
   Py_SetProgramName(const_cast<wchar_t*>(WCHAR(MGR_PYTHON_EXECUTABLE)));
 #undef WCHAR
-#else
-  Py_SetProgramName(const_cast<char*>(MGR_PYTHON_EXECUTABLE));
-#endif
   // Add more modules
   if (g_conf().get_val<bool>("daemonize")) {
     PyImport_AppendInittab("ceph_logger", PyModule::init_ceph_logger);