Ticket 737: Add python3 support
authorAnders Henja <anders@henjab.se>
Fri, 30 Mar 2018 15:56:13 +0000 (17:56 +0200)
committerAnders Henja <anders@henjab.se>
Fri, 30 Mar 2018 15:56:13 +0000 (17:56 +0200)
pybeamb/pybbtopography.c
pybeamb/pybbtopography.h
pybeamb/pybeamblockage.c
pybeamb/pybeamblockage.h
pybeamb/pybeamblockagemap.c
pybeamb/pybeamblockagemap.h
test/pytest/PyBBTopographyTest.py
test/pytest/PyBeamBlockageMapTest.py
test/pytest/PyBeamBlockageTest.py
test/pytest/beamb_quality_plugin_test.py
tools/run_python_script.sh

index 4b22483..43cb074 100644 (file)
@@ -22,6 +22,7 @@ along with beamb.  If not, see <http://www.gnu.org/licenses/>.
  * @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
  * @date 2011-11-16
  */
+#include "pybeamb_compat.h"
 #include "Python.h"
 #include <math.h>
 #include <stdio.h>
@@ -330,45 +331,37 @@ static struct PyMethodDef _pybbtopography_methods[] =
 /**
  * Returns the specified attribute in the beam blockage
  */
-static PyObject* _pybbtopography_getattr(PyBBTopography* self, char* name)
+static PyObject* _pybbtopography_getattro(PyBBTopography* self, PyObject* name)
 {
-  PyObject* res = NULL;
-  if (strcmp("nodata", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("nodata", name) == 0) {
     return PyFloat_FromDouble(BBTopography_getNodata(self->topo));
-  } else if (strcmp("ulxmap", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ulxmap", name) == 0) {
     return PyFloat_FromDouble(BBTopography_getUlxmap(self->topo));
-  } else if (strcmp("ulymap", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ulymap", name) == 0) {
     return PyFloat_FromDouble(BBTopography_getUlymap(self->topo));
-  } else if (strcmp("xdim", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("xdim", name) == 0) {
     return PyFloat_FromDouble(BBTopography_getXDim(self->topo));
-  } else if (strcmp("ydim", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ydim", name) == 0) {
     return PyFloat_FromDouble(BBTopography_getYDim(self->topo));
-  } else if (strcmp("ncols", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ncols", name) == 0) {
     return PyLong_FromLong(BBTopography_getNcols(self->topo));
-  } else if (strcmp("nrows", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("nrows", name) == 0) {
     return PyLong_FromLong(BBTopography_getNrows(self->topo));
   }
-
-  res = Py_FindMethod(_pybbtopography_methods, (PyObject*) self, name);
-  if (res)
-    return res;
-
-  PyErr_Clear();
-  PyErr_SetString(PyExc_AttributeError, name);
-  return NULL;
+  return PyObject_GenericGetAttr((PyObject*)self, name);
 }
 
 /**
  * Returns the specified attribute in the polar volume
  */
-static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* val)
+static int _pybbtopography_setattro(PyBBTopography* self, PyObject* name, PyObject* val)
 {
   int result = -1;
   if (name == NULL) {
     goto done;
   }
 
-  if (strcmp("nodata", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("nodata", name) == 0) {
     if (PyFloat_Check(val)) {
       BBTopography_setNodata(self->topo, PyFloat_AsDouble(val));
     } else if (PyLong_Check(val) || PyInt_Check(val)) {
@@ -376,7 +369,7 @@ static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "nodata must be a floating number");
     }
-  } else if (strcmp("ulxmap", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ulxmap", name) == 0) {
     if (PyFloat_Check(val)) {
       BBTopography_setUlxmap(self->topo, PyFloat_AsDouble(val));
     } else if (PyLong_Check(val) || PyInt_Check(val)) {
@@ -384,7 +377,7 @@ static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "ulxmap must be a floating number");
     }
-  } else if (strcmp("ulymap", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ulymap", name) == 0) {
     if (PyFloat_Check(val)) {
       BBTopography_setUlymap(self->topo, PyFloat_AsDouble(val));
     } else if (PyLong_Check(val) || PyInt_Check(val)) {
@@ -392,7 +385,7 @@ static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "ulymap must be a floating number");
     }
-  } else if (strcmp("xdim", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("xdim", name) == 0) {
     if (PyFloat_Check(val)) {
       BBTopography_setXDim(self->topo, PyFloat_AsDouble(val));
     } else if (PyLong_Check(val) || PyInt_Check(val)) {
@@ -400,7 +393,7 @@ static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "xdim must be a floating number");
     }
-  } else if (strcmp("ydim", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("ydim", name) == 0) {
     if (PyFloat_Check(val)) {
       BBTopography_setYDim(self->topo, PyFloat_AsDouble(val));
     } else if (PyLong_Check(val) || PyInt_Check(val)) {
@@ -409,7 +402,7 @@ static int _pybbtopography_setattr(PyBBTopography* self, char* name, PyObject* v
       raiseException_gotoTag(done, PyExc_ValueError, "ydim must be a floating number");
     }
   } else {
-    raiseException_gotoTag(done, PyExc_AttributeError, name);
+    raiseException_gotoTag(done, PyExc_AttributeError, PY_RAVE_ATTRO_NAME_TO_STRING(name));
   }
 
   result = 0;
@@ -425,21 +418,47 @@ done:
 /*@{ Type definitions */
 PyTypeObject PyBBTopography_Type =
 {
-  PyObject_HEAD_INIT(NULL)0, /*ob_size*/
+  PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/
   "BBTopographyCore", /*tp_name*/
   sizeof(PyBBTopography), /*tp_size*/
   0, /*tp_itemsize*/
   /* methods */
   (destructor)_pybbtopography_dealloc, /*tp_dealloc*/
   0, /*tp_print*/
-  (getattrfunc)_pybbtopography_getattr, /*tp_getattr*/
-  (setattrfunc)_pybbtopography_setattr, /*tp_setattr*/
-  0, /*tp_compare*/
-  0, /*tp_repr*/
-  0, /*tp_as_number */
+  (getattrfunc)0,               /*tp_getattr*/
+  (setattrfunc)0,               /*tp_setattr*/
+  0,                            /*tp_compare*/
+  0,                            /*tp_repr*/
+  0,                            /*tp_as_number */
   0,
-  0, /*tp_as_mapping */
-  0 /*tp_hash*/
+  0,                            /*tp_as_mapping */
+  0,                            /*tp_hash*/
+  (ternaryfunc)0,               /*tp_call*/
+  (reprfunc)0,                  /*tp_str*/
+  (getattrofunc)_pybbtopography_getattro, /*tp_getattro*/
+  (setattrofunc)_pybbtopography_setattro, /*tp_setattro*/
+  0,                            /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT, /*tp_flags*/
+  0,                            /*tp_doc*/
+  (traverseproc)0,              /*tp_traverse*/
+  (inquiry)0,                   /*tp_clear*/
+  0,                            /*tp_richcompare*/
+  0,                            /*tp_weaklistoffset*/
+  0,                            /*tp_iter*/
+  0,                            /*tp_iternext*/
+  _pybbtopography_methods,              /*tp_methods*/
+  0,                            /*tp_members*/
+  0,                            /*tp_getset*/
+  0,                            /*tp_base*/
+  0,                            /*tp_dict*/
+  0,                            /*tp_descr_get*/
+  0,                            /*tp_descr_set*/
+  0,                            /*tp_dictoffset*/
+  0,                            /*tp_init*/
+  0,                            /*tp_alloc*/
+  0,                            /*tp_new*/
+  0,                            /*tp_free*/
+  0,                            /*tp_is_gc*/
 };
 /*@} End of Type definitions */
 
@@ -453,36 +472,38 @@ static PyMethodDef functions[] = {
   {NULL,NULL} /*Sentinel*/
 };
 
-PyMODINIT_FUNC
-init_bbtopography(void)
+MOD_INIT(_bbtopography)
 {
   PyObject *module=NULL,*dictionary=NULL;
   static void *PyBBTopography_API[PyBBTopography_API_pointers];
   PyObject *c_api_object = NULL;
-  PyBBTopography_Type.ob_type = &PyType_Type;
 
-  module = Py_InitModule("_bbtopography", functions);
+  MOD_INIT_SETUP_TYPE(PyBBTopography_Type, &PyType_Type);
+
+  MOD_INIT_VERIFY_TYPE_READY(&PyBBTopography_Type);
+
+  MOD_INIT_DEF(module, "_bbtopography", NULL/*doc*/, functions);
   if (module == NULL) {
-    return;
+    return MOD_INIT_ERROR;
   }
+
   PyBBTopography_API[PyBBTopography_Type_NUM] = (void*)&PyBBTopography_Type;
   PyBBTopography_API[PyBBTopography_GetNative_NUM] = (void *)PyBBTopography_GetNative;
   PyBBTopography_API[PyBBTopography_New_NUM] = (void*)PyBBTopography_New;
 
-  c_api_object = PyCObject_FromVoidPtr((void *)PyBBTopography_API, NULL);
-
-  if (c_api_object != NULL) {
-    PyModule_AddObject(module, "_C_API", c_api_object);
-  }
-
+  c_api_object = PyCapsule_New(PyBBTopography_API, PyBBTopography_CAPSULE_NAME, NULL);
   dictionary = PyModule_GetDict(module);
-  ErrorObject = PyString_FromString("_bbtopography.error");
+  PyDict_SetItemString(dictionary, "_C_API", c_api_object);
 
+  ErrorObject = PyErr_NewException("_bbtopography.error", NULL, NULL);
   if (ErrorObject == NULL || PyDict_SetItemString(dictionary, "error", ErrorObject) != 0) {
     Py_FatalError("Can't define _bbtopography.error");
+    return MOD_INIT_ERROR;
   }
+
   import_array();
 
   PYRAVE_DEBUG_INITIALIZE;
+  return MOD_INIT_SUCCESS(module);
 }
 /*@} End of Module setup */
index afb7fae..47d50b2 100644 (file)
@@ -47,6 +47,8 @@ typedef struct {
 
 #define PyBBTopography_API_pointers 3                          /**< number of type and function pointers */
 
+#define PyBBTopography_CAPSULE_NAME "_bbtopography._C_API"
+
 #ifdef PYBBTOPOGRAPHY_MODULE
 /** Forward declaration of type */
 extern PyTypeObject PyBBTopography_Type;
@@ -85,34 +87,15 @@ static void **PyBBTopography_API;
  * Checks if the object is a python topography instance
  */
 #define PyBBTopography_Check(op) \
-   ((op)->ob_type == (PyTypeObject *)PyBBTopography_API[PyBBTopography_Type_NUM])
+       (Py_TYPE(op) == &PyBBTopography_Type)
+
+#define PyBBTopography_Type (*(PyTypeObject*)PyBBTopography_API[PyBBTopography_Type_NUM])
 
 /**
  * Imports the PyBBTopography module (like import _bbtopography in python).
  */
-static int
-import_bbtopography(void)
-{
-  PyObject *module;
-  PyObject *c_api_object;
-
-  module = PyImport_ImportModule("_bbtopography");
-  if (module == NULL) {
-    return -1;
-  }
-
-  c_api_object = PyObject_GetAttrString(module, "_C_API");
-  if (c_api_object == NULL) {
-    Py_DECREF(module);
-    return -1;
-  }
-  if (PyCObject_Check(c_api_object)) {
-    PyBBTopography_API = (void **)PyCObject_AsVoidPtr(c_api_object);
-  }
-  Py_DECREF(c_api_object);
-  Py_DECREF(module);
-  return 0;
-}
+#define import_bbtopography() \
+       PyBBTopography_API = (void **)PyCapsule_Import(PyBBTopography_CAPSULE_NAME, 1);
 
 #endif
 
index 72b3e5b..f755b16 100644 (file)
@@ -22,6 +22,7 @@ along with beamb.  If not, see <http://www.gnu.org/licenses/>.
  * @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
  * @date 2011-11-14
  */
+#include "pybeamb_compat.h"
 #include "Python.h"
 #include <math.h>
 #include <stdio.h>
@@ -218,49 +219,40 @@ static struct PyMethodDef _pybeamblockage_methods[] =
 /**
  * Returns the specified attribute in the beam blockage
  */
-static PyObject* _pybeamblockage_getattr(PyBeamBlockage* self, char* name)
+static PyObject* _pybeamblockage_getattro(PyBeamBlockage* self, PyObject* name)
 {
-  PyObject* res = NULL;
-
-  if (strcmp("topo30dir", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("topo30dir", name) == 0) {
     const char* str = BeamBlockage_getTopo30Directory(self->beamb);
     if (str != NULL) {
       return PyString_FromString(str);
     } else {
       Py_RETURN_NONE;
     }
-  } else if (strcmp("cachedir", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("cachedir", name) == 0) {
     const char* str = BeamBlockage_getCacheDirectory(self->beamb);
     if (str != NULL) {
       return PyString_FromString(str);
     } else {
       Py_RETURN_NONE;
     }
-  } else if (strcmp("rewritecache", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("rewritecache", name) == 0) {
     int val = BeamBlockage_getRewriteCache(self->beamb);
     return PyBool_FromLong(val);
   }
-
-  res = Py_FindMethod(_pybeamblockage_methods, (PyObject*) self, name);
-  if (res)
-    return res;
-
-  PyErr_Clear();
-  PyErr_SetString(PyExc_AttributeError, name);
-  return NULL;
+  return PyObject_GenericGetAttr((PyObject*)self, name);
 }
 
 /**
  * Returns the specified attribute in the polar volume
  */
-static int _pybeamblockage_setattr(PyBeamBlockage* self, char* name, PyObject* val)
+static int _pybeamblockage_setattro(PyBeamBlockage* self, PyObject* name, PyObject* val)
 {
   int result = -1;
   if (name == NULL) {
     goto done;
   }
 
-  if (strcmp("topo30dir", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("topo30dir", name) == 0) {
     if (PyString_Check(val)) {
       if (!BeamBlockage_setTopo30Directory(self->beamb, PyString_AsString(val))) {
         raiseException_gotoTag(done, PyExc_ValueError, "topo30dir must be a string or None");
@@ -270,7 +262,7 @@ static int _pybeamblockage_setattr(PyBeamBlockage* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "topo30dir must be a string or None");
     }
-  } else if (strcmp("cachedir", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("cachedir", name) == 0) {
     if (PyString_Check(val)) {
       if (!BeamBlockage_setCacheDirectory(self->beamb, PyString_AsString(val))) {
         raiseException_gotoTag(done, PyExc_ValueError, "cachedir must be a string or None");
@@ -280,14 +272,14 @@ static int _pybeamblockage_setattr(PyBeamBlockage* self, char* name, PyObject* v
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "cachedir must be a string or None");
     }
-  } else if (strcmp("rewritecache", name) == 0) {
+  } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("rewritecache", name) == 0) {
     if (PyBool_Check(val)) {
       BeamBlockage_setRewriteCache(self->beamb, val == Py_True?1:0);
     } else {
       raiseException_gotoTag(done, PyExc_ValueError, "rewritecache must be a boolean");
     }
   } else {
-    raiseException_gotoTag(done, PyExc_AttributeError, name);
+    raiseException_gotoTag(done, PyExc_AttributeError, PY_RAVE_ATTRO_NAME_TO_STRING(name));
   }
 
   result = 0;
@@ -303,21 +295,47 @@ done:
 /*@{ Type definitions */
 PyTypeObject PyBeamBlockage_Type =
 {
-  PyObject_HEAD_INIT(NULL)0, /*ob_size*/
+  PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/
   "BeamBlockageCore", /*tp_name*/
   sizeof(PyBeamBlockage), /*tp_size*/
   0, /*tp_itemsize*/
   /* methods */
   (destructor)_pybeamblockage_dealloc, /*tp_dealloc*/
   0, /*tp_print*/
-  (getattrfunc)_pybeamblockage_getattr, /*tp_getattr*/
-  (setattrfunc)_pybeamblockage_setattr, /*tp_setattr*/
-  0, /*tp_compare*/
-  0, /*tp_repr*/
-  0, /*tp_as_number */
+  (getattrfunc)0,               /*tp_getattr*/
+  (setattrfunc)0,               /*tp_setattr*/
+  0,                            /*tp_compare*/
+  0,                            /*tp_repr*/
+  0,                            /*tp_as_number */
   0,
-  0, /*tp_as_mapping */
-  0 /*tp_hash*/
+  0,                            /*tp_as_mapping */
+  0,                            /*tp_hash*/
+  (ternaryfunc)0,               /*tp_call*/
+  (reprfunc)0,                  /*tp_str*/
+  (getattrofunc)_pybeamblockage_getattro, /*tp_getattro*/
+  (setattrofunc)_pybeamblockage_setattro, /*tp_setattro*/
+  0,                            /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT, /*tp_flags*/
+  0,                            /*tp_doc*/
+  (traverseproc)0,              /*tp_traverse*/
+  (inquiry)0,                   /*tp_clear*/
+  0,                            /*tp_richcompare*/
+  0,                            /*tp_weaklistoffset*/
+  0,                            /*tp_iter*/
+  0,                            /*tp_iternext*/
+  _pybeamblockage_methods,              /*tp_methods*/
+  0,                            /*tp_members*/
+  0,                            /*tp_getset*/
+  0,                            /*tp_base*/
+  0,                            /*tp_dict*/
+  0,                            /*tp_descr_get*/
+  0,                            /*tp_descr_set*/
+  0,                            /*tp_dictoffset*/
+  0,                            /*tp_init*/
+  0,                            /*tp_alloc*/
+  0,                            /*tp_new*/
+  0,                            /*tp_free*/
+  0,                            /*tp_is_gc*/
 };
 /*@} End of Type definitions */
 
@@ -332,36 +350,39 @@ static PyMethodDef functions[] = {
   {NULL,NULL} /*Sentinel*/
 };
 
-PyMODINIT_FUNC
-init_beamblockage(void)
+MOD_INIT(_beamblockage)
 {
   PyObject *module=NULL,*dictionary=NULL;
   static void *PyBeamBlockage_API[PyBeamBlockage_API_pointers];
   PyObject *c_api_object = NULL;
-  PyBeamBlockage_Type.ob_type = &PyType_Type;
 
-  module = Py_InitModule("_beamblockage", functions);
+  MOD_INIT_SETUP_TYPE(PyBeamBlockage_Type, &PyType_Type);
+
+  MOD_INIT_VERIFY_TYPE_READY(&PyBeamBlockage_Type);
+
+  MOD_INIT_DEF(module, "_beamblockage", NULL/*doc*/, functions);
   if (module == NULL) {
-    return;
+    return MOD_INIT_ERROR;
   }
+
   PyBeamBlockage_API[PyBeamBlockage_Type_NUM] = (void*)&PyBeamBlockage_Type;
   PyBeamBlockage_API[PyBeamBlockage_GetNative_NUM] = (void *)PyBeamBlockage_GetNative;
   PyBeamBlockage_API[PyBeamBlockage_New_NUM] = (void*)PyBeamBlockage_New;
 
-  c_api_object = PyCObject_FromVoidPtr((void *)PyBeamBlockage_API, NULL);
-
-  if (c_api_object != NULL) {
-    PyModule_AddObject(module, "_C_API", c_api_object);
-  }
-
+  c_api_object = PyCapsule_New(PyBeamBlockage_API, PyBeamBlockage_CAPSULE_NAME, NULL);
   dictionary = PyModule_GetDict(module);
-  ErrorObject = PyString_FromString("_beamblockage.error");
+  PyDict_SetItemString(dictionary, "_C_API", c_api_object);
 
+  ErrorObject = PyErr_NewException("_beamblockage.error", NULL, NULL);
   if (ErrorObject == NULL || PyDict_SetItemString(dictionary, "error", ErrorObject) != 0) {
     Py_FatalError("Can't define _beamblockage.error");
+    return MOD_INIT_ERROR;
   }
+
   import_pyravefield();
   import_pypolarscan();
   PYRAVE_DEBUG_INITIALIZE;
+
+  return MOD_INIT_SUCCESS(module);
 }
 /*@} End of Module setup */
index 877cb8b..2d33523 100644 (file)
@@ -46,6 +46,8 @@ typedef struct {
 
 #define PyBeamBlockage_API_pointers 3                          /**< number of type and function pointers */
 
+#define PyBeamBlockage_CAPSULE_NAME "_beamblockage._C_API"
+
 #ifdef PYBEAMBLOCKAGE_MODULE
 /** Forward declaration of type */
 extern PyTypeObject PyBeamBlockage_Type;
@@ -84,34 +86,17 @@ static void **PyBeamBlockage_API;
  * Checks if the object is a python beam blockage instance
  */
 #define PyBeamBlockage_Check(op) \
-   ((op)->ob_type == (PyTypeObject *)PyBeamBlockage_API[PyBeamBlockage_Type_NUM])
+       (Py_TYPE(op) == &PyBeamBlockage_Type)
+
+
+#define PyBeamBlockage_Type (*(PyTypeObject*)PyBeamBlockage_API[PyBeamBlockage_Type_NUM])
+
 
 /**
  * Imports the PyBeamBlockage module (like import _beamblockage in python).
  */
-static int
-import_beamblockage(void)
-{
-  PyObject *module;
-  PyObject *c_api_object;
-
-  module = PyImport_ImportModule("_beamblockage");
-  if (module == NULL) {
-    return -1;
-  }
-
-  c_api_object = PyObject_GetAttrString(module, "_C_API");
-  if (c_api_object == NULL) {
-    Py_DECREF(module);
-    return -1;
-  }
-  if (PyCObject_Check(c_api_object)) {
-    PyBeamBlockage_API = (void **)PyCObject_AsVoidPtr(c_api_object);
-  }
-  Py_DECREF(c_api_object);
-  Py_DECREF(module);
-  return 0;
-}
+#define import_beamblockage() \
+               PyBeamBlockage_API = (void **)PyCapsule_Import(PyBeamBlockage_CAPSULE_NAME, 1);
 
 #endif
 
index 5955d3e..da289a9 100644 (file)
@@ -22,6 +22,7 @@ along with beamb.  If not, see <http://www.gnu.org/licenses/>.
  * @author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
  * @date 2011-11-15
  */
+#include "pybeamb_compat.h"
 #include "Python.h"
 #include <math.h>
 #include <stdio.h>
@@ -204,11 +205,9 @@ static struct PyMethodDef _pybeamblockagemap_methods[] =
 /**
  * Returns the specified attribute in the beam blockage map
  */
-static PyObject* _pybeamblockagemap_getattr(PyBeamBlockageMap* self, char* name)
+static PyObject* _pybeamblockagemap_getattro(PyBeamBlockageMap* self, PyObject* name)
 {
-  PyObject* res = NULL;
-
-  if (strcmp("topo30dir", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("topo30dir", name) == 0) {
     const char* str = BeamBlockageMap_getTopo30Directory(self->map);
     if (str != NULL) {
       return PyString_FromString(str);
@@ -216,27 +215,20 @@ static PyObject* _pybeamblockagemap_getattr(PyBeamBlockageMap* self, char* name)
       Py_RETURN_NONE;
     }
   }
-
-  res = Py_FindMethod(_pybeamblockagemap_methods, (PyObject*) self, name);
-  if (res)
-    return res;
-
-  PyErr_Clear();
-  PyErr_SetString(PyExc_AttributeError, name);
-  return NULL;
+  return PyObject_GenericGetAttr((PyObject*)self, name);
 }
 
 /**
  * Returns the specified attribute in the beam blockage instance
  */
-static int _pybeamblockagemap_setattr(PyBeamBlockageMap* self, char* name, PyObject* val)
+static int _pybeamblockagemap_setattro(PyBeamBlockageMap* self, PyObject* name, PyObject* val)
 {
   int result = -1;
   if (name == NULL) {
     goto done;
   }
 
-  if (strcmp("topo30dir", name) == 0) {
+  if (PY_COMPARE_STRING_WITH_ATTRO_NAME("topo30dir", name) == 0) {
     if (PyString_Check(val)) {
       if (!BeamBlockageMap_setTopo30Directory(self->map, PyString_AsString(val))) {
         raiseException_gotoTag(done, PyExc_ValueError, "topo30dir must be a string or None");
@@ -247,7 +239,7 @@ static int _pybeamblockagemap_setattr(PyBeamBlockageMap* self, char* name, PyObj
       raiseException_gotoTag(done, PyExc_ValueError, "topo30dir must be a string or None");
     }
   } else {
-    raiseException_gotoTag(done, PyExc_AttributeError, name);
+    raiseException_gotoTag(done, PyExc_AttributeError, PY_RAVE_ATTRO_NAME_TO_STRING(name));
   }
 
   result = 0;
@@ -263,22 +255,49 @@ done:
 /*@{ Type definitions */
 PyTypeObject PyBeamBlockageMap_Type =
 {
-  PyObject_HEAD_INIT(NULL)0, /*ob_size*/
+  PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/
   "BeamBlockageMapCore", /*tp_name*/
   sizeof(PyBeamBlockageMap), /*tp_size*/
   0, /*tp_itemsize*/
   /* methods */
   (destructor)_pybeamblockagemap_dealloc, /*tp_dealloc*/
   0, /*tp_print*/
-  (getattrfunc)_pybeamblockagemap_getattr, /*tp_getattr*/
-  (setattrfunc)_pybeamblockagemap_setattr, /*tp_setattr*/
-  0, /*tp_compare*/
-  0, /*tp_repr*/
-  0, /*tp_as_number */
+  (getattrfunc)0,               /*tp_getattr*/
+  (setattrfunc)0,               /*tp_setattr*/
+  0,                            /*tp_compare*/
+  0,                            /*tp_repr*/
+  0,                            /*tp_as_number */
   0,
-  0, /*tp_as_mapping */
-  0 /*tp_hash*/
+  0,                            /*tp_as_mapping */
+  0,                            /*tp_hash*/
+  (ternaryfunc)0,               /*tp_call*/
+  (reprfunc)0,                  /*tp_str*/
+  (getattrofunc)_pybeamblockagemap_getattro, /*tp_getattro*/
+  (setattrofunc)_pybeamblockagemap_setattro, /*tp_setattro*/
+  0,                            /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT, /*tp_flags*/
+  0,                            /*tp_doc*/
+  (traverseproc)0,              /*tp_traverse*/
+  (inquiry)0,                   /*tp_clear*/
+  0,                            /*tp_richcompare*/
+  0,                            /*tp_weaklistoffset*/
+  0,                            /*tp_iter*/
+  0,                            /*tp_iternext*/
+  _pybeamblockagemap_methods,              /*tp_methods*/
+  0,                            /*tp_members*/
+  0,                            /*tp_getset*/
+  0,                            /*tp_base*/
+  0,                            /*tp_dict*/
+  0,                            /*tp_descr_get*/
+  0,                            /*tp_descr_set*/
+  0,                            /*tp_dictoffset*/
+  0,                            /*tp_init*/
+  0,                            /*tp_alloc*/
+  0,                            /*tp_new*/
+  0,                            /*tp_free*/
+  0,                            /*tp_is_gc*/
 };
+
 /*@} End of Type definitions */
 
 /*@{ Functions */
@@ -291,36 +310,38 @@ static PyMethodDef functions[] = {
   {NULL,NULL} /*Sentinel*/
 };
 
-PyMODINIT_FUNC
-init_beamblockagemap(void)
+MOD_INIT(_beamblockagemap)
 {
   PyObject *module=NULL,*dictionary=NULL;
   static void *PyBeamBlockageMap_API[PyBeamBlockageMap_API_pointers];
   PyObject *c_api_object = NULL;
-  PyBeamBlockageMap_Type.ob_type = &PyType_Type;
 
-  module = Py_InitModule("_beamblockagemap", functions);
+  MOD_INIT_SETUP_TYPE(PyBeamBlockageMap_Type, &PyType_Type);
+
+  MOD_INIT_VERIFY_TYPE_READY(&PyBeamBlockageMap_Type);
+
+  MOD_INIT_DEF(module, "_beamblockagemap", NULL/*doc*/, functions);
   if (module == NULL) {
-    return;
+    return MOD_INIT_ERROR;
   }
+
   PyBeamBlockageMap_API[PyBeamBlockageMap_Type_NUM] = (void*)&PyBeamBlockageMap_Type;
   PyBeamBlockageMap_API[PyBeamBlockageMap_GetNative_NUM] = (void *)PyBeamBlockageMap_GetNative;
   PyBeamBlockageMap_API[PyBeamBlockageMap_New_NUM] = (void*)PyBeamBlockageMap_New;
 
-  c_api_object = PyCObject_FromVoidPtr((void *)PyBeamBlockageMap_API, NULL);
-
-  if (c_api_object != NULL) {
-    PyModule_AddObject(module, "_C_API", c_api_object);
-  }
-
+  c_api_object = PyCapsule_New(PyBeamBlockageMap_API, PyBeamBlockageMap_CAPSULE_NAME, NULL);
   dictionary = PyModule_GetDict(module);
-  ErrorObject = PyString_FromString("_beamblockagemap.error");
+  PyDict_SetItemString(dictionary, "_C_API", c_api_object);
 
+  ErrorObject = PyErr_NewException("_beamblockagemap.error", NULL, NULL);
   if (ErrorObject == NULL || PyDict_SetItemString(dictionary, "error", ErrorObject) != 0) {
     Py_FatalError("Can't define _beamblockagemap.error");
+    return MOD_INIT_ERROR;
   }
+
   import_bbtopography();
   import_pypolarscan();
   PYRAVE_DEBUG_INITIALIZE;
+  return MOD_INIT_SUCCESS(module);
 }
 /*@} End of Module setup */
index 0e3beb0..7235828 100644 (file)
@@ -46,6 +46,8 @@ typedef struct {
 
 #define PyBeamBlockageMap_API_pointers 3                          /**< number of type and function pointers */
 
+#define PyBeamBlockageMap_CAPSULE_NAME "_beamblockagemap._C_API"
+
 #ifdef PYBEAMBLOCKAGEMAP_MODULE
 /** Forward declaration of type */
 extern PyTypeObject PyBeamBlockageMap_Type;
@@ -84,34 +86,15 @@ static void **PyBeamBlockageMap_API;
  * Checks if the object is a python beam blockage instance
  */
 #define PyBeamBlockageMap_Check(op) \
-   ((op)->ob_type == (PyTypeObject *)PyBeamBlockageMap_API[PyBeamBlockageMap_Type_NUM])
+       (Py_TYPE(op) == &PyBeamBlockageMap_Type)
+
+#define PyBeamBlockageMap_Type (*(PyTypeObject*)PyBeamBlockageMap_API[PyBeamBlockageMap_Type_NUM])
 
 /**
  * Imports the PyBeamBlockageMap module (like import _beamblockage in python).
  */
-static int
-import_beamblockagemap(void)
-{
-  PyObject *module;
-  PyObject *c_api_object;
-
-  module = PyImport_ImportModule("_beamblockagemap");
-  if (module == NULL) {
-    return -1;
-  }
-
-  c_api_object = PyObject_GetAttrString(module, "_C_API");
-  if (c_api_object == NULL) {
-    Py_DECREF(module);
-    return -1;
-  }
-  if (PyCObject_Check(c_api_object)) {
-    PyBeamBlockageMap_API = (void **)PyCObject_AsVoidPtr(c_api_object);
-  }
-  Py_DECREF(c_api_object);
-  Py_DECREF(module);
-  return 0;
-}
+#define import_beamblockagemap() \
+               PyBeamBlockageMap_API = (void **)PyCapsule_Import(PyBeamBlockageMap_CAPSULE_NAME, 1);
 
 #endif
 
index be37761..537d39c 100644 (file)
@@ -40,7 +40,7 @@ class PyBBTopographyTest(unittest.TestCase):
   
   def test_new(self):
     a = _bbtopography.new()
-    self.assertNotEqual(-1, string.find(`type(a)`, "BBTopographyCore"))
+    self.assertNotEqual(-1, str(type(a)).find("BBTopographyCore"))
 
   def test_nodata(self):
     a = _bbtopography.new()
@@ -114,12 +114,12 @@ class PyBBTopographyTest(unittest.TestCase):
     obj2.setValue(5,4,25.0)
 
     result = obj.concatx(obj2)
-    self.assertEquals(16, result.ncols)
-    self.assertEquals(10, result.nrows)
-    self.assertAlmostEquals(10.0, result.getValue(0,1)[1], 4)
-    self.assertAlmostEquals(20.0, result.getValue(5,4)[1], 4)
-    self.assertAlmostEquals(15.0, result.getValue(10,1)[1], 4)
-    self.assertAlmostEquals(25.0, result.getValue(15,4)[1], 4)    
+    self.assertEqual(16, result.ncols)
+    self.assertEqual(10, result.nrows)
+    self.assertAlmostEqual(10.0, result.getValue(0,1)[1], 4)
+    self.assertAlmostEqual(20.0, result.getValue(5,4)[1], 4)
+    self.assertAlmostEqual(15.0, result.getValue(10,1)[1], 4)
+    self.assertAlmostEqual(25.0, result.getValue(15,4)[1], 4)    
 
   def test_concaty(self):
     obj = _bbtopography.new()
@@ -133,12 +133,12 @@ class PyBBTopographyTest(unittest.TestCase):
     obj2.setValue(5,4,25.0)
 
     result = obj.concaty(obj2)
-    self.assertEquals(10, result.ncols)
-    self.assertEquals(16, result.nrows)
-    self.assertAlmostEquals(10.0, result.getValue(0,1)[1], 4)
-    self.assertAlmostEquals(20.0, result.getValue(5,4)[1], 4)
-    self.assertAlmostEquals(15.0, result.getValue(0,11)[1], 4)
-    self.assertAlmostEquals(25.0, result.getValue(5,14)[1], 4)    
+    self.assertEqual(10, result.ncols)
+    self.assertEqual(16, result.nrows)
+    self.assertAlmostEqual(10.0, result.getValue(0,1)[1], 4)
+    self.assertAlmostEqual(20.0, result.getValue(5,4)[1], 4)
+    self.assertAlmostEqual(15.0, result.getValue(0,11)[1], 4)
+    self.assertAlmostEqual(25.0, result.getValue(5,14)[1], 4)    
 
 
 if __name__ == "__main__":
index 4893bc7..293e792 100644 (file)
@@ -43,29 +43,29 @@ class PyBeamBlockageMapTest(unittest.TestCase):
   
   def testNew(self):
     a = _beamblockagemap.new()
-    self.assertNotEqual(-1, string.find(`type(a)`, "BeamBlockageMapCore"))
+    self.assertNotEqual(-1, str(type(a)).find("BeamBlockageMapCore"))
 
   def testTopo30(self):
     a = _beamblockagemap.new()
     self.assertTrue(None != a.topo30dir)
     a.topo30dir="/tmp"
-    self.assertEquals("/tmp", a.topo30dir)
+    self.assertEqual("/tmp", a.topo30dir)
   
   def testReadTopo30(self):
     a = _beamblockagemap.new()
     a.topo30dir="../../data/gtopo30"
     result = a.readTopography(60*math.pi/180, 0*math.pi/180.0, 100000)
     self.assertTrue(result != None)
-    self.assertEquals(6000, result.nrows)
-    self.assertEquals(4800, result.ncols)
+    self.assertEqual(6000, result.nrows)
+    self.assertEqual(4800, result.ncols)
     
   def testReadTopo30_combined(self):
     a = _beamblockagemap.new()
     a.topo30dir="../../data/gtopo30"
     result = a.readTopography(60*math.pi/180, 20*math.pi/180.0, 200000)
     self.assertTrue(result != None)
-    self.assertEquals(6000, result.nrows)
-    self.assertEquals(9600, result.ncols)
+    self.assertEqual(6000, result.nrows)
+    self.assertEqual(9600, result.ncols)
   
   def testGetTopographyForScan(self):
     a = _beamblockagemap.new()
index 1f12e29..6457a63 100644 (file)
@@ -58,19 +58,19 @@ class PyBeamBlockageTest(unittest.TestCase):
         
   def testNew(self):
     a = _beamblockage.new()
-    self.assertNotEqual(-1, string.find(`type(a)`, "BeamBlockageCore"))
+    self.assertNotEqual(-1, str(type(a)).find("BeamBlockageCore"))
 
   def testTopo30(self):
     a = _beamblockage.new()
     self.assertTrue(None != a.topo30dir)
     a.topo30dir="/tmp"
-    self.assertEquals("/tmp", a.topo30dir)
+    self.assertEqual("/tmp", a.topo30dir)
 
   def testCachedir(self):
     a = _beamblockage.new()
     self.assertTrue(a.cachedir != None)
     a.cachedir="/tmp"
-    self.assertEquals("/tmp", a.cachedir)
+    self.assertEqual("/tmp", a.cachedir)
   
   def testReadTopo30(self):
     a = _beamblockage.new()
@@ -84,11 +84,11 @@ class PyBeamBlockageTest(unittest.TestCase):
     result = a.getBlockage(scan, -20.0);
     self.assertFalse(os.path.isfile(self.CACHEFILE_1))
 
-    self.assertEquals(_rave.RaveDataType_UCHAR, result.datatype)
-    self.assertAlmostEquals(0.0, result.getAttribute("what/offset"), 4)
-    self.assertAlmostEquals(1/255.0, result.getAttribute("what/gain"), 4)
-    self.assertEquals(scan.nbins, result.xsize)
-    self.assertEquals(scan.nrays, result.ysize)
+    self.assertEqual(_rave.RaveDataType_UCHAR, result.datatype)
+    self.assertAlmostEqual(0.0, result.getAttribute("what/offset"), 4)
+    self.assertAlmostEqual(1/255.0, result.getAttribute("what/gain"), 4)
+    self.assertEqual(scan.nbins, result.xsize)
+    self.assertEqual(scan.nrays, result.ysize)
 
   def test_getBlockage_caching(self):
     a = _beamblockage.new()
@@ -102,11 +102,11 @@ class PyBeamBlockageTest(unittest.TestCase):
     
     self.assertTrue(os.path.isfile(self.CACHEFILE_1))
 
-    self.assertEquals(_rave.RaveDataType_UCHAR, result.datatype)
-    self.assertAlmostEquals(0.0, result.getAttribute("what/offset"), 4)
-    self.assertAlmostEquals(1/255.0, result.getAttribute("what/gain"), 4)
-    self.assertEquals(scan.nbins, result.xsize)
-    self.assertEquals(scan.nrays, result.ysize)
+    self.assertEqual(_rave.RaveDataType_UCHAR, result.datatype)
+    self.assertAlmostEqual(0.0, result.getAttribute("what/offset"), 4)
+    self.assertAlmostEqual(1/255.0, result.getAttribute("what/gain"), 4)
+    self.assertEqual(scan.nbins, result.xsize)
+    self.assertEqual(scan.nrays, result.ysize)
     
   def test_getBlockage2(self):
     a = _beamblockage.new()
@@ -114,11 +114,11 @@ class PyBeamBlockageTest(unittest.TestCase):
     a.cachedir="/tmp"
     scan = _raveio.open(self.FIXTURE_2).object
     result = a.getBlockage(scan, -20.0);
-    self.assertEquals(_rave.RaveDataType_UCHAR, result.datatype)
-    self.assertAlmostEquals(0.0, result.getAttribute("what/offset"), 4)
-    self.assertAlmostEquals(1/255.0, result.getAttribute("what/gain"), 4)
-    self.assertEquals(scan.nbins, result.xsize)
-    self.assertEquals(scan.nrays, result.ysize)
+    self.assertEqual(_rave.RaveDataType_UCHAR, result.datatype)
+    self.assertAlmostEqual(0.0, result.getAttribute("what/offset"), 4)
+    self.assertAlmostEqual(1/255.0, result.getAttribute("what/gain"), 4)
+    self.assertEqual(scan.nbins, result.xsize)
+    self.assertEqual(scan.nrays, result.ysize)
 
   def test_getBlockage2_keep_cache(self):
     a = _beamblockage.new()
@@ -133,8 +133,8 @@ class PyBeamBlockageTest(unittest.TestCase):
     result = a.getBlockage(scan, -20.0);
     c2stat_n = os.stat(self.CACHEFILE_2)
 
-    self.assertEquals(c2stat.st_ctime, c2stat_n.st_ctime)
-    self.assertEquals(c2stat.st_mtime, c2stat_n.st_mtime)
+    self.assertEqual(c2stat.st_ctime, c2stat_n.st_ctime)
+    self.assertEqual(c2stat.st_mtime, c2stat_n.st_mtime)
     
   def test_getBlockage2_recreate_cache(self):
     a = _beamblockage.new()
@@ -150,8 +150,8 @@ class PyBeamBlockageTest(unittest.TestCase):
     result = a.getBlockage(scan, -20.0);
     c2stat_n = os.stat(self.CACHEFILE_2)
 
-    self.assertNotEquals(c2stat.st_ctime, c2stat_n.st_ctime)
-    self.assertNotEquals(c2stat.st_mtime, c2stat_n.st_mtime)    
+    self.assertNotEqual(c2stat.st_ctime, c2stat_n.st_ctime)
+    self.assertNotEqual(c2stat.st_mtime, c2stat_n.st_mtime)    
 
   def test_getBlockage2_different_dblim(self):
     a = _beamblockage.new()
index 3ff172b..1937bb3 100644 (file)
@@ -70,15 +70,15 @@ class beamb_quality_plugin_test(unittest.TestCase):
   def testNew(self):
     a = beamb_quality_plugin.beamb_quality_plugin()
     self.assertTrue(isinstance(a, rave_quality_plugin.rave_quality_plugin))
-    self.assertEquals(None, a._cachedir)
-    self.assertEquals(None, a._topodir)
-    self.assertEquals(beamb_quality_plugin.BEAMBLOCKAGE_DBLIMIT, a._dblimit)
+    self.assertEqual(None, a._cachedir)
+    self.assertEqual(None, a._topodir)
+    self.assertEqual(beamb_quality_plugin.BEAMBLOCKAGE_DBLIMIT, a._dblimit)
     
   def test_getQualityFields(self):
     a = beamb_quality_plugin.beamb_quality_plugin()
     result = a.getQualityFields()
-    self.assertEquals(1, len(result))
-    self.assertEquals("se.smhi.detector.beamblockage", result[0])
+    self.assertEqual(1, len(result))
+    self.assertEqual("se.smhi.detector.beamblockage", result[0])
 
   def test_create_bb_default(self):
     a = beamb_quality_plugin.beamb_quality_plugin()
@@ -90,21 +90,21 @@ class beamb_quality_plugin_test(unittest.TestCase):
     a = beamb_quality_plugin.beamb_quality_plugin()
     a._cachedir="/tmp"
     result = a._create_bb()
-    self.assertEquals("/tmp", result.cachedir)
+    self.assertEqual("/tmp", result.cachedir)
 
   def test_create_bb_modified_topo(self):
     a = beamb_quality_plugin.beamb_quality_plugin()
     a._topodir="../../data/gtopo30"
     result = a._create_bb()
-    self.assertEquals("../../data/gtopo30", result.topo30dir)
+    self.assertEqual("../../data/gtopo30", result.topo30dir)
 
   def test_create_bb_modified_dirs(self):
     a = beamb_quality_plugin.beamb_quality_plugin()
     a._cachedir="/tmp"
     a._topodir="../../data/gtopo30"
     result = a._create_bb()
-    self.assertEquals("/tmp", result.cachedir)
-    self.assertEquals("../../data/gtopo30", result.topo30dir)
+    self.assertEqual("/tmp", result.cachedir)
+    self.assertEqual("../../data/gtopo30", result.topo30dir)
 
 
   def test_process_scan(self):
@@ -209,7 +209,7 @@ class beamb_quality_plugin_test(unittest.TestCase):
       scan = volume.getScan(i)
       fields2.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
     
-    self.assertEquals(len(fields), len(fields2))
+    self.assertEqual(len(fields), len(fields2))
     for i in range(len(fields)):
       self.assertTrue(fields[i] != fields2[i])
 
@@ -233,7 +233,7 @@ class beamb_quality_plugin_test(unittest.TestCase):
       scan = volume.getScan(i)
       fields2.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
     
-    self.assertEquals(len(fields), len(fields2))
+    self.assertEqual(len(fields), len(fields2))
     for i in range(len(fields)):
       self.assertTrue(fields[i] == fields2[i])
     
index a2093d0..9a96e42 100755 (executable)
@@ -9,7 +9,7 @@
 #
 # History:  2011-08-30 Created by Anders Henja
 ############################################################
-SCRFILE=`python -c "import os;print os.path.abspath(\"$0\")"`
+SCRFILE=`python -c "import os;print(os.path.abspath(\"$0\"))"`
 SCRIPTPATH=`dirname "$SCRFILE"`
 
 DEF_MK_FILE="${SCRIPTPATH}/../def.mk"
@@ -25,6 +25,12 @@ RESULT=0
 RAVE_ROOT_DIR=`fgrep RAVE_ROOT_DIR "${DEF_MK_FILE}" | sed -e"s/\(RAVE_ROOT_DIR=[ \t]*\)//"`
 RAVE_ROOT_MKFILE="$RAVE_ROOT_DIR/mkf/def.mk"
 
+# Identify python version
+PYTHON_BIN=`fgrep PYTHON_BIN "${RAVE_ROOT_MKFILE}" | sed -e "s/\(PYTHON_BIN=[ \t]*\)//"`
+if [ "$PYTHON_BIN" = "" ]; then
+  PYTHON_BIN=python
+fi
+
 # HLHDFS MKF FILE
 HLHDF_MKFFILE=`fgrep HLHDF_HLDEF_MK_FILE "${RAVE_ROOT_MKFILE}" | sed -e"s/\(HLHDF_HLDEF_MK_FILE=[ \t]*\)//"`
 
@@ -34,7 +40,7 @@ HDF5_LDPATH=`fgrep HDF5_LIBDIR "${HLHDF_MKFFILE}" | sed -e"s/\(HDF5_LIBDIR=[ \t]
 # Get HLHDFs libpath from raves mkf file
 HLHDF_LDPATH=`fgrep HLHDF_LIB_DIR "${RAVE_ROOT_MKFILE}" | sed -e"s/\(HLHDF_LIB_DIR=[ \t]*\)//"`
 
-BNAME=`python -c 'from distutils import util; import sys; print "lib.%s-%s" % (util.get_platform(), sys.version[0:3])'`
+BNAME=`$PYTHON_BIN -c 'from distutils import util; import sys; print("lib.%s-%s" % (util.get_platform(), sys.version[0:3]))'`
 
 RBPATH="${SCRIPTPATH}/../pybeamb"
 RAVE_LDPATH="${RAVE_ROOT_DIR}/lib"
@@ -80,9 +86,9 @@ NARGS=$#
 PYSCRIPT=
 DIRNAME=
 if [ $NARGS -eq 1 ]; then
-  PYSCRIPT=`python -c "import os;print os.path.abspath(\"$1\")"`
+  PYSCRIPT=`$PYTHON_BIN -c "import os;print(os.path.abspath(\"$1\"))"`
 elif [ $NARGS -eq 2 ]; then
-  PYSCRIPT=`python -c "import os;print os.path.abspath(\"$1\")"`
+  PYSCRIPT=`$PYTHON_BIN -c "import os;print(os.path.abspath(\"$1\"))"`
   DIRNAME="$2"
 elif [ $NARGS -eq 0 ]; then
   # Do nothing
@@ -99,9 +105,9 @@ fi
 
 if [ "$PYSCRIPT" != "" ]; then
   #valgrind --leak-check=full --show-reachable=yes 
-  python "$PYSCRIPT"
+  $PYTHON_BIN "$PYSCRIPT"
 else
-  python
+  $PYTHON_BIN
 fi
 
 VAL=$?