Skip to content

Commit b60a63b

Browse files
committed
use os.path.expand user for home directories for python (reintroduces fixes from #2515)
1 parent b44ae22 commit b60a63b

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/python/qgspythonutilsimpl.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,31 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
5858
runString( "import sys" ); // import sys module (for display / exception hooks)
5959
runString( "import os" ); // import os module (for user paths)
6060

61+
#ifdef Q_OS_WIN
62+
runString( "oldhome=None" );
63+
runString( "if os.environ.has_key('HOME'): oldhome=os.environ['HOME']" );
64+
runString( "os.environ['HOME']=os.environ['USERPROFILE']" );
65+
#endif
66+
6167
// construct a list of plugin paths
6268
// plugin dirs passed in QGIS_PLUGINPATH env. variable have highest priority (usually empty)
6369
// locally installed plugins have priority over the system plugins
64-
QStringList pluginpaths = extraPluginsPaths();
65-
pluginpaths << homePluginsPath() << pluginsPath();
70+
// use os.path.expanduser to support usernames with special characters (see #2512)
71+
QStringList pluginpaths;
72+
foreach( QString p, extraPluginsPaths() )
73+
{
74+
pluginpaths << '"' + p + '"';
75+
}
76+
pluginpaths << "os.path.expanduser(\"~/.qgis/python/plugins\")";
77+
pluginpaths << '"' + pluginsPath() + '"';
6678

6779
// expect that bindings are installed locally, so add the path to modules
6880
// also add path to plugins
6981
QStringList newpaths;
70-
newpaths << pythonPath() << homePythonPath();
71-
newpaths += pluginpaths;
72-
runString( "sys.path = [\"" + newpaths.join( "\", \"" ) + "\"] + sys.path" );
82+
newpaths << '"' + pythonPath() + '"';
83+
newpaths << "os.path.expanduser(\"~/.qgis/python\")";
84+
newpaths << pluginpaths;
85+
runString( "sys.path = [" + newpaths.join( "," ) + "] + sys.path" );
7386

7487
// import SIP
7588
if ( !runString( "from sip import wrapinstance, unwrapinstance",
@@ -104,7 +117,11 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
104117
}
105118

106119
// tell the utils script where to look for the plugins
107-
runString( "qgis.utils.plugin_paths = [\"" + pluginpaths.join( "\",\"" ) + "\"]" );
120+
runString( "qgis.utils.plugin_paths = [" + pluginpaths.join( "," ) + "]" );
121+
122+
#ifdef Q_OS_WIN
123+
runString( "if oldhome: os.environ['HOME']=oldhome" );
124+
#endif
108125

109126
// initialize 'iface' object
110127
runString( "qgis.utils.initInterface(" + QString::number(( unsigned long ) interface ) + ")" );

0 commit comments

Comments
 (0)