Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
QmitkSetupVirtualEnvUtil Class Referenceabstract

Abstract Class to Setup a python virtual environment and pip install required packages. Derive this class for creating installer for the respective tool. More...

#include <QmitkSetupVirtualEnvUtil.h>

Inheritance diagram for QmitkSetupVirtualEnvUtil:

Public Member Functions

 QmitkSetupVirtualEnvUtil (const QString &baseDir)
 
 QmitkSetupVirtualEnvUtil ()
 
virtual bool SetupVirtualEnv (const QString &venvName)=0
 Implement the method in child class to setup the virtual environment. More...
 
virtual QString GetVirtualEnvPath ()
 Get the Virtual Env Path object. Override this method in the respective tool installer class. More...
 
void PipInstall (const std::string &library, const std::string &workingDir, void(*callback)(itk::Object *, const itk::EventObject &, void *), const std::string &command="pip3")
 Function to Pip install a library package given the location of pip3 executable. Any callback function can be passed to process the output. More...
 
void PipInstall (const std::string &library, void(*callback)(itk::Object *, const itk::EventObject &, void *), const std::string &command="pip3")
 Overloaded function to Pip install a library function. More...
 
void ExecutePython (const std::string &args, const std::string &pythonPath, void(*callback)(itk::Object *, const itk::EventObject &, void *), const std::string &command="python")
 Function to execute any python code given a python path. Any callback function can be passed to process the output. More...
 
void ExecutePython (const std::string &args, void(*callback)(itk::Object *, const itk::EventObject &, void *), const std::string &command="python")
 Overloaded function to Execute Python code. Any callback function can be passed to process the output. More...
 
void InstallPytorch (const std::string &workingDir, void(*callback)(itk::Object *, const itk::EventObject &, void *))
 Installs pytorch using light-the-torch package, correctly identifying cuda version. Requires location of pip3 executable. Any callback function can be passed to process the output. More...
 
void InstallPytorch ()
 Overloaded function to install pytorch using light-the-torch package, correctly identifying cuda version. More...
 
QString & GetBaseDir ()
 Get the Base Dir object. More...
 
QString & GetSystemPythonPath ()
 Get the System Python Path object. More...
 
QString & GetPythonPath ()
 Get the Python Path object. More...
 
QString & GetPipPath ()
 Get the Pip Path object. More...
 
void SetSystemPythonPath (const QString &path)
 Set the System Python Path object. More...
 
void SetPythonPath (const QString &path)
 Set the Python Path object. More...
 
void SetPipPath (const QString &path)
 Set the Pip Path object. More...
 
void SetVirtualEnvPath (const QString &path)
 Set the Virtual Env Path object. More...
 
bool IsPythonPath (const QString &pythonPath)
 Check if the path provide has python executable or not. More...
 

Static Public Member Functions

static bool IsVenvInstalled (const QString &pythonPath)
 Checks if venv module is available for the python. More...
 
static QString GetPipPackageVersion (const QString &pythonPath, const QString &packageName)
 Returns version of the pip installed package. More...
 
static void PrintProcessEvent (itk::Object *, const itk::EventObject &e, void *)
 Function can be used as callback to simply print out all the process execution output parsed out from itk::EventObject. More...
 
static std::pair< QString, QString > GetExactPythonPath (const QString &pyEnv)
 Get the exact Python path and version for any OS from the virtual environment path. More...
 

Detailed Description

Abstract Class to Setup a python virtual environment and pip install required packages. Derive this class for creating installer for the respective tool.

Definition at line 25 of file QmitkSetupVirtualEnvUtil.h.

Constructor & Destructor Documentation

◆ QmitkSetupVirtualEnvUtil() [1/2]

QmitkSetupVirtualEnvUtil::QmitkSetupVirtualEnvUtil ( const QString &  baseDir)

◆ QmitkSetupVirtualEnvUtil() [2/2]

QmitkSetupVirtualEnvUtil::QmitkSetupVirtualEnvUtil ( )

Member Function Documentation

◆ ExecutePython() [1/2]

void QmitkSetupVirtualEnvUtil::ExecutePython ( const std::string &  args,
const std::string &  pythonPath,
void(*)(itk::Object *, const itk::EventObject &, void *)  callback,
const std::string &  command = "python" 
)

Function to execute any python code given a python path. Any callback function can be passed to process the output.

Parameters
args
pythonPath
callback
command

◆ ExecutePython() [2/2]

void QmitkSetupVirtualEnvUtil::ExecutePython ( const std::string &  args,
void(*)(itk::Object *, const itk::EventObject &, void *)  callback,
const std::string &  command = "python" 
)

Overloaded function to Execute Python code. Any callback function can be passed to process the output.

Parameters
args
callback
command

◆ GetBaseDir()

QString& QmitkSetupVirtualEnvUtil::GetBaseDir ( )

Get the Base Dir object.

Returns
QString&

◆ GetExactPythonPath()

static std::pair<QString, QString> QmitkSetupVirtualEnvUtil::GetExactPythonPath ( const QString &  pyEnv)
static

Get the exact Python path and version for any OS from the virtual environment path.

Returns
A pair of the exact python path and its Python version or empty, if an supported version of Python could not be found.

◆ GetPipPackageVersion()

static QString QmitkSetupVirtualEnvUtil::GetPipPackageVersion ( const QString &  pythonPath,
const QString &  packageName 
)
static

Returns version of the pip installed package.

◆ GetPipPath()

QString& QmitkSetupVirtualEnvUtil::GetPipPath ( )

Get the Pip Path object.

Returns
QString&

◆ GetPythonPath()

QString& QmitkSetupVirtualEnvUtil::GetPythonPath ( )

Get the Python Path object.

Returns
QString&

◆ GetSystemPythonPath()

QString& QmitkSetupVirtualEnvUtil::GetSystemPythonPath ( )

Get the System Python Path object.

Returns
QString&

◆ GetVirtualEnvPath()

virtual QString QmitkSetupVirtualEnvUtil::GetVirtualEnvPath ( )
virtual

Get the Virtual Env Path object. Override this method in the respective tool installer class.

Returns
QString

Reimplemented in QmitkTotalSegmentatorToolInstaller, and QmitkSAMInstaller.

◆ InstallPytorch() [1/2]

void QmitkSetupVirtualEnvUtil::InstallPytorch ( )

Overloaded function to install pytorch using light-the-torch package, correctly identifying cuda version.

◆ InstallPytorch() [2/2]

void QmitkSetupVirtualEnvUtil::InstallPytorch ( const std::string &  workingDir,
void(*)(itk::Object *, const itk::EventObject &, void *)  callback 
)

Installs pytorch using light-the-torch package, correctly identifying cuda version. Requires location of pip3 executable. Any callback function can be passed to process the output.

Parameters
workingDir
callback

◆ IsPythonPath()

bool QmitkSetupVirtualEnvUtil::IsPythonPath ( const QString &  pythonPath)

Check if the path provide has python executable or not.

Parameters
pythonPath
Returns
true
false

◆ IsVenvInstalled()

static bool QmitkSetupVirtualEnvUtil::IsVenvInstalled ( const QString &  pythonPath)
static

Checks if venv module is available for the python.

◆ PipInstall() [1/2]

void QmitkSetupVirtualEnvUtil::PipInstall ( const std::string &  library,
const std::string &  workingDir,
void(*)(itk::Object *, const itk::EventObject &, void *)  callback,
const std::string &  command = "pip3" 
)

Function to Pip install a library package given the location of pip3 executable. Any callback function can be passed to process the output.

Parameters
library
workingDir
callback
command

◆ PipInstall() [2/2]

void QmitkSetupVirtualEnvUtil::PipInstall ( const std::string &  library,
void(*)(itk::Object *, const itk::EventObject &, void *)  callback,
const std::string &  command = "pip3" 
)

Overloaded function to Pip install a library function.

Parameters
library
callback
command

◆ PrintProcessEvent()

static void QmitkSetupVirtualEnvUtil::PrintProcessEvent ( itk::Object *  ,
const itk::EventObject &  e,
void *   
)
static

Function can be used as callback to simply print out all the process execution output parsed out from itk::EventObject.

◆ SetPipPath()

void QmitkSetupVirtualEnvUtil::SetPipPath ( const QString &  path)

Set the Pip Path object.

Parameters
path

◆ SetPythonPath()

void QmitkSetupVirtualEnvUtil::SetPythonPath ( const QString &  path)

Set the Python Path object.

Parameters
path

◆ SetSystemPythonPath()

void QmitkSetupVirtualEnvUtil::SetSystemPythonPath ( const QString &  path)

Set the System Python Path object.

Parameters
path

◆ SetupVirtualEnv()

virtual bool QmitkSetupVirtualEnvUtil::SetupVirtualEnv ( const QString &  venvName)
pure virtual

Implement the method in child class to setup the virtual environment.

Implemented in QmitkTotalSegmentatorToolInstaller, and QmitkSAMInstaller.

◆ SetVirtualEnvPath()

void QmitkSetupVirtualEnvUtil::SetVirtualEnvPath ( const QString &  path)

Set the Virtual Env Path object.

Parameters
path

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