ATLAS Offline Software
Loading...
Searching...
No Matches
python.Helpers Namespace Reference

Classes

class  ShutUp

Functions

 MakexAODDataFrame (inputs)
 ROOTSetup (batch=False)
 release_metadata ()
str get_release_setup (Logger logger, no_setup=False)
None list_changed_packages (Logger logger, no_setup=False)
List[str] warnings_count (Path file_name)

Function Documentation

◆ get_release_setup()

str python.Helpers.get_release_setup ( Logger logger,
no_setup = False )
Get release setup.

Definition at line 9 of file Tools/WorkflowTestRunner/python/Helpers.py.

9def get_release_setup(logger: Logger, no_setup=False) -> str:
10 """Get release setup."""
11 if no_setup:
12 logger.info("No release information is available when a release is not set-up.\n")
13 return ""
14
15 current_nightly = environ["AtlasBuildStamp"]
16 release_base = environ["AtlasBuildBranch"]
17 release_head = environ["AtlasVersion"]
18 platform = environ["LCG_PLATFORM"]
19 project = environ["AtlasProject"]
20 builds_dir_search_str = f"/cvmfs/atlas-nightlies.cern.ch/repo/sw/{release_base}_{project}_{platform}/[!latest_]*/{project}/{release_head}"
21 # finds all directories matching above search pattern, and sorts by modification time
22 # suggest to use latest opt over dbg
23 sorted_list = sorted(glob(builds_dir_search_str), key=path.getmtime)
24 latest_nightly = ""
25 for folder in reversed(sorted_list):
26 if not glob(f"{folder}/../../{release_base}__{project}*-opt*.log"):
27 continue
28 latest_nightly = folder.split("/")[-3]
29 break
30
31 if current_nightly != latest_nightly:
32 logger.info(f"Please be aware that you are not testing your tags in the latest available nightly, which is {latest_nightly}")
33
34 setup = "%s,%s,%s,Athena" % (release_base, platform.replace("-", ","), current_nightly)
35
36 logger.info(f"Your tags will be tested in environment {setup}")
37
38 return setup
39
40

◆ list_changed_packages()

None python.Helpers.list_changed_packages ( Logger logger,
no_setup = False )
List packages that have changed.

Definition at line 41 of file Tools/WorkflowTestRunner/python/Helpers.py.

41def list_changed_packages(logger: Logger, no_setup=False) -> None:
42 """List packages that have changed."""
43 if no_setup:
44 logger.info("The list of changed packages is not available when the relase is not set-up.\n")
45 return
46
47 if "WorkDir_DIR" in environ:
48 logger.info("Changed packages in your build to be tested:\n")
49 file_path = Path(environ["WorkDir_DIR"])
50 fname = file_path / "packages.txt"
51 with fname.open() as fp:
52 lines = fp.readlines()
53 last_line = lines[-1].strip() if lines else None
54 for line in lines:
55 line = line.strip()
56 if "#" not in line:
57 if line == last_line:
58 logger.info(f"{line}\n")
59 else:
60 logger.info(line)
61 else:
62 logger.warning("A release area with locally installed packages has not been setup.")
63 logger.warning("quit by executing <CONTROL-C> if this is not your intention, and")
64 logger.warning("source <YOUR_CMake_BUILD_AREA>/setup.sh")
65 logger.warning("to pickup locally built packages in your environment.\n")
66 pass
67
68

◆ MakexAODDataFrame()

python.Helpers.MakexAODDataFrame ( inputs)
Helper function creating a ROOT::RDataFrame object reading xAOD files

The function returns an instance of ROOT::RDataFrame that uses
xAOD::RDataSource for reading its inputs.

Keyword arguments:
  inputs -- A single string, or a list of string selecting the input file(s)
            Note that the string(s) may contain wildcards and environment
            variables as well.

Definition at line 6 of file Control/xAODDataSource/python/Helpers.py.

6def MakexAODDataFrame( inputs ):
7 """Helper function creating a ROOT::RDataFrame object reading xAOD files
8
9 The function returns an instance of ROOT::RDataFrame that uses
10 xAOD::RDataSource for reading its inputs.
11
12 Keyword arguments:
13 inputs -- A single string, or a list of string selecting the input file(s)
14 Note that the string(s) may contain wildcards and environment
15 variables as well.
16 """
17
18 # Make sure that the dictionary is loaded.
19 ROOT.xAOD.ROOT6_xAODDataSource_WorkAround_Dummy()
20
21 # Use the C++ function for the heavy lifting.
22 return ROOT.xAOD.MakeDataFrame( inputs )

◆ release_metadata()

python.Helpers.release_metadata ( )
Returns information about the current release based on ReleaseData

Definition at line 129 of file Tools/PyUtils/python/Helpers.py.

129def release_metadata():
130 """Returns information about the current release based on ReleaseData"""
131
132 import configparser
133 d = {
134 'project name': '?',
135 'release': '?',
136 'base release': '?',
137 'nightly release': '?',
138 'nightly name': '?',
139 'date': '?',
140 'platform': '?',
141 }
142
143 for cmake_path in os.environ['CMAKE_PREFIX_PATH'].split(os.pathsep):
144 release_data = os.path.join(cmake_path, 'ReleaseData')
145 if os.path.exists(release_data):
146 d1=d
147 cfg = configparser.ConfigParser()
148 try:
149 cfg.read( release_data )
150 if cfg.has_section( 'release_metadata' ):
151 d1.update( dict( cfg.items( 'release_metadata' ) ) )
152 d1['platform'] = os.getenv( '%s_PLATFORM' % d1['project name'],
153 '?' )
154 release = d1['release'].split('.')
155 base_release = d1['base release'].split('.')
156 if len(release)>=3 or len(base_release)>=3:
157 return d1
158 except Exception:
159 pass
160 return d
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ ROOTSetup()

python.Helpers.ROOTSetup ( batch = False)
At this point this function just makes sure the ROOT batch mode is set
correctly when someone imports ROOT

Definition at line 18 of file Tools/PyUtils/python/Helpers.py.

18def ROOTSetup(batch=False):
19 """
20 At this point this function just makes sure the ROOT batch mode is set
21 correctly when someone imports ROOT
22 """
23 from AthenaCommon.Logging import log
24 import builtins as builtin_mod
25 oldimporthook = builtin_mod.__import__
26 batch_mode = bool(batch)
27
28 def root6_importhook(name, globals={}, locals={}, fromlist=[], level=0):
29 nonlocal batch_mode
30 isroot = False
31 bm = batch_mode
32 if name=='ROOT' or (name[0:4]=='ROOT' and name!='ROOT.pythonization'):
33 isroot = True
34 batch_mode = None # only set it on first ROOT import
35
36 m = oldimporthook(name, globals, locals, fromlist, level)
37
38 if m and isroot:
39 log.debug('Python import module=%s, fromlist=%s', name, fromlist)
40 if bm is not None:
41 log.debug('Setting ROOT batch mode to %s', bm)
42 m.gROOT.SetBatch(bm)
43
44 return m
45
46 builtin_mod.__import__ = root6_importhook
47
48

◆ warnings_count()

List[str] python.Helpers.warnings_count ( Path file_name)
Run a WARNING helper function.

Definition at line 69 of file Tools/WorkflowTestRunner/python/Helpers.py.

69def warnings_count(file_name: Path) -> List[str]:
70 """Run a WARNING helper function."""
71 warnings = []
72 with file_name.open() as file:
73 for line in file:
74 if "WARNING" in line and "| WARNING |" not in line:
75 warnings.append(line)
76 return warnings