Repository: deltares/hydromt
Issue: values in [setup_config] section of ini files not evaluated

This bug originates in PR https://github.com/Deltares/hydromt/pull/246

The required behaviour is that only paths in setup_config are not evaluate and changed into absolute paths by default. Other python objects should be evaluated. 

Suggested solution: Distinguish between the `skip_eval_sections` (`[]` by default) and a new `skip_abspath_sections` optional argument (`['setup_config']` by default) in configread.

this fixes https://github.com/Deltares/hydromt_wflow/issues/151

Changed files:
hydromt/cli/cli_utils.py, hydromt/config.py, tests/test_config.py

diff --git a/hydromt/cli/cli_utils.py b/hydromt/cli/cli_utils.py
index d03e069..cad287a 100644
--- a/hydromt/cli/cli_utils.py
+++ b/hydromt/cli/cli_utils.py
@@ -79,7 +79,7 @@ def parse_config(path: Union[Path, str] = None, opt_cli: Dict = None) -> Dict:
     opt = {}
     if path is not None and isfile(path):
         opt = config.configread(
-            path, abs_path=True, skip_eval_sections=["setup_config"]
+            path, abs_path=True, skip_abspath_sections=["setup_config"]
         )
     elif path is not None:
         raise IOError(f"Config not found at {path}")
diff --git a/hydromt/config.py b/hydromt/config.py
index 1bd270b..6eec12f 100644
--- a/hydromt/config.py
+++ b/hydromt/config.py
@@ -22,7 +22,8 @@ def configread(
     noheader: bool = False,
     abs_path: bool = False,
     skip_eval: bool = False,
-    skip_eval_sections: List = ["setup_config"],
+    skip_eval_sections: List = [],
+    skip_abspath_sections: List = ["setup_config"],
 ) -> Dict:
     """Read configuration file and parse to (nested) dictionary.
     Values are evaluated and if possible parsed into python int, float, list or boolean types.
@@ -46,6 +47,9 @@ def configread(
         Skip evaluating argument values for python types, by default False
     skip_eval_sections: list, optional
         These sections are not evaluated for python types or absolute paths
+        if abs_path=True, by default []
+    skip_abspath_sections: list, optional
+        These sections are not evaluated for absolute paths
         if abs_path=True, by default ['update_config']
 
     Returns
@@ -78,7 +82,7 @@ def configread(
                 pass
             if isinstance(value, str) and len(value) == 0:
                 value = None
-            if abs_path:
+            if abs_path and section not in skip_abspath_sections:
                 if isinstance(value, str) and exists(join(root, value)):
                     value = Path(abspath(join(root, value)))
                 elif (
diff --git a/tests/test_config.py b/tests/test_config.py
index 36eed83..30a21a2 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -30,5 +30,13 @@ def test_config(tmpdir):
     assert cfdict["section1"] == cfdict1["section1"]
     assert isinstance(cfdict1["section2"]["path"], Path)
     assert isinstance(cfdict1["section2"]["path1"], str)
+    # by default paths in setup_config are not evaluated
     assert isinstance(cfdict1["setup_config"]["path"], str)
+    assert isinstance(cfdict1["setup_config"]["float"], float)
+    # return only str if skip_eval=True
+    cfdict1 = config.configread(config_fn, skip_eval=True)
+    for section in cfdict1:
+        assert all([isinstance(val, str) for val in cfdict1[section].values()])
+    # do not evaluate a specific section
+    cfdict1 = config.configread(config_fn, skip_eval_sections=["setup_config"])
     assert isinstance(cfdict1["setup_config"]["float"], str)