From 4f68c8c629c936628416e1422489ca9dc9c74b70 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Tue, 20 Jun 2023 15:28:31 +0200 Subject: [PATCH 1/4] update docs --- src/mpsd_software_manager/mpsd_software.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index c9e5055..3b4653b 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -554,8 +554,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 -- GitLab From 502145807eb138d4a567fe99ba7809a413121273 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Tue, 20 Jun 2023 15:32:16 +0200 Subject: [PATCH 2/4] update log message --- src/mpsd_software_manager/mpsd_software.py | 35 ++++------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 3b4653b..92e3f8a 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -580,10 +580,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, src/mpsd_software_manager/mpsd_software.py prepare dev-23a + # MPSD Software manager version: 2023.6.16 + # Spack environments branch: dev-23a (commit hash: 8eac43476b2fd9a3a044f5562f3f7c2bccfe384a) # MSGs with os_chdir(root_dir): with open(config_vars["cmd_log_file"], "a") as f: @@ -597,39 +596,15 @@ 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") + # logs script version f.write( - f"Software environment installer branch: {script_branch} " - f"(commit hash: {script_commit_hash})\n" + f"MPSD Software manager version: {__version__}\n" ) f.write( f"Spack environments branch: {spe_branch} " -- GitLab From f7e78df048916c8c81ad85eac184596c17708e1f Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Tue, 20 Jun 2023 15:36:20 +0200 Subject: [PATCH 3/4] add test to check that version is logged --- tests/test_mpsd_software.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_mpsd_software.py b/tests/test_mpsd_software.py index 6c6c713..f4564df 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,10 @@ 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: dev-23a " in last_line + lines = f.readlines() + assert "Spack environments branch: 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): -- GitLab From 48ba40892d6739494ebd8ff932a9b8d3575dfb98 Mon Sep 17 00:00:00 2001 From: iamashwin99 <ashwin-kumar.karnad@mpsd.mpg.de> Date: Tue, 20 Jun 2023 15:38:23 +0200 Subject: [PATCH 4/4] black and reduce line length in comments --- src/mpsd_software_manager/mpsd_software.py | 10 ++++------ tests/test_mpsd_software.py | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py index 92e3f8a..21f026a 100755 --- a/src/mpsd_software_manager/mpsd_software.py +++ b/src/mpsd_software_manager/mpsd_software.py @@ -580,9 +580,9 @@ def record_script_execution_summary( """ # Write to the log file with the following format # -------------------------------------------------- - # 2023-06-20T15:30:37.965370, src/mpsd_software_manager/mpsd_software.py prepare dev-23a - # MPSD Software manager version: 2023.6.16 - # Spack environments branch: dev-23a (commit hash: 8eac43476b2fd9a3a044f5562f3f7c2bccfe384a) + # 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: @@ -603,9 +603,7 @@ def record_script_execution_summary( # Write to log file f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n") # logs script version - f.write( - f"MPSD Software manager version: {__version__}\n" - ) + 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 f4564df..3322401 100644 --- a/tests/test_mpsd_software.py +++ b/tests/test_mpsd_software.py @@ -190,7 +190,6 @@ def test_record_script_execution_summary(tmp_path): assert f"MPSD Software manager version: {script_version}" in lines[-2] - def test_install_environment_wrong_package_set(tmp_path): """Test exception is raised for non-existing package_set.""" # exits with exit code 1 when wrong package_sets are provided -- GitLab