22 """Version of a library, from the version header installed with it.
24 The library is the loaded one, or the one that would be loaded if it is not
25 loaded yet. The header is next to the library's lib/ directory: in include/
26 of an install prefix (conda, cmake --install), or at the top of a build
32 prefix = os.path.dirname(os.path.dirname(path))
33 for candidate
in (os.path.join(prefix,
"include", header), os.path.join(prefix, header)):
34 with contextlib.suppress(OSError):
35 with open(candidate)
as f:
36 macros = dict(re.findall(
r'#define\s+(\w+)\s+"([^"]*)"', f.read()))
37 version = macros.get(version_macro)
40 git = macros.get(git_macro)
41 return f
"{version} ({git})" if git
else version
46 """Record the versions this run uses, dropping any it cannot determine.
48 FairShip is the Python source (FAIRSHIP_HASH from aliBuild, else its git
49 commit), FairShipLibrary the compiled libraries, which differ from it when
50 they come from the conda package.
52 versions = {
"FairShip":
None}
53 if "FAIRSHIP_HASH" in os.environ:
54 versions[
"FairShip"] = os.environ[
"FAIRSHIP_HASH"]
56 source_dir = os.environ.get(
"FAIRSHIP", os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
57 with contextlib.suppress(subprocess.CalledProcessError, FileNotFoundError):
58 versions[
"FairShip"] = subprocess.check_output(
59 [
"git",
"-C", source_dir,
"rev-parse",
"HEAD"],
61 stderr=subprocess.DEVNULL,
64 "libShipData",
"FairShipVersion.h",
"FAIRSHIP_VERSION",
"FAIRSHIP_GIT_HASH"
67 "libBase",
"FairVersion.h",
"FAIRROOT_VERSION",
"FAIRROOT_GIT_VERSION"
69 for key, version
in versions.items():