My friend mentioned that he had a python session on his desktop that he never dared to close, since the setup had been so much trouble.
Thinking that it would be great to have this more frequently, and more easily, I created a python file which gets loaded every time I start my python interpreter, pyprompt.py.
projects = os.path.join(os.environ['HOME'], "projects")
if os.path.dirname(d) in ['/home', '/']:
elif projects == os.path.dirname(d):
if os.path.exists(os.path.join(d, "src/pylons/proj")):
pd = getProjectDir()
print "Detected %s project. Setting up database." %(os.path.basename(pd))
from proj.lib.helpers import setup_db
factory = setup_db()
dbcon = factory.getConnection()
Now I want this file to run every time the python interpreter is started.
So, what happens is, when the python interpreter starts, it checks the PYTHONSTARTUP variable for a python file to run. That executes the getProjectDir() function, which tests if my current working directory is in a project. (Our workflow includes many branches of the main project.) If I am in a project, it will import the files from that project and setup my interpreter, ready for some interactive work.