diff options
author | hjk <hjk@qt.io> | 2021-05-12 14:25:50 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2021-05-14 13:19:01 +0000 |
commit | 55f768e1b0a2f49977a48972b243d3efa255e337 (patch) | |
tree | 004b6e589d3589c2a11335f59b7a6e1380a859a7 /src/plugins/python | |
parent | f23b27ded6bc4f7859ff2091b957213fa4597fe9 (diff) |
Utils: Make process results accessible through QtcProcess object
The result is fully stored in the object anyway. Using the extra
SynchronousProcessResponse structure only causes copies of
the data and complicates access on the user side in
a lot of cases.
The result bits are now also accessible individually.
There's obvious room for follow-up changes on the topic, e.g.
ShellCommand::runCommand's parameter list could shrink to
just a SynchronousProcess parameter.
Change-Id: I45aa7eb23832340be06905929280c012e1217263
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/python')
-rw-r--r-- | src/plugins/python/pythonsettings.cpp | 7 | ||||
-rw-r--r-- | src/plugins/python/pythonutils.cpp | 20 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/plugins/python/pythonsettings.cpp b/src/plugins/python/pythonsettings.cpp index ffe8b83e02c..9700630bf60 100644 --- a/src/plugins/python/pythonsettings.cpp +++ b/src/plugins/python/pythonsettings.cpp @@ -281,10 +281,9 @@ Interpreter::Interpreter(const FilePath &python, const QString &defaultName, boo SynchronousProcess pythonProcess; pythonProcess.setProcessChannelMode(QProcess::MergedChannels); pythonProcess.setTimeoutS(1); - SynchronousProcessResponse response = pythonProcess.runBlocking( - CommandLine(python, {"--version"})); - if (response.result == SynchronousProcessResponse::Finished) - name = response.stdOut().trimmed(); + pythonProcess.runBlocking({python, {"--version"}}); + if (pythonProcess.result() == QtcProcess::Finished) + name = pythonProcess.stdOut().trimmed(); if (name.isEmpty()) name = defaultName; if (windowedSuffix) diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index 309bb873f69..60639492c6d 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -87,10 +87,10 @@ static QString pythonName(const FilePath &pythonPath) SynchronousProcess pythonProcess; pythonProcess.setTimeoutS(2); const CommandLine pythonVersionCommand(pythonPath, {"--version"}); - const SynchronousProcessResponse response = pythonProcess.runBlocking(pythonVersionCommand); - if (response.result != SynchronousProcessResponse::Finished) + pythonProcess.runBlocking(pythonVersionCommand); + if (pythonProcess.result() != QtcProcess::Finished) return {}; - name = response.allOutput().trimmed(); + name = pythonProcess.allOutput().trimmed(); nameForPython[pythonPath] = name; } return name; @@ -109,7 +109,7 @@ FilePath getPylsModulePath(CommandLine pylsCommand) Environment env = pythonProcess.environment(); env.set("PYTHONVERBOSE", "x"); pythonProcess.setEnvironment(env); - SynchronousProcessResponse response = pythonProcess.runBlocking(pylsCommand); + pythonProcess.runBlocking(pylsCommand); static const QString pylsInitPattern = "(.*)" + QRegularExpression::escape( @@ -120,7 +120,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 ®ex : {regexCached, regexNotCached}) { const QRegularExpressionMatch result = regex.match(output); if (result.hasMatch()) { @@ -148,7 +148,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()) { @@ -159,13 +158,14 @@ static PythonLanguageServerState checkPythonLanguageServer(const FilePath &pytho } } - SynchronousProcessResponse response = pythonProcess.runBlocking(pythonLShelpCommand); - if (response.allOutput().contains("Python Language Server")) + SynchronousProcess pythonProcess; + pythonProcess.runBlocking(pythonLShelpCommand); + 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.runBlocking(pythonPipVersionCommand); + if (pythonProcess.allOutput().startsWith("pip ")) return {PythonLanguageServerState::CanBeInstalled, FilePath()}; else return {PythonLanguageServerState::CanNotBeInstalled, FilePath()}; |