diff --git a/src/plugins/python/pipsupport.cpp b/src/plugins/python/pipsupport.cpp index 96aa4f64e2f..e84e8f63a6d 100644 --- a/src/plugins/python/pipsupport.cpp +++ b/src/plugins/python/pipsupport.cpp @@ -35,23 +35,31 @@ PipInstallTask::PipInstallTask(const FilePath &python) m_watcher.setFuture(m_future.future()); } -void PipInstallTask::setPackage(const PipPackage &package) +void PipInstallTask::addPackage(const PipPackage &package) { - m_package = package; + m_packages << package; +} + +void PipInstallTask::setPackages(const QList &packages) +{ + m_packages = packages; } void PipInstallTask::run() { - if (m_package.packageName.isEmpty()) { + if (m_packages.isEmpty()) { emit finished(false); return; } - const QString taskTitle = Tr::tr("Install %1").arg(m_package.displayName); + const QString taskTitle = Tr::tr("Install Python Packages"); Core::ProgressManager::addTask(m_future.future(), taskTitle, pipInstallTaskId); - QString package = m_package.packageName; - if (!m_package.version.isEmpty()) - package += "==" + m_package.version; - QStringList arguments = {"-m", "pip", "install", package}; + QStringList arguments = {"-m", "pip", "install"}; + for (const PipPackage &package : m_packages) { + QString pipPackage = package.packageName; + if (!package.version.isEmpty()) + pipPackage += "==" + package.version; + arguments << pipPackage; + } // add --user to global pythons, but skip it for venv pythons if (!QDir(m_python.parentDir().toString()).exists("activate")) @@ -62,7 +70,7 @@ void PipInstallTask::run() Core::MessageManager::writeDisrupting( Tr::tr("Running \"%1\" to install %2.") - .arg(m_process.commandLine().toUserOutput(), m_package.displayName)); + .arg(m_process.commandLine().toUserOutput(), packagesDisplayName())); m_killTimer.setSingleShot(true); m_killTimer.start(5 /*minutes*/ * 60 * 1000); @@ -74,7 +82,7 @@ void PipInstallTask::cancel() m_process.waitForFinished(); Core::MessageManager::writeFlashing( Tr::tr("The %1 installation was canceled by %2.") - .arg(m_package.displayName, m_killTimer.isActive() ? Tr::tr("user") : Tr::tr("time out"))); + .arg(packagesDisplayName(), m_killTimer.isActive() ? Tr::tr("user") : Tr::tr("time out"))); } void PipInstallTask::handleDone() @@ -82,8 +90,8 @@ void PipInstallTask::handleDone() m_future.reportFinished(); const bool success = m_process.result() == ProcessResult::FinishedWithSuccess; if (!success) { - Core::MessageManager::writeFlashing(Tr::tr("Installing the %1 failed with exit code %2") - .arg(m_package.displayName).arg(m_process.exitCode())); + Core::MessageManager::writeFlashing(Tr::tr("Installing %1 failed with exit code %2") + .arg(packagesDisplayName()).arg(m_process.exitCode())); } emit finished(success); } @@ -102,6 +110,11 @@ void PipInstallTask::handleError() Core::MessageManager::writeSilently(stdErr); } +QString PipInstallTask::packagesDisplayName() const +{ + return Utils::transform(m_packages, &PipPackage::displayName).join(", "); +} + void PipPackageInfo::parseField(const QString &field, const QStringList &data) { if (field.isEmpty()) diff --git a/src/plugins/python/pipsupport.h b/src/plugins/python/pipsupport.h index e5f53768ce9..aa17edca82f 100644 --- a/src/plugins/python/pipsupport.h +++ b/src/plugins/python/pipsupport.h @@ -66,7 +66,8 @@ class PipInstallTask : public QObject Q_OBJECT public: explicit PipInstallTask(const Utils::FilePath &python); - void setPackage(const PipPackage &package); + void addPackage(const PipPackage &package); + void setPackages(const QList &packages); void run(); signals: @@ -78,8 +79,10 @@ private: void handleOutput(); void handleError(); + QString packagesDisplayName() const; + const Utils::FilePath m_python; - PipPackage m_package; + QList m_packages; Utils::QtcProcess m_process; QFutureInterface m_future; QFutureWatcher m_watcher; diff --git a/src/plugins/python/pyside.cpp b/src/plugins/python/pyside.cpp index f994108cae0..1309f777ed9 100644 --- a/src/plugins/python/pyside.cpp +++ b/src/plugins/python/pyside.cpp @@ -88,7 +88,7 @@ void PySideInstaller::installPyside(const FilePath &python, if (success) emit pySideInstalled(python, pySide); }); - install->setPackage(PipPackage(pySide)); + install->setPackages({PipPackage(pySide)}); install->run(); } diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp index 088cd516440..cd95d4d329f 100644 --- a/src/plugins/python/pythonlanguageclient.cpp +++ b/src/plugins/python/pythonlanguageclient.cpp @@ -305,7 +305,7 @@ void PyLSConfigureAssistant::installPythonLanguageServer(const FilePath &python, install->deleteLater(); }); - install->setPackage(PipPackage{"python-lsp-server[all]", "Python Language Server"}); + install->setPackages({PipPackage{"python-lsp-server[all]", "Python Language Server"}}); install->run(); }