aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2023-12-13 08:06:41 +0100
committerDavid Schulz <david.schulz@qt.io>2024-01-08 10:42:48 +0000
commit4f857711c2dfdd3214948bc7d19e368db2fd37eb (patch)
tree0b7f768e084bacbd83b5fba423e619ffd52f5bdd /src/plugins/python
parent7a0cae607ebbf3ba81b76a53c85c7c1842647740 (diff)
Python: install lsp into tempdir for remote interpreters
Change-Id: I4b0b1a47c73742cc14f68d80b9116fcd51224bd1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python')
-rw-r--r--src/plugins/python/pipsupport.cpp9
-rw-r--r--src/plugins/python/pythonlanguageclient.cpp30
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 <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
@@ -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<FilePath, PyLSClient*> &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<FilePath> 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();
}
};