tarbell-project/tarbell

Python modules in project root

eyeseast opened this issue · 0 comments

In a recent project, I have a Python file in my project directory that gets imported in tarbell_config.py:

from flask import Blueprint, g
from tarbell.oauth import get_drive_api

from gdoc import DocumentSource

I have gdoc.py in the same directory as tarbell_config.py. I can import it, but another member of my team cloned the repo and hit an import error when running tarbell serve from that directory. I've run into this before, and it's easy enough to resolve by adding the project root to sys.path:

import os
import sys

# do this before importing gdoc
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
sys.path.append(PROJECT_ROOT)

from flask import Blueprint, g
from tarbell.oauth import get_drive_api

from gdoc import DocumentSource

But it's another step, and it's a pain, and it's not documented. So, I think the best solution is adding directory containing tarbell_config.py to sys.path in TarbellSite.load_project, but I haven't tried this yet. (Some part of the problem seems to depend on how you organize virtual environments, so that's another little complication.) This would make adding extra Python files more seamless.