From ca314f971d4553fc178ccc3820178176070bf47b Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Sun, 24 Nov 2024 10:08:19 +0100 Subject: [PATCH] Add utility functions add_project_path_to_sys_path() to set up path to DIMA's modules dynamically. --- notebooks/nbutils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 notebooks/nbutils.py diff --git a/notebooks/nbutils.py b/notebooks/nbutils.py new file mode 100644 index 0000000..cf0bfa3 --- /dev/null +++ b/notebooks/nbutils.py @@ -0,0 +1,16 @@ +import sys +import os + +def add_project_path_to_sys_path(): + """ + Adds the project path (root directory containing the package) to sys.path. + """ + # Determine the root directory (project_root, which contains 'dima') + notebook_dir = os.getcwd() # Current working directory (assumes running from notebooks/) + project_path = os.path.normpath(os.path.join(notebook_dir, "..")) # Move up to project root + + if project_path not in sys.path: # Avoid duplicate entries + sys.path.append(project_path) + +if __name__ == "__main__": + add_project_path_to_sys_path() \ No newline at end of file