Преглед на файлове

make root folder detection more flexible

Johannes Gütschow преди 2 месеца
родител
ревизия
8659ce2fc8
променени са 3 файла, в които са добавени 32 реда и са изтрити 27 реда
  1. 1 1
      src/unfccc_ghg_data/__init__.py
  2. 19 19
      src/unfccc_ghg_data/helper/__init__.py
  3. 12 7
      src/unfccc_ghg_data/helper/definitions.py

+ 1 - 1
src/unfccc_ghg_data/__init__.py

@@ -19,10 +19,10 @@ from . import (
 
 __all__ = [
     "helper",
-    "unfccc_reader",
     "unfccc_crf_reader",
     "unfccc_di_reader",
     "unfccc_downloader",
+    "unfccc_reader",
 ]
 
 __version__ = importlib.metadata.version("unfccc_ghg_data")

+ 19 - 19
src/unfccc_ghg_data/helper/__init__.py

@@ -39,32 +39,32 @@ from .functions import (
 )
 
 __all__ = [
-    "root_path",
+    "AI_countries",
+    "GWP_factors",
+    "all_countries",
     "code_path",
-    "log_path",
-    "extracted_data_path",
-    "extracted_data_path_UNFCCC",
-    "legacy_data_path",
-    "downloaded_data_path",
-    "downloaded_data_path_UNFCCC",
-    "dataset_path",
-    "dataset_path_UNFCCC",
+    "compression",
+    "convert_categories",
+    "create_folder_mapping",
     "custom_country_mapping",
     "custom_folders",
-    "GWP_factors",
+    "dataset_path",
+    "dataset_path_UNFCCC",
+    "downloaded_data_path",
+    "downloaded_data_path_UNFCCC",
+    "extracted_data_path",
+    "extracted_data_path_UNFCCC",
+    "fix_rows",
     "gas_baskets",
+    "get_code_file",
     "get_country_code",
     "get_country_name",
-    "convert_categories",
-    "create_folder_mapping",
-    "process_data_for_country",
-    "fix_rows",
-    "get_code_file",
-    "compression",
-    "make_wide_table",
+    "legacy_data_path",
+    "log_path",
     "make_long_table",
+    "make_wide_table",
     "nAI_countries",
-    "AI_countries",
-    "all_countries",
+    "process_data_for_country",
+    "root_path",
     "set_to_nan_in_ds",
 ]

+ 12 - 7
src/unfccc_ghg_data/helper/definitions.py

@@ -1,5 +1,6 @@
 """definitions like folders, mappings etc."""
 
+import os
 from pathlib import Path
 
 import pandas as pd
@@ -26,13 +27,17 @@ def get_root_path(root_indicator: str = ".datalad") -> Path:
     ------
         RuntimeError: If the repository root cannot be found.
     """
-    current_dir = Path(__file__).resolve().parent
-    while current_dir != Path(current_dir.root):
-        if (current_dir / root_indicator).exists():
-            return current_dir
-        current_dir = current_dir.parent
-    msg = f"Repository root with indicator '{root_indicator}' not found."
-    raise RuntimeError(msg)
+    root_path_env = os.getenv("UNFCCC_GHG_ROOT_PATH", None)
+    if root_path_env is None:
+        current_dir = Path(__file__).resolve().parent
+        while current_dir != Path(current_dir.root):
+            if (current_dir / root_indicator).exists():
+                return current_dir
+            current_dir = current_dir.parent
+        msg = f"Repository root with indicator '{root_indicator}' not found."
+        raise RuntimeError(msg)
+    else:
+        return Path(root_path_env).resolve()
 
 
 # def get_root_path() -> Path: