ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
PythonConfig Class Referencefinal

#include <PythonConfig.h>

Public Types

enum class  Type { Venv , Conda , System , Bundled }
 

Public Member Functions

 PythonConfig ()=default
 
Type type () const
 
const QString & pythonHome () const
 
void preparePythonProcess (QProcess &pythonProcess) const
 
PythonConfigPaths pythonCompatiblePaths () const
 
Version getVersion () const
 
bool validateAndDisplayErrors (QWidget *parent=nullptr) const
 
void initDefault ()
 
void initBundled ()
 
void initFromLocation (const QString &prefix)
 
void initCondaEnv (const QString &condaPrefix)
 Initialize the paths to use the conda environment stored at condaPrefix. More...
 
void initVenv (const QString &venvPrefix)
 Initialize the paths to use the python venv stored at venvPrefix. More...
 
void initFromPythonExecutable (const QString &pythonExecutable)
 

Static Public Member Functions

static bool IsInsideEnvironment ()
 
static PythonConfig fromContainingEnvironment ()
 

Detailed Description

This class infers the right python home and python path for the python environment to be used.

Its only used for Windows (on other platform it doesn't do much) as on Windows we can't rely on the system's python.

Definition at line 71 of file PythonConfig.h.

Member Enumeration Documentation

◆ Type

enum PythonConfig::Type
strong
Enumerator
Venv 
Conda 
System 
Bundled 

Definition at line 74 of file PythonConfig.h.

Constructor & Destructor Documentation

◆ PythonConfig()

PythonConfig::PythonConfig ( )
default

Member Function Documentation

◆ fromContainingEnvironment()

PythonConfig PythonConfig::fromContainingEnvironment ( )
static

◆ getVersion()

Version PythonConfig::getVersion ( ) const

Calls the python.exe of this environment / config to get its version.

Returns
The version returned by the python process If the python process failed for whatever reason the version will be {0, 0, 0}

Definition at line 341 of file PythonConfig.cpp.

References GetPythonExeVersion(), and preparePythonProcess().

Referenced by validateAndDisplayErrors().

◆ initBundled()

void PythonConfig::initBundled ( )

Initialize the paths to point to where the Python environment was bundled on installation

Definition at line 202 of file PythonConfig.cpp.

References initFromLocation().

Referenced by PythonRuntimeSettings::pythonEnvConfig(), and PythonPlugin::PythonPlugin().

◆ initCondaEnv()

void PythonConfig::initCondaEnv ( const QString &  condaPrefix)

Initialize the paths to use the conda environment stored at condaPrefix.

Definition at line 283 of file PythonConfig.cpp.

References Conda.

Referenced by initFromLocation().

◆ initDefault()

void PythonConfig::initDefault ( )

On Windows:

Initialize python home and python path corresponding to the environment to be used.

Other Platforms

Does nothing, as we rely on the system's python to be properly installed

Definition at line 193 of file PythonConfig.cpp.

References Bundled, and System.

Referenced by PythonRuntimeSettings::pythonEnvConfig().

◆ initFromLocation()

void PythonConfig::initFromLocation ( const QString &  prefix)

Initialize from the path to an environment. Will try to guess if the environment is a conda env or a python venv

Definition at line 212 of file PythonConfig.cpp.

References Bundled, Conda, initCondaEnv(), initFromPythonExecutable(), initVenv(), PathToPythonExecutableInEnv(), and Venv.

Referenced by initBundled(), and PythonRuntimeSettings::pythonEnvConfig().

◆ initFromPythonExecutable()

void PythonConfig::initFromPythonExecutable ( const QString &  pythonExecutable)

◆ initVenv()

void PythonConfig::initVenv ( const QString &  venvPrefix)

Initialize the paths to use the python venv stored at venvPrefix.

Definition at line 294 of file PythonConfig.cpp.

References PyVenvCfg::FromFile(), PyVenvCfg::home, PyVenvCfg::includeSystemSitesPackages, and Venv.

Referenced by initFromLocation().

◆ IsInsideEnvironment()

bool PythonConfig::IsInsideEnvironment ( )
static

Definition at line 380 of file PythonConfig.cpp.

Referenced by PythonPlugin::PythonPlugin().

◆ preparePythonProcess()

void PythonConfig::preparePythonProcess ( QProcess &  pythonProcess) const

Sets the necessary settings of the QProcess so that it uses the correct Python exe.

Definition at line 311 of file PythonConfig.cpp.

References Conda, cloudViewer::t::geometry::path, PathToPythonExecutableInEnv(), and type().

Referenced by getVersion(), and PackageManager::PackageManager().

◆ pythonCompatiblePaths()

PythonConfigPaths PythonConfig::pythonCompatiblePaths ( ) const

Returns the python home & path stored in types that the CPython API can use.

Definition at line 333 of file PythonConfig.cpp.

References QStringToWcharArray().

◆ pythonHome()

const QString& PythonConfig::pythonHome ( ) const
inline

Definition at line 109 of file PythonConfig.h.

Referenced by PackageManager::PackageManager().

◆ type()

Type PythonConfig::type ( ) const
inline

◆ validateAndDisplayErrors()

bool PythonConfig::validateAndDisplayErrors ( QWidget *  parent = nullptr) const

Does some basic validation (check is python executable exists and checks if its version is compatible) and displays a GUI with a message describing the error to the user.

Parameters
parentparent for the GUI to be displayed, can be nullptr
Returns
true if the config passes the validation (meaning no error where displayed to the user)

Definition at line 348 of file PythonConfig.cpp.

References getVersion(), Version::isCompatibleWithCompiledVersion(), Version::isNull(), PythonVersion(), Version::versionMajor, Version::versionMinor, and Version::versionPatch.

Referenced by PythonPlugin::PythonPlugin().


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