From 00183a75c8eefe2d6f1a6567d702f4d9bf117d87 Mon Sep 17 00:00:00 2001 From: abn Date: Mon, 3 Mar 2014 09:42:05 +0100 Subject: [PATCH] SWIG: improve precedence mechanism: isinstance(obj, MEDCoupling.obj_class) and isinstance(obj, MEDLoader.obj_class) both return true. --- src/MEDCoupling_Swig/MEDCoupling.i | 13 +++++++++++++ src/MEDCoupling_Swig/MEDCouplingFinalize.i | 1 + src/MEDLoader/Swig/MEDLoader.i | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index a7080a02a..e9176473f 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -98,3 +98,16 @@ def ParaMEDMEMDataArrayIntTupleImod(self,*args): %} %include "MEDCouplingFinalize.i" + +%pythoncode %{ + +# Give precedence to MEDCoupling namespace: +import sys +# If MEDLoader was already loaded override its namespace with the one from MEDCoupling: +if sys.modules.has_key('MEDLoader'): + ml_mod = sys.modules['MEDLoader'] + for k, v in sys.modules['MEDCoupling'].__dict__.items(): + if (k.startswith("MED") or k.startswith("InterpKernel")) and type(v) is type(type): + exec("ml_mod.__dict__[k] = %s" % k) + +%} diff --git a/src/MEDCoupling_Swig/MEDCouplingFinalize.i b/src/MEDCoupling_Swig/MEDCouplingFinalize.i index e54cc904d..194cc4c70 100644 --- a/src/MEDCoupling_Swig/MEDCouplingFinalize.i +++ b/src/MEDCoupling_Swig/MEDCouplingFinalize.i @@ -71,4 +71,5 @@ del ParaMEDMEMDataArrayIntTupleIsub del ParaMEDMEMDataArrayIntTupleImul del ParaMEDMEMDataArrayIntTupleIdiv del ParaMEDMEMDataArrayIntTupleImod + %} diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 24aa39736..5d4126234 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -99,3 +99,16 @@ def ParaMEDMEMDataArrayIntTupleImod(self,*args): %} %include "MEDCouplingFinalize.i" + +%pythoncode %{ + +# Give precedence to MEDCoupling namespace: +import sys +# If MEDLoader was already loaded override its namespace with the one from MEDCoupling: +if sys.modules.has_key('MEDCoupling'): + mc_mod = sys.modules['MEDCoupling'] + for k, v in mc_mod.__dict__.items(): + if (k.startswith("MED") or k.startswith("InterpKernel")) and type(v) is type(type): + exec("%s = v" % k) + +%} -- 2.39.2