Python script launcher with logging and progress support. More...
#include <python_runner.h>
Signals | |
| void | lineReceived (int channel, const QString &line) |
| void | progressUpdated (float pct, const QString &msg) |
| void | finished (const UTILSLIB::PythonRunnerResult &result) |
Public Member Functions | |
| PythonRunner (QObject *pParent=nullptr) | |
| PythonRunner (const PythonRunnerConfig &config, QObject *pParent=nullptr) | |
| void | setConfig (const PythonRunnerConfig &config) |
| const PythonRunnerConfig & | config () const |
| void | setLineCallback (PythonLineCallback cb) |
| void | setProgressCallback (PythonProgressCallback cb) |
| PythonRunnerResult | run (const QString &scriptPath, const QStringList &args={}) |
| PythonRunnerResult | runCode (const QString &code, const QStringList &args={}) |
| bool | isPythonAvailable () const |
| QString | pythonVersion () const |
| bool | isPackageAvailable (const QString &packageName) const |
| PythonRunnerResult | ensureVenv () |
| PythonRunnerResult | runInVenv (const QString &scriptPath, const QStringList &args={}) |
| QString | venvPythonPath () const |
Python script launcher with logging and progress support.
Standardized interface for launching Python scripts from C++.
Features:
No Python embedding or linkage is required.
Definition at line 131 of file python_runner.h.

|
explicit |
Construct a PythonRunner with default configuration.
| [in] | pParent | Parent QObject (optional). |
Definition at line 63 of file python_runner.cpp.
|
explicit |
Construct a PythonRunner with explicit configuration.
| [in] | config | Execution configuration. |
| [in] | pParent | Parent QObject (optional). |
Definition at line 70 of file python_runner.cpp.
| const PythonRunnerConfig & PythonRunner::config | ( | ) | const |
Get the current configuration.
Definition at line 85 of file python_runner.cpp.
| PythonRunnerResult PythonRunner::ensureVenv | ( | ) |
Ensure a virtual environment exists, is up-to-date, and has all required packages installed.
Workflow:
Definition at line 197 of file python_runner.cpp.
|
signal |
Emitted when the script finishes.
| [in] | result | Execution result. |
| bool PythonRunner::isPackageAvailable | ( | const QString & | packageName | ) | const |
Check whether a Python package is importable.
| [in] | packageName | Package name (e.g. "torch", "mne"). |
Definition at line 163 of file python_runner.cpp.
| bool PythonRunner::isPythonAvailable | ( | ) | const |
Check that the configured Python interpreter is reachable.
Definition at line 135 of file python_runner.cpp.
|
signal |
Emitted for every stdout/stderr line (mirrors the line callback).
| [in] | channel | 0 = stdout, 1 = stderr. |
| [in] | line | Text line. |
|
signal |
Emitted when a progress line is parsed (mirrors the progress callback).
| [in] | pct | Progress 0–100. |
| [in] | msg | Optional message. |
| QString PythonRunner::pythonVersion | ( | ) | const |
Query the version string of the configured Python interpreter.
Definition at line 146 of file python_runner.cpp.
| PythonRunnerResult PythonRunner::run | ( | const QString & | scriptPath, |
| const QStringList & | args = {} ) |
Run a Python script synchronously.
| [in] | scriptPath | Path to the .py file. |
| [in] | args | Arguments forwarded to the script. |
Definition at line 106 of file python_runner.cpp.
| PythonRunnerResult PythonRunner::runCode | ( | const QString & | code, |
| const QStringList & | args = {} ) |
Run a Python one-liner synchronously (python -c "...").
| [in] | code | Python code string. |
| [in] | args | Extra arguments appended after -c code. |
Definition at line 120 of file python_runner.cpp.
| PythonRunnerResult PythonRunner::runInVenv | ( | const QString & | scriptPath, |
| const QStringList & | args = {} ) |
Convenience: ensure venv, then run a script inside it.
Equivalent to calling ensureVenv() + run(), but returns early with an error result if venv setup fails.
| [in] | scriptPath | Path to the .py file. |
| [in] | args | Arguments forwarded to the script. |
Definition at line 321 of file python_runner.cpp.
| void PythonRunner::setConfig | ( | const PythonRunnerConfig & | config | ) |
Set the configuration.
| [in] | config | Execution configuration. |
Definition at line 78 of file python_runner.cpp.
| void PythonRunner::setLineCallback | ( | PythonLineCallback | cb | ) |
Set a callback invoked for every stdout/stderr line.
| [in] | cb | Line callback (channel, line). |
Definition at line 92 of file python_runner.cpp.
| void PythonRunner::setProgressCallback | ( | PythonProgressCallback | cb | ) |
Set a callback invoked when a progress line is detected.
Progress protocol: the script prints lines matching: [progress] 42.5% [progress] 42.5% Training epoch 10/50
| [in] | cb | Progress callback (pct, msg). |
Definition at line 99 of file python_runner.cpp.
| QString PythonRunner::venvPythonPath | ( | ) | const |
Get the Python interpreter path inside the configured venv.
Definition at line 183 of file python_runner.cpp.