From f0f0cf129ad34be6bcbbf0b693e7dde5cbbc56a1 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 13 Jan 2023 06:55:05 +0100 Subject: Python: add interpreter selector to editor toolbar Fixes: PYSIDE-2154 Change-Id: If5e90f5bf2923b61af37ebbfcd35c512b3b07db4 Reviewed-by: Christian Stenger --- src/plugins/python/pythonutils.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/plugins/python/pythonutils.cpp') 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 &userDefinedPythonsForDocument() +{ + static QHash 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 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; -- cgit v1.2.1