mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-18 19:09:17 +00:00
Python: switch to arg arrays for launch
Fixes Python when there are spaces in interpreter path
This commit is contained in:
parent
e741d46770
commit
3bdf82aea7
common
scripting
@ -284,7 +284,7 @@ void API_PLUGIN_MANAGER::InvokeAction( const wxString& aIdentifier )
|
||||
if( pythonHome )
|
||||
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
|
||||
|
||||
long pid = manager.Execute( pluginFile.GetFullPath(),
|
||||
long pid = manager.Execute( { pluginFile.GetFullPath() },
|
||||
[]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||
{
|
||||
wxLogTrace( traceApi,
|
||||
@ -495,10 +495,14 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
||||
env.env.erase( "PYTHONPATH" );
|
||||
}
|
||||
#endif
|
||||
std::vector<wxString> args = {
|
||||
"-m",
|
||||
"venv",
|
||||
"--system-site-packages",
|
||||
job.env_path
|
||||
};
|
||||
|
||||
manager.Execute(
|
||||
wxString::Format( wxS( "-m venv --system-site-packages \"%s\"" ),
|
||||
job.env_path ),
|
||||
manager.Execute( args,
|
||||
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||
{
|
||||
wxLogTrace( traceApi,
|
||||
@ -553,10 +557,15 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
||||
}
|
||||
#endif
|
||||
|
||||
wxString cmd = wxS( "-m pip install --upgrade pip" );
|
||||
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
|
||||
std::vector<wxString> args = {
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"--upgrade",
|
||||
"pip"
|
||||
};
|
||||
|
||||
manager.Execute( cmd,
|
||||
manager.Execute( args,
|
||||
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||
{
|
||||
wxLogTrace( traceApi, wxString::Format( "Manager: upgrade pip returned %d",
|
||||
@ -618,14 +627,22 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
||||
if( pythonHome )
|
||||
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
|
||||
|
||||
wxString cmd = wxString::Format(
|
||||
wxS( "-m pip install --no-input --isolated --only-binary :all: --require-virtualenv "
|
||||
"--exists-action i -r \"%s\"" ),
|
||||
reqs.GetFullPath() );
|
||||
std::vector<wxString> args = {
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"--no-input",
|
||||
"--isolated",
|
||||
"--only-binary",
|
||||
":all:",
|
||||
"--require-virtualenv",
|
||||
"--exists-action",
|
||||
"i",
|
||||
"-r",
|
||||
reqs.GetFullPath()
|
||||
};
|
||||
|
||||
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
|
||||
|
||||
manager.Execute( cmd,
|
||||
manager.Execute( args,
|
||||
[this, job]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||
{
|
||||
if( !aError.IsEmpty() )
|
||||
|
@ -136,7 +136,7 @@ void PANEL_PLUGIN_SETTINGS::validatePythonInterpreter()
|
||||
|
||||
PYTHON_MANAGER manager( pythonExe.GetFullPath() );
|
||||
|
||||
manager.Execute( wxS( "--version" ),
|
||||
manager.Execute( { wxS( "--version" ) },
|
||||
[&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
|
||||
{
|
||||
wxString msg;
|
||||
|
@ -90,7 +90,7 @@ PYTHON_MANAGER::PYTHON_MANAGER( const wxString& aInterpreterPath )
|
||||
}
|
||||
|
||||
|
||||
long PYTHON_MANAGER::Execute( const wxString& aArgs,
|
||||
long PYTHON_MANAGER::Execute( const std::vector<wxString>& aArgs,
|
||||
const std::function<void(int, const wxString&, const wxString&)>& aCallback,
|
||||
const wxExecuteEnv* aEnv, bool aSaveOutput )
|
||||
{
|
||||
@ -115,10 +115,19 @@ long PYTHON_MANAGER::Execute( const wxString& aArgs,
|
||||
}
|
||||
};
|
||||
|
||||
wxString cmd = wxString::Format( wxS( "%s %s" ), m_interpreterPath, aArgs );
|
||||
wxString argsStr;
|
||||
std::vector<const wchar_t*> args = { m_interpreterPath.wc_str() };
|
||||
|
||||
wxLogTrace( traceApi, wxString::Format( "Execute: %s", cmd ) );
|
||||
long pid = wxExecute( cmd, wxEXEC_ASYNC, process, aEnv );
|
||||
for( const wxString& arg : aArgs )
|
||||
{
|
||||
args.emplace_back( arg.wc_str() );
|
||||
argsStr << arg << " ";
|
||||
}
|
||||
|
||||
args.emplace_back( nullptr );
|
||||
|
||||
wxLogTrace( traceApi, wxString::Format( "Execute: %s %s", m_interpreterPath, argsStr ) );
|
||||
long pid = wxExecute( args.data(), wxEXEC_ASYNC, process, aEnv );
|
||||
|
||||
if( pid == 0 )
|
||||
{
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
* @param aSaveOutput
|
||||
* @return the process ID of the created process, or 0 if one was not created
|
||||
*/
|
||||
long Execute( const wxString& aArgs,
|
||||
long Execute( const std::vector<wxString>& aArgs,
|
||||
const std::function<void(int, const wxString&, const wxString&)>& aCallback,
|
||||
const wxExecuteEnv* aEnv = nullptr,
|
||||
bool aSaveOutput = false );
|
||||
|
Loading…
Reference in New Issue
Block a user