diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 495af4364b5743a75184335de0575b087f4ecdc5..b3b4da2add905eba42bae758ebbcac5fa9c4026a 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -556,8 +556,8 @@ def record_script_execution_summary( ) -> None: """Log the command used to build the package_set. - It also logs information about the mpsd-software-manager repository branch, the - spack-environments branch, and the commit hashes of each. It also logs + It also logs information about the spack-environments branch and commit hash, + as well as the version of the mpsd-software-manager user. It also logs steps taken in the install process using the optional message argument. Parameters @@ -582,10 +582,9 @@ def record_script_execution_summary( """ # Write to the log file with the following format # -------------------------------------------------- - # 2023-02-29T23:32:01, install-software-environment.py --release 23b --install ALL - # Software environment installer branch: script_branch (commit hash: \ - # script_commit_hash) - # Spack environments branch: dev-23a (commit hash: spe_commit_hash) + # 2023-06-20T15:30:37.965370, mpsd_software prepare dev-23a + # MPSD Software manager version: 2023.6.16 + # Spack environments branch: dev-23a (commit hash: abcdefg) # MSGs with os_chdir(root_dir): with open(config_vars["cmd_log_file"], "a") as f: @@ -599,40 +598,14 @@ def record_script_execution_summary( # Gather data to log # call statement: cmd_line = " ".join(sys.argv) - # script branch and commit hash - with os_chdir(root_dir): - try: - script_branch = ( - run( - ["git", "rev-parse", "--abbrev-ref", "HEAD"], - stdout=subprocess.PIPE, - check=True, - ) - .stdout.decode() - .strip() - ) - script_commit_hash = ( - run( - ["git", "rev-parse", "--short", "HEAD"], - stdout=subprocess.PIPE, - check=True, - ) - .stdout.decode() - .strip() - ) - except subprocess.CalledProcessError: - script_branch = "unknown" - script_commit_hash = "unknown" # spack-environments branch and commit hash from kwargs spe_branch = kwargs.get("spe_branch", None) spe_commit_hash = kwargs.get("spe_commit_hash", None) # Write to log file f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n") - f.write( - f"Software environment installer branch: {script_branch} " - f"(commit hash: {script_commit_hash})\n" - ) + # logs script version + f.write(f"MPSD Software manager version: {__version__}\n") f.write( f"Spack environments branch: {spe_branch} " f"(commit hash: {spe_commit_hash})\n" diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 6c9c8824b35d9dfc31b9109977708fb18d797cd7..6efde257bc6818fcbc2c87ea2688a19d11731d82 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -169,6 +169,7 @@ def test_record_script_execution_summary(tmp_path): root_dir = tmp_path / "test_prepare_env" mpsd_release_to_test = "dev-23a" + script_version = mod.__version__ if os.path.exists(root_dir / cmd_log_file): initial_bytes = os.path.getsize(cmd_log_file) else: @@ -184,8 +185,9 @@ def test_record_script_execution_summary(tmp_path): # Check that the log file has "Spack environments branch: dev-23a " in the last line with open(root_dir / cmd_log_file, "r") as f: - last_line = f.readlines()[-1] - assert "Spack environments branch: releases/dev-23a" in last_line + lines = f.readlines() + assert "Spack environments branch: releases/dev-23a " in lines[-1] + assert f"MPSD Software manager version: {script_version}" in lines[-2] def test_install_environment_wrong_package_set(tmp_path):