mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02: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
@ -284,7 +284,7 @@ void API_PLUGIN_MANAGER::InvokeAction( const wxString& aIdentifier )
|
|||||||
if( pythonHome )
|
if( pythonHome )
|
||||||
env.env[wxS( "VIRTUAL_ENV" )] = *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 )
|
[]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||||
{
|
{
|
||||||
wxLogTrace( traceApi,
|
wxLogTrace( traceApi,
|
||||||
@ -495,10 +495,14 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
|||||||
env.env.erase( "PYTHONPATH" );
|
env.env.erase( "PYTHONPATH" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
std::vector<wxString> args = {
|
||||||
|
"-m",
|
||||||
|
"venv",
|
||||||
|
"--system-site-packages",
|
||||||
|
job.env_path
|
||||||
|
};
|
||||||
|
|
||||||
manager.Execute(
|
manager.Execute( args,
|
||||||
wxString::Format( wxS( "-m venv --system-site-packages \"%s\"" ),
|
|
||||||
job.env_path ),
|
|
||||||
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||||
{
|
{
|
||||||
wxLogTrace( traceApi,
|
wxLogTrace( traceApi,
|
||||||
@ -553,10 +557,15 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxString cmd = wxS( "-m pip install --upgrade pip" );
|
std::vector<wxString> args = {
|
||||||
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
|
"-m",
|
||||||
|
"pip",
|
||||||
|
"install",
|
||||||
|
"--upgrade",
|
||||||
|
"pip"
|
||||||
|
};
|
||||||
|
|
||||||
manager.Execute( cmd,
|
manager.Execute( args,
|
||||||
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
[this]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||||
{
|
{
|
||||||
wxLogTrace( traceApi, wxString::Format( "Manager: upgrade pip returned %d",
|
wxLogTrace( traceApi, wxString::Format( "Manager: upgrade pip returned %d",
|
||||||
@ -618,14 +627,22 @@ void API_PLUGIN_MANAGER::processNextJob( wxCommandEvent& aEvent )
|
|||||||
if( pythonHome )
|
if( pythonHome )
|
||||||
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
|
env.env[wxS( "VIRTUAL_ENV" )] = *pythonHome;
|
||||||
|
|
||||||
wxString cmd = wxString::Format(
|
std::vector<wxString> args = {
|
||||||
wxS( "-m pip install --no-input --isolated --only-binary :all: --require-virtualenv "
|
"-m",
|
||||||
"--exists-action i -r \"%s\"" ),
|
"pip",
|
||||||
reqs.GetFullPath() );
|
"install",
|
||||||
|
"--no-input",
|
||||||
|
"--isolated",
|
||||||
|
"--only-binary",
|
||||||
|
":all:",
|
||||||
|
"--require-virtualenv",
|
||||||
|
"--exists-action",
|
||||||
|
"i",
|
||||||
|
"-r",
|
||||||
|
reqs.GetFullPath()
|
||||||
|
};
|
||||||
|
|
||||||
wxLogTrace( traceApi, "Manager: calling python %s", cmd );
|
manager.Execute( args,
|
||||||
|
|
||||||
manager.Execute( cmd,
|
|
||||||
[this, job]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
[this, job]( int aRetVal, const wxString& aOutput, const wxString& aError )
|
||||||
{
|
{
|
||||||
if( !aError.IsEmpty() )
|
if( !aError.IsEmpty() )
|
||||||
|
@ -136,7 +136,7 @@ void PANEL_PLUGIN_SETTINGS::validatePythonInterpreter()
|
|||||||
|
|
||||||
PYTHON_MANAGER manager( pythonExe.GetFullPath() );
|
PYTHON_MANAGER manager( pythonExe.GetFullPath() );
|
||||||
|
|
||||||
manager.Execute( wxS( "--version" ),
|
manager.Execute( { wxS( "--version" ) },
|
||||||
[&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
|
[&]( int aRetCode, const wxString& aStdOut, const wxString& aStdErr )
|
||||||
{
|
{
|
||||||
wxString msg;
|
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 std::function<void(int, const wxString&, const wxString&)>& aCallback,
|
||||||
const wxExecuteEnv* aEnv, bool aSaveOutput )
|
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 ) );
|
for( const wxString& arg : aArgs )
|
||||||
long pid = wxExecute( cmd, wxEXEC_ASYNC, process, aEnv );
|
{
|
||||||
|
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 )
|
if( pid == 0 )
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,7 @@ public:
|
|||||||
* @param aSaveOutput
|
* @param aSaveOutput
|
||||||
* @return the process ID of the created process, or 0 if one was not created
|
* @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 std::function<void(int, const wxString&, const wxString&)>& aCallback,
|
||||||
const wxExecuteEnv* aEnv = nullptr,
|
const wxExecuteEnv* aEnv = nullptr,
|
||||||
bool aSaveOutput = false );
|
bool aSaveOutput = false );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user