diff --git a/.gitignore b/.gitignore index 9f8c5d665..675269b24 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,5 @@ doc/html/* # union code gen .unioncode *.unioncode +.cursorindexingignore +.specstory diff --git a/src/plugins/python/installer/pipinstaller.cpp b/src/plugins/python/installer/pipinstaller.cpp index 7da01cabd..3129bfa73 100644 --- a/src/plugins/python/installer/pipinstaller.cpp +++ b/src/plugins/python/installer/pipinstaller.cpp @@ -35,6 +35,15 @@ void PIPInstaller::install(const InstallInfo &info) return install("python3", info); } +bool PIPInstaller::checkPipExists(const QString &python) +{ + QProcess process; + process.start(python, { "-m", "pip", "--version" }); + process.waitForFinished(); + + return process.exitCode() == 0; +} + bool PIPInstaller::checkInstalled(const QString &python, const QString &package) { // remove extra dependency @@ -61,16 +70,32 @@ void PIPInstaller::install(const QString &python, const InstallInfo &info) if (!termSrv) termSrv = dpfGetService(TerminalService); - QStringList args { "-m", "pip", "install" }; - args << info.packageList - << "--target" - << Utils::packageInstallPath(python); - + uiController.doSwitch(MWNA_EDIT); + uiController.switchContext(TERMINAL_TAB_TEXT); const auto &map = OptionManager::getInstance()->getValue(option::CATEGORY_PYTHON, "Interpreter").toMap(); const auto &pipSrc = map.value("pipSource").toString(); - if (!pipSrc.isEmpty()) - args << "-i" << pipSrc; - uiController.switchContext(TERMINAL_TAB_TEXT); - termSrv->executeCommand(info.plugin.isEmpty() ? "PIPInstaller" : info.plugin, python, args, "", QStringList()); + // Check if pip exists, if not install python3-pip first + if (!checkPipExists(python)) { + // Install python3-pip and then install packages in one command + QString installCommand = QString("apt install python3-pip -y && %1 -m pip install").arg(python); + QStringList packages = info.packageList; + installCommand += " " + packages.join(" "); + installCommand += " --target " + Utils::packageInstallPath(python); + if (!pipSrc.isEmpty()) + installCommand += " -i " + pipSrc; + + termSrv->executeCommand(info.plugin.isEmpty() ? "PIPInstaller" : info.plugin, "sudo", { installCommand }, "", QStringList()); + } else { + // pip exists, install packages directly + QStringList args { "-m", "pip", "install" }; + args << info.packageList + << "--target" + << Utils::packageInstallPath(python); + + if (!pipSrc.isEmpty()) + args << "-i" << pipSrc; + + termSrv->executeCommand(info.plugin.isEmpty() ? "PIPInstaller" : info.plugin, python, args, "", QStringList()); + } } diff --git a/src/plugins/python/installer/pipinstaller.h b/src/plugins/python/installer/pipinstaller.h index ce3380132..8cd6d3f27 100644 --- a/src/plugins/python/installer/pipinstaller.h +++ b/src/plugins/python/installer/pipinstaller.h @@ -25,6 +25,7 @@ class PIPInstaller : public AbstractInstaller void install(const QString &python, const InstallInfo &info); private: + bool checkPipExists(const QString &python); dpfservice::TerminalService *termSrv { nullptr }; };