summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2023-01-23 13:43:58 +0100
committerDavid Schulz <david.schulz@qt.io>2023-03-21 05:39:48 +0000
commit7d4f123842ea937de4390b2ba783c7c13f9ea55a (patch)
tree2a430480e14f39435c80d1b203bcdc61e6f297fc /src/plugins/python/pythonutils.cpp
parent5256f08b6dcd6fe5abdf80427626b56194ca209a (diff)
downloadqt-creator-7d4f123842ea937de4390b2ba783c7c13f9ea55a.tar.gz
Python: add create venv action
The action can be triggered from the interpreter chooser of the editor toolbar. Change-Id: Ie23b68a3790525ea02883ef359b357a0d317b2f5 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r--src/plugins/python/pythonutils.cpp21
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