Repository: IAMconsortium/nomenclature

Issue:
Relative definition of path in Nomenclature
The relative definition of the `path` variable in the `__init__` of  `Nomenclature` `def __init__(self, path="definitions")` can lead to problems when the workflow where it is used is not started from the parent directory of `definitions`.

One possible fix would be to remove the default and require it to be set explicitly in every workflow in the following pattern:

`Nomenclature(Path(__file__).absolute().parent / "definitions").validate(df)`

Another fix would be checking if the directory specified in `path` actually exists and throw an error if it doesn't. Might also be a usecase for pydantic as it specifies an `FilePath` datatype which does this validation automatically (https://pydantic-docs.helpmanual.io/usage/types/#pydantic-types)

Discussion:

Patch:
diff --git a/nomenclature/core.py b/nomenclature/core.py
index 93180ed..cb40464 100644
--- a/nomenclature/core.py
+++ b/nomenclature/core.py
@@ -7,10 +7,13 @@ from nomenclature.validation import validate
 class Nomenclature:
     """A nomenclature with codelists for all dimensions used in the IAMC data format"""
 
-    def __init__(self, path="definitions"):
+    def __init__(self, path):
         if not isinstance(path, Path):
             path = Path(path)
 
+        if not path.is_dir():
+            raise NotADirectoryError(f"Definitions directory not found: {path}")
+
         self.variable = CodeList("variable").parse_files(path / "variables")
         self.region = CodeList("region").parse_files(
             path / "regions", top_level_attr="hierarchy"
diff --git a/nomenclature/validation.py b/nomenclature/validation.py
index ab04374..cefa394 100644
--- a/nomenclature/validation.py
+++ b/nomenclature/validation.py
@@ -1,5 +1,5 @@
 import logging
-from pyam import to_list
+from pyam import IamDataFrame, to_list
 
 # define logger for this script at logging level INFO
 logger = logging.getLogger(__name__)
@@ -19,6 +19,9 @@ def is_subset(x, y):
 def validate(nc, df):
     """Validation of an IamDataFrame against codelists of a Nomenclature"""
 
+    if not isinstance(df, IamDataFrame):
+        df = IamDataFrame(df)
+
     error = False
 
     # combined validation of variables and units
@@ -58,3 +61,5 @@ def validate(nc, df):
 
     if error:
         raise ValueError("The validation failed. Please check the log for details.")
+
+    return True


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
new file mode 100644
index 0000000..58e5d9c
--- /dev/null
+++ b/tests/test_core.py
@@ -0,0 +1,8 @@
+import pytest
+import nomenclature as nc
+
+
+def test_nonexisting_path_raises():
+    """Check that initializing a Nomenclature with a non-existing path raises"""
+    with pytest.raises(NotADirectoryError, match="Definitions directory not found: foo"):
+        nc.Nomenclature("foo")