From 4bef8c46c426db3675654889ed1d3adedacd4df6 Mon Sep 17 00:00:00 2001
From: Baptiste Bauvin <baptiste.bauvin@lis-lab.fr>
Date: Fri, 1 May 2020 09:02:15 -0400
Subject: [PATCH] Windows compatible paths

---
 docs/source/conf.py                               | 12 +++++++-----
 summit/multiview_platform/utils/configuration.py  |  8 +++++---
 summit/tests/test_exec_classif.py                 |  1 +
 .../test_mono_view/test_exec_classif_mono_view.py |  9 ++-------
 .../tests/test_multi_view/test_multiview_utils.py |  2 ++
 .../tests/test_result_analysis/test_execution.py  |  1 +
 .../test_tracebacks_analysis.py                   |  1 +
 summit/tests/test_utils/test_GetMultiviewDB.py    | 15 ++-------------
 summit/tests/test_utils/test_configuration.py     |  4 +---
 summit/tests/test_utils/test_execution.py         |  4 +++-
 summit/tests/utils.py                             |  2 +-
 11 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/docs/source/conf.py b/docs/source/conf.py
index 52905c53..f74697da 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -21,11 +21,13 @@
 import os
 import sys
 
+repo_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
 sys.path.insert(0, os.path.abspath('.'))
-sys.path.insert(0, os.path.abspath('../../summit'))
-sys.path.insert(0, os.path.abspath('../..'))
-file_loc = os.path.split(__file__)[0]
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(file_loc), '.')))
+sys.path.insert(0, os.path.join(repo_path, "summit'"))
+sys.path.insert(0, repo_path)
+
+# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(file_loc), '.')))
 # import summit
 # -- General configuration ------------------------------------------------
 
@@ -121,7 +123,7 @@ html_theme = 'classic'
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ["_static/"]
+html_static_path = ["_static"]
 
 # -- Options for HTMLHelp output ------------------------------------------
 
diff --git a/summit/multiview_platform/utils/configuration.py b/summit/multiview_platform/utils/configuration.py
index 4adefc4a..75bd4b02 100644
--- a/summit/multiview_platform/utils/configuration.py
+++ b/summit/multiview_platform/utils/configuration.py
@@ -2,8 +2,10 @@ import os
 
 import yaml
 
+package_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+print(package_path)
 
-def get_the_args(path_to_config_file="../config_files/config.yml"):
+def get_the_args(path_to_config_file=os.path.join(os.path.dirname(package_path), "config_files", "config.yml")):
     """
     The function for extracting the args for a '.yml' file.
 
@@ -27,7 +29,7 @@ def pass_default_config(log=True,
                         label="_",
                         file_type=".hdf5",
                         views=None,
-                        pathf="../data/",
+                        pathf=os.path.join(os.path.dirname(package_path), "data", ""),
                         nice=0,
                         random_state=42,
                         nb_cores=1,
@@ -35,7 +37,7 @@ def pass_default_config(log=True,
                         debug=False,
                         add_noise=False,
                         noise_std=0.0,
-                        res_dir="../results/",
+                        res_dir=os.path.join(os.path.dirname(package_path),"results", ""),
                         track_tracebacks=True,
                         split=0.49,
                         nb_folds=5,
diff --git a/summit/tests/test_exec_classif.py b/summit/tests/test_exec_classif.py
index 1696d720..4b3555bc 100644
--- a/summit/tests/test_exec_classif.py
+++ b/summit/tests/test_exec_classif.py
@@ -85,6 +85,7 @@ class Test_Functs(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
 
     @classmethod
diff --git a/summit/tests/test_mono_view/test_exec_classif_mono_view.py b/summit/tests/test_mono_view/test_exec_classif_mono_view.py
index 6388f630..ab1d9ce5 100644
--- a/summit/tests/test_mono_view/test_exec_classif_mono_view.py
+++ b/summit/tests/test_mono_view/test_exec_classif_mono_view.py
@@ -31,7 +31,7 @@ class Test_initConstants(unittest.TestCase):
                                       np.array([1, 3, 5, 7, 9])]
         cls.labels_names = ["test_true", "test_false"]
         cls.name = "test"
-        cls.directory = os.path.join(tmp_path, "test_dir/")
+        cls.directory = os.path.join(tmp_path, "test_dir", "")
 
     def test_simple(cls):
         kwargs, \
@@ -60,12 +60,7 @@ class Test_initConstants(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        os.remove(tmp_path + "test.hdf5")
-        os.rmdir(
-            tmp_path + "test_dir/test_clf/test_dataset")
-        os.rmdir(tmp_path + "test_dir/test_clf")
-        os.rmdir(tmp_path + "test_dir")
-        os.rmdir(tmp_path)
+        rm_tmp()
 
 
 class Test_initTrainTest(unittest.TestCase):
diff --git a/summit/tests/test_multi_view/test_multiview_utils.py b/summit/tests/test_multi_view/test_multiview_utils.py
index aae8a743..491d0134 100644
--- a/summit/tests/test_multi_view/test_multiview_utils.py
+++ b/summit/tests/test_multi_view/test_multiview_utils.py
@@ -27,6 +27,7 @@ class TestBaseMultiviewClassifier(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
 
     @classmethod
@@ -62,6 +63,7 @@ class TestFunctions(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
         cls.rs = np.random.RandomState(42)
 
diff --git a/summit/tests/test_result_analysis/test_execution.py b/summit/tests/test_result_analysis/test_execution.py
index b5c2ad4b..364009d9 100644
--- a/summit/tests/test_result_analysis/test_execution.py
+++ b/summit/tests/test_result_analysis/test_execution.py
@@ -113,6 +113,7 @@ class Test_analyze_iterations(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
         cls.results = [[0, [FakeClassifierResult(), FakeClassifierResult(i=2)], []], [
             1, [FakeClassifierResult(), FakeClassifierResult(i=2)], []]]
diff --git a/summit/tests/test_result_analysis/test_tracebacks_analysis.py b/summit/tests/test_result_analysis/test_tracebacks_analysis.py
index b1059d8a..5c78b443 100644
--- a/summit/tests/test_result_analysis/test_tracebacks_analysis.py
+++ b/summit/tests/test_result_analysis/test_tracebacks_analysis.py
@@ -31,6 +31,7 @@ class Test_funcs(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
         cls.res_file = open(os.path.join(tmp_path, "tmp.txt"), "w")
 
diff --git a/summit/tests/test_utils/test_GetMultiviewDB.py b/summit/tests/test_utils/test_GetMultiviewDB.py
index 2941c0ba..c825a272 100644
--- a/summit/tests/test_utils/test_GetMultiviewDB.py
+++ b/summit/tests/test_utils/test_GetMultiviewDB.py
@@ -98,7 +98,7 @@ class Test_get_classic_db_csv(unittest.TestCase):
         self.datas = []
         for i in range(4):
             data = self.random_state.randint(0, 100, (10, 20))
-            np.savetxt(self.pathF + "Views/test_view_" + str(i) + ".csv",
+            np.savetxt(os.path.join(self.pathF +"Views","test_view_" + str(i) + ".csv"),
                        data, delimiter=",")
             self.datas.append(data)
 
@@ -118,18 +118,7 @@ class Test_get_classic_db_csv(unittest.TestCase):
 
     @classmethod
     def tearDown(self):
-        for i in range(4):
-            os.remove(
-                tmp_path + "Views/test_view_" + str(
-                    i) + ".csv")
-        os.rmdir(tmp_path + "Views")
-        os.remove(
-            tmp_path + "test_dataset-labels-names.csv")
-        os.remove(tmp_path + "test_dataset-labels.csv")
-        os.remove(tmp_path + "test_dataset.hdf5")
-        os.remove(
-            tmp_path + "test_dataset_temp_filter.hdf5")
-        os.rmdir(tmp_path)
+        rm_tmp()
 
 
 class Test_get_plausible_db_hdf5(unittest.TestCase):
diff --git a/summit/tests/test_utils/test_configuration.py b/summit/tests/test_utils/test_configuration.py
index a43906dc..49a4f795 100644
--- a/summit/tests/test_utils/test_configuration.py
+++ b/summit/tests/test_utils/test_configuration.py
@@ -13,9 +13,7 @@ class Test_get_the_args(unittest.TestCase):
     def setUpClass(cls):
         rm_tmp()
         cls.path_to_config_file = tmp_path + "config_temp.yml"
-        path_file = os.path.dirname(os.path.abspath(__file__))
-        make_tmp_dir = os.path.join(path_file, "../tmp_tests")
-        os.mkdir(make_tmp_dir)
+        os.mkdir(tmp_path)
         data = {"log": 10, "name": [12.5, 1e-06], "type": True}
         with open(cls.path_to_config_file, "w") as config_file:
             yaml.dump(data, config_file)
diff --git a/summit/tests/test_utils/test_execution.py b/summit/tests/test_utils/test_execution.py
index f678dd4f..93c01cab 100644
--- a/summit/tests/test_utils/test_execution.py
+++ b/summit/tests/test_utils/test_execution.py
@@ -21,6 +21,7 @@ class Test_init_log_file(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
 
     @classmethod
@@ -135,6 +136,7 @@ class Test_find_dataset_names(unittest.TestCase):
 
     @classmethod
     def setUpClass(cls):
+        rm_tmp()
         os.mkdir(tmp_path)
         with open(os.path.join(tmp_path, "test.txt"), "w") as file_stream:
             file_stream.write("test")
@@ -154,7 +156,7 @@ class Test_find_dataset_names(unittest.TestCase):
         self.assertEqual(path, tmp_path)
         self.assertIn("test1", names)
         path, names = execution.find_dataset_names(
-            "examples/data", ".hdf5", ["all"])
+            os.path.join("examples","data"), ".hdf5", ["all"])
         self.assertIn("doc_summit", names)
         self.assertRaises(ValueError, execution.find_dataset_names, tmp_path + "test", ".txt",
                           ["test"])
diff --git a/summit/tests/utils.py b/summit/tests/utils.py
index ca4fe43a..5ce5d8d6 100644
--- a/summit/tests/utils.py
+++ b/summit/tests/utils.py
@@ -8,7 +8,7 @@ from ..multiview_platform.utils.dataset import HDF5Dataset
 tmp_path = os.path.join(
     os.path.dirname(
         os.path.abspath(__file__)),
-    "tmp_tests/")
+    "tmp_tests", "")
 # TODO Convert to ram dataset
 test_dataset = HDF5Dataset(
     hdf5_file=h5py.File(
-- 
GitLab