From 1b2b319295ccce6a21db7e18593fd902c724dab2 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Sun, 24 Nov 2024 17:37:38 +0100 Subject: [PATCH] Attempt to dynamically resolve path to dima package, when excecuted from command line. --- pipelines/data_integration.py | 14 ++++++++++++-- pipelines/metadata_revision.py | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pipelines/data_integration.py b/pipelines/data_integration.py index af0c2cc..aaf49a4 100644 --- a/pipelines/data_integration.py +++ b/pipelines/data_integration.py @@ -1,7 +1,17 @@ import sys import os -root_dir = os.path.abspath(os.curdir) -sys.path.append(root_dir) + +try: + thisFilePath = os.path.abspath(__file__) +except NameError: + print("Error: __file__ is not available. Ensure the script is being run from a file.") + print("[Notice] Path to DIMA package may not be resolved properly.") + thisFilePath = os.getcwd() # Use current directory or specify a default + +dimaPath = os.path.normpath(os.path.join(thisFilePath, "..",'..')) # Move up to project root + +if dimaPath not in sys.path: # Avoid duplicate entries + sys.path.append(dimaPath) import yaml diff --git a/pipelines/metadata_revision.py b/pipelines/metadata_revision.py index c22deb3..363243e 100644 --- a/pipelines/metadata_revision.py +++ b/pipelines/metadata_revision.py @@ -1,8 +1,17 @@ import sys import os -# Add the parent directory to the system path -sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +try: + thisFilePath = os.path.abspath(__file__) +except NameError: + print("Error: __file__ is not available. Ensure the script is being run from a file.") + print("[Notice] Path to DIMA package may not be resolved properly.") + thisFilePath = os.getcwd() # Use current directory or specify a default + +dimaPath = os.path.normpath(os.path.join(thisFilePath, "..",'..')) # Move up to project root + +if dimaPath not in sys.path: # Avoid duplicate entries + sys.path.append(dimaPath) import h5py import yaml