Belle II Software  release-05-02-19
validationtools.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 """This file contains multiple utility functions which can be used by
5 validation steering files. """
6 
7 import subprocess
8 import pickle
9 import sys
10 import os
11 
12 
13 def update_env():
14  """Update the environment with b2setup
15 
16  This is very annoying as there is no way for sub processes to modify the
17  parent environment. And also b2setup ist not inherited by sub shells. So we
18  have to run bash, source the tools, run b2setup and get all the environment
19  variables from the output.
20  """
21  # the no_tools_check variable speeds up the process as it does not check
22  # git to see if the tools are up to date.
23  cmd = 'BELLE2_NO_TOOLS_CHECK=1 source {}/b2setup > /dev/null && ' \
24  '{} -c "import sys,os,pickle; ' \
25  'sys.stdout.buffer.write(pickle.dumps(dict(os.environ)))"'.format(
26  os.environ['BELLE2_TOOLS'], sys.executable)
27  output = subprocess.check_output(['bash', '-c', cmd])
28  newenv = pickle.loads(output)
29  os.environ.update(newenv)