KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PYTHON_MANAGER Class Reference

#include <python_manager.h>

Public Member Functions

 PYTHON_MANAGER (const wxString &aInterpreterPath)
 
long Execute (const std::vector< wxString > &aArgs, const std::function< void(int, const wxString &, const wxString &)> &aCallback, const wxExecuteEnv *aEnv=nullptr, bool aSaveOutput=false)
 Launches the Python interpreter with the given arguments.
 
long ExecuteSync (const std::vector< wxString > &aArgs, wxString *aStdout=nullptr, wxString *aStderr=nullptr, const wxExecuteEnv *aEnv=nullptr)
 
wxString GetInterpreterPath () const
 
void SetInterpreterPath (const wxString &aPath)
 

Static Public Member Functions

static wxString FindPythonInterpreter ()
 Searches for a Python intepreter on the user's system.
 
static std::optional< wxString > GetPythonEnvironment (const wxString &aNamespace)
 
static std::optional< wxString > GetVirtualPython (const wxString &aNamespace)
 Returns a full path to the python binary in a venv, if it exists.
 
static std::optional< wxString > GetVenvInterpreter (const wxString &aEnvPath)
 Returns the path of the interpreter that was used to create the venv in the given environment directory according to its config file.
 
static bool IsVenvUsable (const wxString &aEnvPath)
 
static bool IsVenvStale (const wxString &aEnvPath, const wxString &aConfiguredInterpreter)
 Returns true if the venv at aEnvPath was created by an interpreter other than aConfiguredInterpreter.
 

Private Attributes

wxString m_interpreterPath
 

Detailed Description

Definition at line 32 of file python_manager.h.

Constructor & Destructor Documentation

◆ PYTHON_MANAGER()

PYTHON_MANAGER::PYTHON_MANAGER ( const wxString & aInterpreterPath)

Definition at line 86 of file python_manager.cpp.

References FN_NORMALIZE_FLAGS, m_interpreterPath, and path.

Member Function Documentation

◆ Execute()

long PYTHON_MANAGER::Execute ( const std::vector< wxString > & aArgs,
const std::function< void(int, const wxString &, const wxString &)> & aCallback,
const wxExecuteEnv * aEnv = nullptr,
bool aSaveOutput = false )

Launches the Python interpreter with the given arguments.

Parameters
aArgs
aCallback
aEnv
aSaveOutput
Returns
the process ID of the created process, or 0 if one was not created

Definition at line 113 of file python_manager.cpp.

References _, GetKiCadThreadPool(), m_interpreterPath, process, readAllFromStream(), tp, and traceApi.

Referenced by API_PLUGIN_MANAGER::doInvokeAction(), API_PLUGIN_MANAGER::processNextJob(), and PANEL_PLUGIN_SETTINGS::validatePythonInterpreter().

◆ ExecuteSync()

long PYTHON_MANAGER::ExecuteSync ( const std::vector< wxString > & aArgs,
wxString * aStdout = nullptr,
wxString * aStderr = nullptr,
const wxExecuteEnv * aEnv = nullptr )

◆ FindPythonInterpreter()

wxString PYTHON_MANAGER::FindPythonInterpreter ( )
static

Searches for a Python intepreter on the user's system.

Returns
the absolute path to a Python interpreter, or an empty string if one was not found

Definition at line 252 of file python_manager.cpp.

References FindKicadFile().

Referenced by PGM_BASE::InitPgm(), and PANEL_PLUGIN_SETTINGS::OnBtnDetectAutomaticallyClicked().

◆ GetInterpreterPath()

wxString PYTHON_MANAGER::GetInterpreterPath ( ) const
inline

Definition at line 54 of file python_manager.h.

References m_interpreterPath.

◆ GetPythonEnvironment()

◆ GetVenvInterpreter()

std::optional< wxString > PYTHON_MANAGER::GetVenvInterpreter ( const wxString & aEnvPath)
static

Returns the path of the interpreter that was used to create the venv in the given environment directory according to its config file.

May return nullopt if the venv is invalid but also if it was created with an older Python version (venv only started recording the executable path in Python 3.11)

Definition at line 353 of file python_manager.cpp.

Referenced by IsVenvStale(), and IsVenvUsable().

◆ GetVirtualPython()

std::optional< wxString > PYTHON_MANAGER::GetVirtualPython ( const wxString & aNamespace)
static

Returns a full path to the python binary in a venv, if it exists.

Definition at line 313 of file python_manager.cpp.

References GetPythonEnvironment().

Referenced by API_PLUGIN_MANAGER::doInvokeAction(), and API_PLUGIN_MANAGER::processNextJob().

◆ IsVenvStale()

bool PYTHON_MANAGER::IsVenvStale ( const wxString & aEnvPath,
const wxString & aConfiguredInterpreter )
static

Returns true if the venv at aEnvPath was created by an interpreter other than aConfiguredInterpreter.

Definition at line 415 of file python_manager.cpp.

References canonicalizePath(), and GetVenvInterpreter().

Referenced by API_PLUGIN_MANAGER::HandlePythonInterpreterChanged(), and API_PLUGIN_MANAGER::processPluginDependencies().

◆ IsVenvUsable()

bool PYTHON_MANAGER::IsVenvUsable ( const wxString & aEnvPath)
static

◆ SetInterpreterPath()

void PYTHON_MANAGER::SetInterpreterPath ( const wxString & aPath)
inline

Definition at line 55 of file python_manager.h.

References m_interpreterPath.

Member Data Documentation

◆ m_interpreterPath

wxString PYTHON_MANAGER::m_interpreterPath
private

The documentation for this class was generated from the following files: