Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkPipInstaller.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkPipInstaller_h
14 #define QmitkPipInstaller_h
15 
16 #include <mitkPipPackageInfo.h>
17 
18 #include <QObject>
19 #include <QProcess>
20 #include <QTemporaryFile>
21 
44 {
45  Q_OBJECT
46 
47 public:
48  explicit QmitkPipInstaller(QObject* parent = nullptr);
49  ~QmitkPipInstaller() override;
50 
57 
69  void StartInstall();
70 
81  void Cancel();
82 
94 
96  bool IsRunning() const;
97 
104  const std::vector<mitk::PipPackageInfo>& GetResolvedPackages() const;
105 
106 signals:
109 
112 
115 
125  void PackageStatusChanged(int index, const QString& name, mitk::PackageStatus status);
126 
133  void PostInstallStepStarted(const QString& displayName);
134 
149  void InstallFinished(bool success);
150 
156  void OutputReceived(const QString& text, bool isError);
157 
168  void ProgressChanged(int current, int total);
169 
171  void ErrorOccurred(const QString& message);
172 
173 private slots:
174  void OnStandardOutputReady();
175  void OnStandardErrorReady();
176  void OnProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
177 
178 private:
179  enum class State
180  {
181  Idle,
182  CreatingVirtualEnv,
183  UpgradingPip,
184  Resolving,
185  Installing,
186  RunningPostInstall,
187  Cancelling,
188  Done,
189  Failed
190  };
191 
192  void BeginVirtualEnvPhase();
193  void StartPipUpgrade();
194  void StartResolveGroup();
195  void StartInstallPackage();
196  void BeginPostInstallPhase();
197  void StartPostInstallStep();
198  QStringList BuildPipArgs(const QStringList& baseArgs, const mitk::PipInstallGroup& group) const;
199  void AdvanceToNextGroup();
200  bool ParseResolveReport(const QString& reportPath, int groupIndex);
201  QString PythonExecutable() const;
202  QString RequirePythonExecutable();
203  void FinalizeCancel();
204  void RemoveCreatedVirtualEnv();
205 
206  mitk::PipInstallSpec m_Spec;
207 
208  // Working copy of the groups driving the current install run. Currently equal
209  // to m_Spec.groups; kept as a separate member so the install loop and
210  // ParseResolveReport index a stable list, and so future synthetic groups can
211  // be appended in StartInstall() without disturbing the caller's spec.
212  std::vector<mitk::PipInstallGroup> m_Groups;
213  std::vector<mitk::PipPackageInfo> m_ResolvedPackages;
214 
215  QProcess* m_Process = nullptr;
216  State m_State = State::Idle;
217  bool m_AnyFailed = false;
218  bool m_CreatedVirtualEnv = false;
219 
220  int m_CurrentGroup = 0;
221  int m_CurrentPackage = 0;
222  int m_GroupStartIndex = 0;
223  int m_CurrentPostInstallStep = 0;
224 
225  QTemporaryFile m_ReportFile;
226 };
227 
228 #endif
#define MITKPYTHONINSTALLER_EXPORT
Headless pip installer with structured progress reporting.
void PackageStatusChanged(int index, const QString &name, mitk::PackageStatus status)
Emitted when a package's installation status changes.
void OutputReceived(const QString &text, bool isError)
Raw process output for display in a details view.
void ProgressChanged(int current, int total)
Per-package progress during the install phase only.
void AbandonInstall()
Tear down anything this installer created during a failed install.
void SetInstallSpec(const mitk::PipInstallSpec &spec)
Set the installation specification.
void ErrorOccurred(const QString &message)
Emitted on fatal errors (e.g. Python executable not found).
void PostInstallStepStarted(const QString &displayName)
Emitted when a post-install step starts.
void StartInstall()
Start the installation.
bool IsRunning() const
Whether an operation is currently running.
void Cancel()
Cancel the current operation.
void VirtualEnvCreationStarted()
Emitted when virtual environment creation starts.
const std::vector< mitk::PipPackageInfo > & GetResolvedPackages() const
The full list of resolved packages across all groups.
void ResolveStarted()
Emitted when resolution of a group starts.
void PipUpgradeStarted()
Emitted when the pip upgrade step starts.
~QmitkPipInstaller() override
void InstallFinished(bool success)
Emitted when the installation terminates.
QmitkPipInstaller(QObject *parent=nullptr)
PackageStatus
Status of a single package during installation.
A set of packages that share the same pip options.
Full specification for a pip installation run.