From 5c61e2391a8fb7400eae199e16cca84b65ee6cf7 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Sun, 24 Nov 2024 19:45:18 +0100 Subject: [PATCH] Update to DIMA package path resolution from file. --- src/hdf5_ops.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/hdf5_ops.py b/src/hdf5_ops.py index 21de1f0..e020216 100644 --- a/src/hdf5_ops.py +++ b/src/hdf5_ops.py @@ -1,7 +1,18 @@ 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 h5py import pandas as pd @@ -12,7 +23,6 @@ import src.hdf5_writer as hdf5_lib import logging import datetime -import os import h5py import yaml @@ -640,17 +650,20 @@ def read_mtable_as_dataframe(filename): return output_dataframe if __name__ == "__main__": - if len(sys.argv) < 4: - print("Usage: python hdf5_ops.py serialize ") + if len(sys.argv) < 5: + print("Usage: python hdf5_ops.py serialize ") sys.exit(1) if sys.argv[1] == 'serialize': input_hdf5_file = sys.argv[2] - file_format = sys.argv[3] + folder_depth = int(sys.argv[3]) + file_format = sys.argv[4] try: # Call the serialize_metadata function and capture the output path - path_to_file = serialize_metadata(input_hdf5_file, output_format=file_format) + path_to_file = serialize_metadata(input_hdf5_file, + folder_depth = folder_depth, + output_format=file_format) print(f"Metadata serialized to {path_to_file}") except Exception as e: print(f"An error occurred during serialization: {e}")