11 from functools
import cache
12 from tempfile
import NamedTemporaryFile
20 from AthenaCommon.Logging
import log
21 log.info(
'executing ROOT6Setup')
22 import builtins
as builtin_mod
23 oldimporthook = builtin_mod.__import__
24 autoload_var_name =
'ROOT6_NamespaceAutoloadHook'
25 batch_mode =
bool(batch)
27 def root6_importhook(name, globals={}, locals={}, fromlist=[], level=0):
31 if name==
'ROOT' or (name[0:4]==
'ROOT' and name!=
'ROOT.pythonization'):
35 m = oldimporthook(name, globals, locals, fromlist, level)
38 log.debug(
'Python import module=%s, fromlist=%s', name, fromlist)
40 log.debug(
'Setting ROOT batch mode to %s', bm)
45 vars = [
'.'.
join([
'', fl, autoload_var_name])
for fl
in fromlist]
47 vars = [
'.'.
join([name, autoload_var_name]) ]
53 for comp
in v.split(
'.')[1:]:
54 mm = getattr(mm, comp)
60 builtin_mod.__import__ = root6_importhook
65 A little helper class to keep ROOT silent...
68 re.compile(
"Warning in <TClass::TClass>: no dictionary for class."),
69 re.compile(
"Warning in <TEnvRec::ChangeValue>: duplicate entry."),
70 re.compile(
"Error in <TStreamerInfo::BuildOld>:."),
74 if os.environ.get(
'PYUTILS_SHUTUP_DEBUG',
'0') ==
'1':
80 self.
quiet_err = NamedTemporaryFile( suffix =
".msg.log" )
81 self.
quiet_out = NamedTemporaryFile( suffix =
".msg.log" )
88 self.
quiet_err = NamedTemporaryFile( suffix =
".msg.log" )
89 self.
quiet_out = NamedTemporaryFile( suffix =
".msg.log" )
97 os.dup2( sys.stderr.fileno(), self.
save_err.fileno() )
98 os.dup2( sys.stdout.fileno(), self.
save_out.fileno() )
108 os.dup2( self.
quiet_err.fileno(), sys.stderr.fileno() )
109 os.dup2( self.
quiet_out.fileno(), sys.stdout.fileno() )
114 os.dup2( self.
save_err.fileno(), sys.stderr.fileno() )
115 os.dup2( self.
save_out.fileno(), sys.stdout.fileno() )
124 for l
in fd.readlines():
128 if re.match(filter, l):
131 print (
"PyRoot:",l.replace(
"\n",
""))
144 """Returns information about the current release based on ReleaseData"""
151 'nightly release':
'?',
157 for cmake_path
in os.environ[
'CMAKE_PREFIX_PATH'].
split(os.pathsep):
158 release_data = os.path.join(cmake_path,
'ReleaseData')
159 if os.path.exists(release_data):
161 cfg = configparser.ConfigParser()
163 cfg.read( release_data )
164 if cfg.has_section(
'release_metadata' ):
165 d1.update( dict( cfg.items(
'release_metadata' ) ) )
166 d1[
'platform'] = os.getenv(
'%s_PLATFORM' % d1[
'project name'],
168 release = d1[
'release'].
split(
'.')
169 base_release = d1[
'base release'].
split(
'.')
170 if len(release)>=3
or len(base_release)>=3: