Add utility functions add_project_path_to_sys_path() to set up path to DIMA's modules dynamically.

This commit is contained in:
2024-11-24 10:08:19 +01:00
parent a928c4ef4c
commit ca314f971d

16
notebooks/nbutils.py Normal file
View File

@ -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()