From 97f043d8511554dc5fa729c9c37c0f0ccbe08980 Mon Sep 17 00:00:00 2001
From: Anil Tuncel <anil.tuncel@epfl.ch>
Date: Mon, 29 Aug 2022 17:45:45 +0300
Subject: [PATCH] allow prepare-step to be rerun without deleting /tmp
 explicitly

---
 bluepymm/prepare_combos/prepare_emodel_dirs.py | 3 +++
 tests/test_prepare_emodel_dirs.py              | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/bluepymm/prepare_combos/prepare_emodel_dirs.py b/bluepymm/prepare_combos/prepare_emodel_dirs.py
index 4602f15..60a4651 100644
--- a/bluepymm/prepare_combos/prepare_emodel_dirs.py
+++ b/bluepymm/prepare_combos/prepare_emodel_dirs.py
@@ -90,6 +90,9 @@ def convert_emodel_input(emodels_in_repo, conf_dict, continu):
             with tools.cd(tmp_emodels_dir):
                 sh.git('checkout', conf_dict['emodels_githash'])
         else:
+            if (os.path.exists(tmp_emodels_dir)
+               and os.path.isdir(tmp_emodels_dir)):
+                shutil.rmtree(tmp_emodels_dir)
             shutil.copytree(conf_dict['emodels_dir'], tmp_emodels_dir)
     return tmp_emodels_dir
 
diff --git a/tests/test_prepare_emodel_dirs.py b/tests/test_prepare_emodel_dirs.py
index fedb4f7..b9870d7 100644
--- a/tests/test_prepare_emodel_dirs.py
+++ b/tests/test_prepare_emodel_dirs.py
@@ -82,7 +82,10 @@ def test_convert_emodel_input_dir():
     continu = False
     _test_convert_emodel_input(TEST_DATA_DIR, emodels_in_repo, conf_dict,
                                continu)
-
+    # the second run is to make sure that the tmp_dir gets deleted and recopied
+    # in the consecutive runs
+    _test_convert_emodel_input(TEST_DATA_DIR, emodels_in_repo, conf_dict,
+                               continu)
 
 # TODO : how to do the test below?
 # @pytest.mark.unit
-- 
GitLab