Logo ROOT  
Reference Guide
launcher.py
Go to the documentation of this file.
1 # Module to launch python tutorials.
2 # It serves the purpose of enabling batch mode,
3 # since PyROOT does not parse anymore by default
4 # the command line arguments
5 
6 import sys, os
7 
8 if len(sys.argv) < 2:
9  raise RuntimeError('Please specify tutorial file path as only argument of this script')
10 
11 # Get path to the tutorial file
12 file_path = os.path.expanduser(sys.argv[1])
13 
14 if os.path.exists(file_path):
15  # Module needs to run as main.
16  # Some tutorials have "if __name__ == '__main__'"
17  module_name = "__main__"
18 
19  # Ensure batch mode (some tutorials use graphics)
20  import ROOT
21  ROOT.gROOT.SetBatch(True)
22 
23  # Prevent import from generating .pyc files in source directory
24  sys.dont_write_bytecode = True
25 
26  # Execute test
27  if sys.version_info >= (3,5):
28  import importlib.util
29  spec = importlib.util.spec_from_file_location(module_name, file_path)
30  module = importlib.util.module_from_spec(spec)
31  sys.modules[module_name] = module
32  spec.loader.exec_module(module)
33  else:
34  import imp
35  imp.load_module(module_name, open(file_path, 'r'), file_path, ('.py','r',1))
36 else:
37  raise RuntimeError('Cannot execute test, {} is not a valid tutorial file path'.format(file_path))
ROOT::Math::detail::open
@ open
Definition: GenVectorIO.h:35