Belle II Software development
validationtools.py
1#!/usr/bin/env python3
2
3
10
11"""This file contains multiple utility functions which can be used by
12validation steering files. """
13
14import subprocess
15import pickle
16import sys
17import os
18
19
20def 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 is 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 f"BELLE2_NO_TOOLS_CHECK=1 source {os.environ['BELLE2_TOOLS']}/b2setup > /dev/null && {sys.executable} -c " +
32 '\"import sys,os,pickle; sys.stdout.buffer.write(pickle.dumps(dict(os.environ)))\"')
33 output = subprocess.check_output(["bash", "-c", cmd])
34 newenv = pickle.loads(output)
35 os.environ.update(newenv)