summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2023-01-13 06:55:05 +0100
committerDavid Schulz <david.schulz@qt.io>2023-01-20 10:16:36 +0000
commitf0f0cf129ad34be6bcbbf0b693e7dde5cbbc56a1 (patch)
tree7a70d846c780b8eb323a244ccff694780e446007 /src/plugins/python/pythonutils.cpp
parentd92be80610de0c519a21330cf0e9a24a9c63917d (diff)
downloadqt-creator-f0f0cf129ad34be6bcbbf0b693e7dde5cbbc56a1.tar.gz
Python: add interpreter selector to editor toolbar
Fixes: PYSIDE-2154 Change-Id: If5e90f5bf2923b61af37ebbfcd35c512b3b07db4 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r--src/plugins/python/pythonutils.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp
index 24d8a1f188..346c42d183 100644
--- a/src/plugins/python/pythonutils.cpp
+++ b/src/plugins/python/pythonutils.cpp
@@ -22,6 +22,12 @@ using namespace Utils;
namespace Python::Internal {
+static QHash<FilePath, FilePath> &userDefinedPythonsForDocument()
+{
+ static QHash<FilePath, FilePath> userDefines;
+ return userDefines;
+}
+
FilePath detectPython(const FilePath &documentPath)
{
Project *project = documentPath.isEmpty() ? nullptr
@@ -42,6 +48,10 @@ FilePath detectPython(const FilePath &documentPath)
}
}
+ const FilePath userDefined = userDefinedPythonsForDocument().value(documentPath);
+ if (userDefined.exists())
+ return userDefined;
+
// check whether this file is inside a python virtual environment
const QList<Interpreter> venvInterpreters = PythonSettings::detectPythonVenvs(documentPath);
if (!venvInterpreters.isEmpty())
@@ -71,6 +81,11 @@ FilePath detectPython(const FilePath &documentPath)
return PythonSettings::interpreters().value(0).command;
}
+void definePythonForDocument(const FilePath &documentPath, const FilePath &python)
+{
+ userDefinedPythonsForDocument()[documentPath] = python;
+}
+
static QStringList replImportArgs(const FilePath &pythonFile, ReplType type)
{
using MimeTypes = QList<MimeType>;