From 4f857711c2dfdd3214948bc7d19e368db2fd37eb Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 13 Dec 2023 08:06:41 +0100 Subject: [PATCH] Python: install lsp into tempdir for remote interpreters Change-Id: I4b0b1a47c73742cc14f68d80b9116fcd51224bd1 Reviewed-by: Christian Stenger --- src/plugins/python/pipsupport.cpp | 9 ++++--- src/plugins/python/pythonlanguageclient.cpp | 30 +++++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/plugins/python/pipsupport.cpp b/src/plugins/python/pipsupport.cpp index dd213248961..1ece0c534ca 100644 --- a/src/plugins/python/pipsupport.cpp +++ b/src/plugins/python/pipsupport.cpp @@ -5,6 +5,7 @@ #include "pythonplugin.h" #include "pythontr.h" +#include "pythonutils.h" #include #include @@ -80,10 +81,12 @@ void PipInstallTask::run() } } - if (!m_targetPath.isEmpty()) - arguments << "-t" << m_targetPath.toString(); - else if (!QDir(m_python.parentDir().toString()).exists("activate")) + if (!m_targetPath.isEmpty()) { + QTC_ASSERT(m_targetPath.isSameDevice(m_python), emit finished(false); return); + arguments << "-t" << m_targetPath.path(); + } else if (!isVenvPython(m_python)) { arguments << "--user"; // add --user to global pythons, but skip it for venv pythons + } m_process.setCommand({m_python, arguments}); m_process.setTerminalMode(TerminalMode::Run); diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp index a6bb9fcaa81..5a54a8c4b64 100644 --- a/src/plugins/python/pythonlanguageclient.cpp +++ b/src/plugins/python/pythonlanguageclient.cpp @@ -74,12 +74,12 @@ static QHash &pythonClients() static FilePath pyLspPath(const FilePath &python) { - if (python.needsDevice()) - return {}; const QString version = pythonVersion(python); - if (version.isEmpty()) - return {}; - return Core::ICore::userResourcePath("pylsp") / FileUtils::fileSystemFriendlyName(version); + if (!python.needsDevice()) + return Core::ICore::userResourcePath() / "pylsp" / version; + if (const expected_str tmpDir = python.tmpDir()) + return *tmpDir / "qc-pylsp" / version; + return {}; } static PythonLanguageServerState checkPythonLanguageServer(const FilePath &python) @@ -113,20 +113,22 @@ public: protected: void startImpl() override { - if (!m_cmd.executable().needsDevice()) { + const FilePath python = m_cmd.executable(); + Environment env = python.deviceEnvironment(); + const FilePath lspPath = pyLspPath(python); + if (!lspPath.isEmpty() && lspPath.exists() && QTC_GUARD(lspPath.isSameDevice(python))) { + env.appendOrSet("PYTHONPATH", + lspPath.path(), + OsSpecificAspects::pathListSeparator(env.osType())); + } + if (!python.needsDevice()) { // todo check where to put this tempdir in remote setups - Environment env = Environment::systemEnvironment(); env.appendOrSet("PYTHONPATH", m_extraPythonPath.path().toString(), OsSpecificAspects::pathListSeparator(env.osType())); - const FilePath lspPath = pyLspPath(m_cmd.executable()); - if (!lspPath.isEmpty() && lspPath.exists()) { - env.appendOrSet("PYTHONPATH", - pyLspPath(m_cmd.executable()).toString(), - OsSpecificAspects::pathListSeparator(env.osType())); - } - setEnvironment(env); } + if (env.hasChanges()) + setEnvironment(env); StdIOClientInterface::startImpl(); } };