Skip to content

Commit 3bdf82a

Browse files
committed
Python: switch to arg arrays for launch
Fixes Python when there are spaces in interpreter path
1 parent e741d46 commit 3bdf82a

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

common/api/api_plugin_manager.cpp

+33-16
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void API_PLUGIN_MANAGER::InvokeAction( const wxString& aIdentifier )
284284
if( pythonHome )
285285
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
286286

287-
long pid = manager.Execute( pluginFile.GetFullPath(),
287+
long pid = manager.Execute( { pluginFile.GetFullPath() },
288288
[]( int aRetVal, const wxString& aOutput, const wxString& aError )
289289
{
290290
wxLogTrace( traceApi,
@@ -495,10 +495,14 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
495495
env.env.erase( "PYTHONPATH" );
496496
}
497497
#endif
498-
499-
manager.Execute(
500-
wxString::Format( wxS( "-m venv --system-site-packages \"%s\"" ),
501-
job.env_path ),
498+
std::vector<wxString> args = {
499+
"-m",
500+
"venv",
501+
"--system-site-packages",
502+
job.env_path
503+
};
504+
505+
manager.Execute( args,
502506
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
503507
{
504508
wxLogTrace( traceApi,
@@ -553,10 +557,15 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
553557
}
554558
#endif
555559

556-
wxString cmd = wxS( "-m pip install --upgrade pip" );
557-
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
560+
std::vector<wxString> args = {
561+
"-m",
562+
"pip",
563+
"install",
564+
"--upgrade",
565+
"pip"
566+
};
558567

559-
manager.Execute( cmd,
568+
manager.Execute( args,
560569
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
561570
{
562571
wxLogTrace( traceApi, wxString::Format( "Manager: upgrade pip returned %d",
@@ -618,14 +627,22 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
618627
if( pythonHome )
619628
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
620629

621-
wxString cmd = wxString::Format(
622-
wxS( "-m pip install --no-input --isolated --only-binary :all: --require-virtualenv "
623-
"--exists-action i -r \"%s\"" ),
624-
reqs.GetFullPath() );
625-
626-
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
627-
628-
manager.Execute( cmd,
630+
std::vector<wxString> args = {
631+
"-m",
632+
"pip",
633+
"install",
634+
"--no-input",
635+
"--isolated",
636+
"--only-binary",
637+
":all:",
638+
"--require-virtualenv",
639+
"--exists-action",
640+
"i",
641+
"-r",
642+
reqs.GetFullPath()
643+
};
644+
645+
manager.Execute( args,
629646
[this, job]( int aRetVal, const wxString& aOutput, const wxString& aError )
630647
{
631648
if( !aError.IsEmpty() )

common/dialogs/panel_plugin_settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void PANEL_PLUGIN_SETTINGS::validatePythonInterpreter()
136136

137137
PYTHON_MANAGER manager( pythonExe.GetFullPath() );
138138

139-
manager.Execute( wxS( "--version" ),
139+
manager.Execute( { wxS( "--version" ) },
140140
[&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
141141
{
142142
wxString msg;

scripting/python_manager.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PYTHON_MANAGER::PYTHON_MANAGER( const wxString& aInterpreterPath )
9090
}
9191

9292

93-
long PYTHON_MANAGER::Execute( const wxString& aArgs,
93+
long PYTHON_MANAGER::Execute( const std::vector<wxString>& aArgs,
9494
const std::function<void(int, const wxString&, const wxString&)>& aCallback,
9595
const wxExecuteEnv* aEnv, bool aSaveOutput )
9696
{
@@ -115,10 +115,19 @@ long PYTHON_MANAGER::Execute( const wxString& aArgs,
115115
}
116116
};
117117

118-
wxString cmd = wxString::Format( wxS( "%s %s" ), m_interpreterPath, aArgs );
118+
wxString argsStr;
119+
std::vector<const wchar_t*> args = { m_interpreterPath.wc_str() };
119120

120-
wxLogTrace( traceApi, wxString::Format( "Execute: %s", cmd ) );
121-
long pid = wxExecute( cmd, wxEXEC_ASYNC, process, aEnv );
121+
for( const wxString& arg : aArgs )
122+
{
123+
args.emplace_back( arg.wc_str() );
124+
argsStr << arg << " ";
125+
}
126+
127+
args.emplace_back( nullptr );
128+
129+
wxLogTrace( traceApi, wxString::Format( "Execute: %s %s", m_interpreterPath, argsStr ) );
130+
long pid = wxExecute( args.data(), wxEXEC_ASYNC, process, aEnv );
122131

123132
if( pid == 0 )
124133
{

scripting/python_manager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class KICOMMON_API PYTHON_MANAGER
4242
* @param aSaveOutput
4343
* @return the process ID of the created process, or 0 if one was not created
4444
*/
45-
long Execute( const wxString& aArgs,
45+
long Execute( const std::vector<wxString>& aArgs,
4646
const std::function<void(int, const wxString&, const wxString&)>& aCallback,
4747
const wxExecuteEnv* aEnv = nullptr,
4848
bool aSaveOutput = false );

0 commit comments

Comments
 (0)