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