From 3cdab930c33e0b674c52e610d6ca9d6e003fa5ad Mon Sep 17 00:00:00 2001 From: scap3yvt <149599669+scap3yvt@users.noreply.github.com> Date: Wed, 1 Nov 2023 10:39:44 -0400 Subject: [PATCH 1/3] added cwd to make location explicit --- GANDLF/utils/modelio.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GANDLF/utils/modelio.py b/GANDLF/utils/modelio.py index 92f4a404f..8f05222c3 100644 --- a/GANDLF/utils/modelio.py +++ b/GANDLF/utils/modelio.py @@ -155,8 +155,9 @@ def save_model( model_dict["parameters"] = params try: + print("DEBUG os.getcwd():", os.getcwd()) model_dict["git_hash"] = ( - subprocess.check_output(["git", "rev-parse", "HEAD"]) + subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=os.getcwd()) .decode("ascii") .strip() ) From 39b2428543a2494a7d384f754fabe67397ea326c Mon Sep 17 00:00:00 2001 From: scap3yvt <149599669+scap3yvt@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:07:08 -0400 Subject: [PATCH 2/3] added another check --- GANDLF/utils/modelio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GANDLF/utils/modelio.py b/GANDLF/utils/modelio.py index 8f05222c3..8e719cb58 100644 --- a/GANDLF/utils/modelio.py +++ b/GANDLF/utils/modelio.py @@ -161,7 +161,7 @@ def save_model( .decode("ascii") .strip() ) - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, FileNotFoundError): model_dict["git_hash"] = None torch.save(model_dict, path) From b97fb050277b66633aae3bdd2a8add512291d45b Mon Sep 17 00:00:00 2001 From: scap3yvt <149599669+scap3yvt@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:47:24 -0400 Subject: [PATCH 3/3] remove print and added comment --- GANDLF/utils/modelio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GANDLF/utils/modelio.py b/GANDLF/utils/modelio.py index 8e719cb58..23556b206 100644 --- a/GANDLF/utils/modelio.py +++ b/GANDLF/utils/modelio.py @@ -155,14 +155,14 @@ def save_model( model_dict["parameters"] = params try: - print("DEBUG os.getcwd():", os.getcwd()) + # this will try to encode the git hash of the current GaNDLF codebase, and reverts to "None" if not found model_dict["git_hash"] = ( subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=os.getcwd()) .decode("ascii") .strip() ) except (subprocess.CalledProcessError, FileNotFoundError): - model_dict["git_hash"] = None + model_dict["git_hash"] = "None" torch.save(model_dict, path)