ATLAS Offline Software
Tools/WorkflowTestRunner/python/Helpers.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 from glob import glob
3 from logging import Logger
4 from os import environ, path
5 from pathlib import Path
6 from typing import List
7 
8 
9 def 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 
41 def 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 
69 def 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
python.Helpers.get_release_setup
str get_release_setup(Logger logger, no_setup=False)
Definition: Tools/WorkflowTestRunner/python/Helpers.py:9
python.Helpers.list_changed_packages
None list_changed_packages(Logger logger, no_setup=False)
Definition: Tools/WorkflowTestRunner/python/Helpers.py:41
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.Helpers.warnings_count
List[str] warnings_count(Path file_name)
Definition: Tools/WorkflowTestRunner/python/Helpers.py:69