ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
utils.py
Go to the documentation of this file.
1 # -*- coding:utf-8 -*-
2 #-----------------------------------------------------------------------------
3 # Copyright (c) 2015, ROOT Team.
4 # Authors: Omar Zapata <Omar.Zapata@cern.ch> http://oproject.org
5 # Danilo Piparo <Danilo.Piparo@cern.ch> CERN
6 # Enric Tejedor enric.tejedor.saavedra@cern.ch> CERN
7 # website: http://oproject.org/ROOT+Jupyter+Kernel (information only for ROOT kernel)
8 # Distributed under the terms of the Modified LGPLv3 License.
9 #
10 # The full license is in the file COPYING.rst, distributed with this software.
11 #-----------------------------------------------------------------------------
12 import sys
13 import os
14 from glob import glob
15 from tempfile import NamedTemporaryFile
16 
17 from JupyROOT.kernel.handler import LoadHandlers
18 
19 try:
20  from JupyROOT.utils import invokeAclic
21  from JupyROOT.utils import isPlatformApple
22 except ImportError:
23  raise Exception("Error: JupyROOT not found")
24 
25 import ROOT
26 
27 import __builtin__
28 
29 _ioHandler = None
30 _Executor = None
31 _Declarer = None
32 
34  global _ioHandler
35  if not _ioHandler:
36  LoadHandlers()
37  from ROOT import JupyROOTExecutorHandler
38  _ioHandler = JupyROOTExecutorHandler()
39  return _ioHandler
40 
42  global _Executor
43  if not _Executor:
44  from ROOT import JupyROOTExecutor
45  _Executor = JupyROOTExecutor
46  return _Executor
47 
49  global _Declarer
50  if not _Declarer:
51  from ROOT import JupyROOTDeclarer
52  _Declarer = JupyROOTDeclarer
53  return _Declarer
54 
55 
56 def ACLiC(code):
57  status = 0
58  if isPlatformApple():
59  invokeAclic(code)
60  else:
61  tmpfile = NamedTemporaryFile(delete=False,suffix='.C',dir=os.getcwd())#will be removed when library is created
62  tmpfile.write(code)
63  tmpfilename = tmpfile.name
64  tmpfile.close()
65  Executor = GetExecutor()
66  status = Executor('.L %s+'%tmpfilename)
67  return status
68 
69 class MagicLoader(object):
70  '''Class to load JupyROOT Magics'''
71  def __init__(self,kernel):
72  magics_path = os.path.dirname(__file__)+"/magics/*.py"
73  for file in glob(magics_path):
74  if file != magics_path.replace("*.py","__init__.py"):
75  module_path="JupyROOT.kernel.magics."+file.split("/")[-1].replace(".py","")
76  try:
77  module= __builtin__.__import__(module_path, globals(), locals(), ['register_magics'], -1)
78  module.register_magics(kernel)
79  except ImportError:
80  raise Exception("Error importing Magic: %s"%module_path)
81 
82 
83 
84 
ROOT::R::TRInterface & Exception()
Definition: Exception.C:4
def invokeAclic
Definition: utils.py:206
def isPlatformApple
Definition: utils.py:203