summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r--src/plugins/python/pythonutils.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp
index 56b2dbe6db..d693c2597b 100644
--- a/src/plugins/python/pythonutils.cpp
+++ b/src/plugins/python/pythonutils.cpp
@@ -46,8 +46,8 @@
#include <utils/infobar.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
+#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
-#include <utils/synchronousprocess.h>
#include <QDir>
#include <QFutureWatcher>
@@ -86,11 +86,11 @@ static QString pythonName(const FilePath &pythonPath)
if (name.isEmpty()) {
SynchronousProcess pythonProcess;
pythonProcess.setTimeoutS(2);
- const CommandLine pythonVersionCommand(pythonPath, {"--version"});
- const SynchronousProcessResponse response = pythonProcess.runBlocking(pythonVersionCommand);
- if (response.result != SynchronousProcessResponse::Finished)
+ pythonProcess.setCommand({pythonPath, {"--version"}});
+ pythonProcess.runBlocking();
+ if (pythonProcess.result() != QtcProcess::Finished)
return {};
- name = response.allOutput().trimmed();
+ name = pythonProcess.allOutput().trimmed();
nameForPython[pythonPath] = name;
}
return name;
@@ -104,9 +104,13 @@ FilePath getPylsModulePath(CommandLine pylsCommand)
return modulePath;
pylsCommand.addArg("-h");
+
SynchronousProcess pythonProcess;
- pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x"));
- SynchronousProcessResponse response = pythonProcess.runBlocking(pylsCommand);
+ Environment env = pythonProcess.environment();
+ env.set("PYTHONVERBOSE", "x");
+ pythonProcess.setEnvironment(env);
+ pythonProcess.setCommand(pylsCommand);
+ pythonProcess.runBlocking();
static const QString pylsInitPattern = "(.*)"
+ QRegularExpression::escape(
@@ -117,7 +121,7 @@ FilePath getPylsModulePath(CommandLine pylsCommand)
static const QRegularExpression regexNotCached(" code object from " + pylsInitPattern,
QRegularExpression::MultilineOption);
- const QString &output = response.allOutput();
+ const QString output = pythonProcess.allOutput();
for (const auto &regex : {regexCached, regexNotCached}) {
const QRegularExpressionMatch result = regex.match(output);
if (result.hasMatch()) {
@@ -145,7 +149,6 @@ QList<const StdIOSettings *> configuredPythonLanguageServer()
static PythonLanguageServerState checkPythonLanguageServer(const FilePath &python)
{
using namespace LanguageClient;
- SynchronousProcess pythonProcess;
const CommandLine pythonLShelpCommand(python, {"-m", "pyls", "-h"});
const FilePath &modulePath = getPylsModulePath(pythonLShelpCommand);
for (const StdIOSettings *serverSetting : configuredPythonLanguageServer()) {
@@ -156,13 +159,15 @@ static PythonLanguageServerState checkPythonLanguageServer(const FilePath &pytho
}
}
- SynchronousProcessResponse response = pythonProcess.runBlocking(pythonLShelpCommand);
- if (response.allOutput().contains("Python Language Server"))
+ SynchronousProcess pythonProcess;
+ pythonProcess.setCommand(pythonLShelpCommand);
+ pythonProcess.runBlocking();
+ if (pythonProcess.allOutput().contains("Python Language Server"))
return {PythonLanguageServerState::AlreadyInstalled, modulePath};
- const CommandLine pythonPipVersionCommand(python, {"-m", "pip", "-V"});
- response = pythonProcess.runBlocking(pythonPipVersionCommand);
- if (response.allOutput().startsWith("pip "))
+ pythonProcess.setCommand({python, {"-m", "pip", "-V"}});
+ pythonProcess.runBlocking();
+ if (pythonProcess.allOutput().startsWith("pip "))
return {PythonLanguageServerState::CanBeInstalled, FilePath()};
else
return {PythonLanguageServerState::CanNotBeInstalled, FilePath()};
@@ -267,7 +272,8 @@ public:
if (!QDir(m_python.parentDir().toString()).exists("activate"))
arguments << "--user";
- m_process.start(m_python.toString(), arguments);
+ m_process.setCommand({m_python, arguments});
+ m_process.start();
Core::MessageManager::writeDisrupting(
tr("Running \"%1 %2\" to install Python language server")
@@ -280,7 +286,7 @@ public:
private:
void cancel()
{
- SynchronousProcess::stopProcess(m_process);
+ m_process.stopProcess();
Core::MessageManager::writeFlashing(
tr("The Python language server installation was canceled by %1.")
.arg(m_killTimer.isActive() ? tr("user") : tr("time out")));
@@ -315,7 +321,7 @@ private:
QFutureInterface<void> m_future;
QFutureWatcher<void> m_watcher;
- QProcess m_process;
+ QtcProcess m_process;
QTimer m_killTimer;
const FilePath m_python;
QPointer<TextEditor::TextDocument> m_document;
@@ -377,7 +383,6 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
using CheckPylsWatcher = QFutureWatcher<PythonLanguageServerState>;
QPointer<CheckPylsWatcher> watcher = new CheckPylsWatcher();
- watcher->setFuture(Utils::runAsync(&checkPythonLanguageServer, python));
// cancel and delete watcher after a 10 second timeout
QTimer::singleShot(10000, this, [watcher]() {
@@ -397,6 +402,7 @@ void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python,
handlePyLSState(python, watcher->result(), document);
watcher->deleteLater();
});
+ watcher->setFuture(Utils::runAsync(&checkPythonLanguageServer, python));
}
void PyLSConfigureAssistant::handlePyLSState(const FilePath &python,