diff options
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r-- | src/plugins/python/pythonutils.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index 8635605092..1f89eef5b5 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -8,6 +8,7 @@ #include "pythontr.h" #include <coreplugin/messagemanager.h> +#include <coreplugin/progressmanager/processprogress.h> #include <projectexplorer/project.h> #include <projectexplorer/projectmanager.h> @@ -164,4 +165,24 @@ PythonProject *pythonProjectForFile(const FilePath &pythonFile) return nullptr; } +void createVenv(const Utils::FilePath &python, + const Utils::FilePath &venvPath, + const std::function<void(bool)> &callback) +{ + QTC_ASSERT(python.isExecutableFile(), callback(false); return); + QTC_ASSERT(!venvPath.exists() || venvPath.isDir(), callback(false); return); + + const CommandLine command(python, QStringList{"-m", "venv", venvPath.toUserOutput()}); + + auto process = new QtcProcess; + auto progress = new Core::ProcessProgress(process); + progress->setDisplayName(Tr::tr("Create Python venv")); + QObject::connect(process, &QtcProcess::done, [process, callback](){ + callback(process->result() == ProcessResult::FinishedWithSuccess); + process->deleteLater(); + }); + process->setCommand(command); + process->start(); +} + } // Python::Internal |