Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add support for PYTHONSTARTUP-like environment variable, PYQGIS_STARTUP
- Different than user's 'startup.py,' since it is loaded just after Py_Initialize, specifically from env variable
- Useful for cleaning sys.path, e.g. isolating/loading the initial environ without requiring a virt env, like homebrew or MacPorts installs on Mac
  • Loading branch information
dakcarto committed Sep 24, 2013
1 parent 3fce4a5 commit 4c1b95b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -61,6 +61,14 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
runString( "import sys" ); // import sys module (for display / exception hooks)
runString( "import os" ); // import os module (for user paths)

// support for PYTHONSTARTUP-like environment variable: PYQGIS_STARTUP
// (unlike PYTHONHOME and PYTHONPATH, PYTHONSTARTUP is not supported for embedded interpreter by default)
// this is different than user's 'startup.py' (below), since it is loaded just after Py_Initialize
// it is very useful for cleaning sys.path, which may have undesireable paths, or for
// isolating/loading the initial environ without requiring a virt env, e.g. homebrew or MacPorts installs on Mac
runString( "pyqgstart = os.getenv('PYQGIS_STARTUP')\n" );
runString( "if pyqgstart is not None and os.path.exists(pyqgstart): execfile(pyqgstart)\n" );

#ifdef Q_OS_WIN
runString( "oldhome=None" );
runString( "if os.environ.has_key('HOME'): oldhome=os.environ['HOME']\n" );
Expand Down

0 comments on commit 4c1b95b

Please sign in to comment.