OpenMS
Loading...
Searching...
No Matches
PythonInfo Class Reference

Detect Python and retrieve information. More...

#include <OpenMS/SYSTEM/PythonInfo.h>

Static Public Member Functions

static bool canRun (std::string &python_executable, std::string &error_msg)
 Determine if Python is installed and executable.
 
static bool isPackageInstalled (const std::string &python_executable, const std::string &package_name)
 Determine if the Python given in python_executable has the package package_name already installed.
 
static std::string getVersion (const std::string &python_executable)
 Determine the version of Python given in python_executable by calling '–version'.
 

Detailed Description

Detect Python and retrieve information.

Similar classes exist for other external tools, e.g. JavaInfo .

Member Function Documentation

◆ canRun()

static bool canRun ( std::string &  python_executable,
std::string &  error_msg 
)
static

Determine if Python is installed and executable.

The call fails if either Python is not installed or if a relative location is given and Python is not on the search PATH. If Python is found, the executable name will be modified to the absolute path. If Python is not found, an error message will be put into error_msg

Parameters
[in,out]python_executablePath to Python executable. Can be absolute, relative or just a filename
[out]error_msgOn error, contains detailed error description (e.g.
Returns
Returns false if Python executable can not be called; true if Python executable can be executed

◆ getVersion()

static std::string getVersion ( const std::string &  python_executable)
static

Determine the version of Python given in python_executable by calling '–version'.

If Python cannot be found, the function will return the empty string. Thus, make sure that PythonInfo::canRun() succeeds before calling this function.

Parameters
[in]python_executableAs determined by canRun()...
Returns
the output of 'python –version'

◆ isPackageInstalled()

static bool isPackageInstalled ( const std::string &  python_executable,
const std::string &  package_name 
)
static

Determine if the Python given in python_executable has the package package_name already installed.

If Python cannot be found, the function will just return false. Thus, make sure that PythonInfo::canRun() succeeds before calling this function.

Parameters
[in]python_executableAs determined by canRun()...
[in]package_nameThe package you want to test (mind lower/upper case!)
Returns
true if package is installed