Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python modules in project root #427

Open
eyeseast opened this issue May 31, 2016 · 0 comments
Open

Python modules in project root #427

eyeseast opened this issue May 31, 2016 · 0 comments
Labels
Milestone

Comments

@eyeseast
Copy link
Contributor

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.

@eyeseast eyeseast added this to the 2.0 milestone May 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant