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>
This commit is contained in:
David Schulz
2023-11-27 14:15:29 +01:00
parent 1200419059
commit fbe054116a
6 changed files with 68 additions and 53 deletions

View File

@@ -55,6 +55,11 @@ void PipInstallTask::setPackages(const QList<PipPackage> &packages)
m_packages = packages;
}
void PipInstallTask::setTargetPath(const Utils::FilePath &targetPath)
{
m_targetPath = targetPath;
}
void PipInstallTask::run()
{
if (m_packages.isEmpty() && m_requirementsFile.isEmpty()) {
@@ -75,9 +80,10 @@ void PipInstallTask::run()
}
}
// add --user to global pythons, but skip it for venv pythons
if (!QDir(m_python.parentDir().toString()).exists("activate"))
arguments << "--user";
if (!m_targetPath.isEmpty())
arguments << "-t" << m_targetPath.toString();
else if (!QDir(m_python.parentDir().toString()).exists("activate"))
arguments << "--user"; // add --user to global pythons, but skip it for venv pythons
m_process.setCommand({m_python, arguments});
m_process.setTerminalMode(TerminalMode::Run);