""" Module finder helper for Alembic migrations in containerized environments. """ import sys from pathlib import Path def setup_python_path(): """ Add necessary paths to Python's sys.path to make imports work in various environments including Docker containers """ # Get the directory where this script is located current_dir = Path(__file__).resolve().parent # The project root is one level up from the 'alembic' directory project_root = current_dir.parent # Add the project root to the Python path if it's not already there if str(project_root) not in sys.path: sys.path.insert(0, str(project_root)) # Check if we're in a Docker container with code mounted at /app/repo repo_path = Path('/app/repo') if repo_path.exists() and str(repo_path) not in sys.path: sys.path.insert(0, str(repo_path)) # Return the actual Python paths used, for debugging return sys.path