Skip to content
Snippets Groups Projects
Commit 832989cd authored by maxgalli's avatar maxgalli Committed by Enric Tejedor
Browse files

[Exp PyROOT] Implemented the possibility to call a namespace inside...

[Exp PyROOT] Implemented the possibility to call a namespace inside cppyy.gbl.ROOT by typing simply ROOT.namespace instead of ROOT.ROOT.namespace
parent 2ae68fec
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,14 @@ class ROOTFacade(types.ModuleType):
self.__class__.__getattr__ = self._getattr
self.__class__.__setattr__ = self._setattr
def _fallback_getattr(self, name):
# Try first in the global namespace, then in the ROOT namespace
# This allows to lookup e.g. ROOT.ROOT.Math as ROOT.Math
try:
return getattr(gbl_namespace, name)
except AttributeError:
return getattr(self.__dict__['ROOT_ns'], name)
def _finalSetup(self):
# Setup interactive usage from Python
self.__dict__['app'] = PyROOTApplication(self.PyConfig)
......@@ -51,7 +59,8 @@ class ROOTFacade(types.ModuleType):
self.app.init_graphics()
# Redirect lookups to cppyy's global namespace
self.__class__.__getattr__ = lambda self, name: getattr(gbl_namespace, name)
self.__dict__['ROOT_ns'] = gbl_namespace.ROOT
self.__class__.__getattr__ = self._fallback_getattr
self.__class__.__setattr__ = lambda self, name, val: setattr(gbl_namespace, name, val)
def _getattr(self, name):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment