Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ doc/html/*
# union code gen
.unioncode
*.unioncode
.cursorindexingignore
.specstory
43 changes: 34 additions & 9 deletions src/plugins/python/installer/pipinstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
1 change: 1 addition & 0 deletions src/plugins/python/installer/pipinstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

Expand Down
Loading