diff options
| author | David Schulz <david.schulz@qt.io> | 2023-11-27 14:15:29 +0100 |
|---|---|---|
| committer | David Schulz <david.schulz@qt.io> | 2023-12-13 11:26:16 +0000 |
| commit | fbe054116aff3ce5bd714a1982675c4ecc82d18a (patch) | |
| tree | c9227e03b5cd0c8d22047df559f9f1645108e46f /src/plugins/python/pythonutils.cpp | |
| parent | 12004190595cdf3dc567120d8310e5e8a4476385 (diff) | |
Python: Avoid polluting global or virtual environments with pylsp
Install the language server into the Qt Creator resource directory
instead. Reuse the server for all interpreters with the same
version. This also reduces the amount of editor toolbars asking the user
to install a language server for a specific interpreter.
Change-Id: I48ef4ad30fe0097ee8d2b855b0f278e98be5ce57
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
| -rw-r--r-- | src/plugins/python/pythonutils.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index d1307a351d3..096520dd7ec 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -21,6 +21,8 @@ #include <utils/mimeutils.h> #include <utils/process.h> +#include <QReadLocker> + using namespace ProjectExplorer; using namespace Utils; @@ -208,4 +210,28 @@ bool pipIsUsable(const Utils::FilePath &python) return process.result() == ProcessResult::FinishedWithSuccess; } +QString pythonVersion(const FilePath &python) +{ + static QReadWriteLock lock; + static QMap<FilePath, QString> versionCache; + + { + QReadLocker locker(&lock); + auto it = versionCache.constFind(python); + if (it != versionCache.constEnd()) + return *it; + } + + Process p; + p.setCommand({python, {"--version"}}); + p.runBlocking(); + if (p.result() == Utils::ProcessResult::FinishedWithSuccess) { + const QString version = p.readAllStandardOutput().trimmed(); + QWriteLocker locker(&lock); + versionCache.insert(python, version); + return version; + } + return QString(); +} + } // Python::Internal |
