[glom/glom-1-28] glom_python_call(): Use gi.require_version() to get a specific Gda version.



commit 70a5c67c60b820b06ecd5f087185493b2c507f04
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Feb 29 13:09:29 2016 +0100

    glom_python_call(): Use gi.require_version() to get a specific Gda version.

 glom/python_embed/glom_python.cc |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/glom/python_embed/glom_python.cc b/glom/python_embed/glom_python.cc
index 2b9b43b..633a72b 100644
--- a/glom/python_embed/glom_python.cc
+++ b/glom/python_embed/glom_python.cc
@@ -164,6 +164,8 @@ bool gda_python_module_is_available()
 {
   //TODO: How can we requests a specific version to avoid confusion
   //between the parallel-installed Gda-5.0 and Gda-6.0 APIs?
+  //In a python script we would do this, but how do we do it with the boost::python API?
+  //  gi.require_version('Gda', '5.0')
   const char* name = "gi.repository.Gda";
   const boost::python::object module_glom = import_module(name);
   return module_glom != boost::python::object();
@@ -211,6 +213,8 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
   //between the parallel-installed Gda-5.0 and Gda-6.0 APIs?
   func_def = "def " + func_signature + ":\n"
   "  import glom_" GLOM_ABI_VERSION_UNDERLINED "\n"
+  "  import gi\n"
+  "  gi.require_version('Gda', '5.0')\n"
   "  from gi.repository import Gda\n" + func_def;
 
   //We did this in main(): Py_Initialize();
@@ -262,15 +266,19 @@ static boost::python::object glom_python_call(Field::glom_field_type result_type
     return boost::python::object(); // don't crash
   }
 
-  //TODO: Is this necessary?
-  //TODO: How can we requests a specific version to avoid confusion
-  //between the parallel-installed Gda-5.0 and Gda-6.0 APIs?
-  boost::python::object module_gda = import_module("gi.repository.Gda");
-  if(module_gda == boost::python::object())
-  {
-    g_warning("Could not import python gi.repository.Gda module.");
-    return boost::python::object();
-  }
+  //This doesn't seem to be necessary,
+  //because we do an import in the python script anyway.
+  //And we don't want to do this because the boost::python::import() API
+  //doesn't let us first say:
+  //  gi.require_version('Gda', '5.0')
+  //to specify a particular parallel-installable version.
+  //(There are 5.0 and 6.0 versions of Gda, for instance.)
+  //boost::python::object module_gda = import_module("gi.repository.Gda");
+  //if(module_gda == boost::python::object())
+  //{
+  //  g_warning("Could not import python gi.repository.Gda module.");
+  //  return boost::python::object();
+  //}
 
   //Create the function definition:
   /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]