forked from qt-creator/qt-creator
Python: Allow installing requirement files
Change-Id: If4ac1470fdba4b9f1070fc37d35d5d738a18865f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -35,6 +35,16 @@ PipInstallTask::PipInstallTask(const FilePath &python)
|
|||||||
m_watcher.setFuture(m_future.future());
|
m_watcher.setFuture(m_future.future());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PipInstallTask::setRequirements(const Utils::FilePath &requirementFile)
|
||||||
|
{
|
||||||
|
m_requirementsFile = requirementFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PipInstallTask::setWorkingDirectory(const Utils::FilePath &workingDirectory)
|
||||||
|
{
|
||||||
|
m_process.setWorkingDirectory(workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
void PipInstallTask::addPackage(const PipPackage &package)
|
void PipInstallTask::addPackage(const PipPackage &package)
|
||||||
{
|
{
|
||||||
m_packages << package;
|
m_packages << package;
|
||||||
@@ -47,19 +57,23 @@ void PipInstallTask::setPackages(const QList<PipPackage> &packages)
|
|||||||
|
|
||||||
void PipInstallTask::run()
|
void PipInstallTask::run()
|
||||||
{
|
{
|
||||||
if (m_packages.isEmpty()) {
|
if (m_packages.isEmpty() && m_requirementsFile.isEmpty()) {
|
||||||
emit finished(false);
|
emit finished(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QString taskTitle = Tr::tr("Install Python Packages");
|
const QString taskTitle = Tr::tr("Install Python Packages");
|
||||||
Core::ProgressManager::addTask(m_future.future(), taskTitle, pipInstallTaskId);
|
Core::ProgressManager::addTask(m_future.future(), taskTitle, pipInstallTaskId);
|
||||||
QStringList arguments = {"-m", "pip", "install"};
|
QStringList arguments = {"-m", "pip", "install"};
|
||||||
|
if (!m_requirementsFile.isEmpty())
|
||||||
|
arguments << "-r" << m_requirementsFile.toString();
|
||||||
|
else {
|
||||||
for (const PipPackage &package : m_packages) {
|
for (const PipPackage &package : m_packages) {
|
||||||
QString pipPackage = package.packageName;
|
QString pipPackage = package.packageName;
|
||||||
if (!package.version.isEmpty())
|
if (!package.version.isEmpty())
|
||||||
pipPackage += "==" + package.version;
|
pipPackage += "==" + package.version;
|
||||||
arguments << pipPackage;
|
arguments << pipPackage;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add --user to global pythons, but skip it for venv pythons
|
// add --user to global pythons, but skip it for venv pythons
|
||||||
if (!QDir(m_python.parentDir().toString()).exists("activate"))
|
if (!QDir(m_python.parentDir().toString()).exists("activate"))
|
||||||
@@ -115,7 +129,9 @@ void PipInstallTask::handleError()
|
|||||||
|
|
||||||
QString PipInstallTask::packagesDisplayName() const
|
QString PipInstallTask::packagesDisplayName() const
|
||||||
{
|
{
|
||||||
return Utils::transform(m_packages, &PipPackage::displayName).join(", ");
|
return m_requirementsFile.isEmpty()
|
||||||
|
? Utils::transform(m_packages, &PipPackage::displayName).join(", ")
|
||||||
|
: m_requirementsFile.toUserOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipPackageInfo::parseField(const QString &field, const QStringList &data)
|
void PipPackageInfo::parseField(const QString &field, const QStringList &data)
|
||||||
|
@@ -63,6 +63,8 @@ class PipInstallTask : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit PipInstallTask(const Utils::FilePath &python);
|
explicit PipInstallTask(const Utils::FilePath &python);
|
||||||
|
void setRequirements(const Utils::FilePath &requirementFile);
|
||||||
|
void setWorkingDirectory(const Utils::FilePath &workingDirectory);
|
||||||
void addPackage(const PipPackage &package);
|
void addPackage(const PipPackage &package);
|
||||||
void setPackages(const QList<PipPackage> &packages);
|
void setPackages(const QList<PipPackage> &packages);
|
||||||
void run();
|
void run();
|
||||||
@@ -80,6 +82,7 @@ private:
|
|||||||
|
|
||||||
const Utils::FilePath m_python;
|
const Utils::FilePath m_python;
|
||||||
QList<PipPackage> m_packages;
|
QList<PipPackage> m_packages;
|
||||||
|
Utils::FilePath m_requirementsFile;
|
||||||
Utils::Process m_process;
|
Utils::Process m_process;
|
||||||
QFutureInterface<void> m_future;
|
QFutureInterface<void> m_future;
|
||||||
QFutureWatcher<void> m_watcher;
|
QFutureWatcher<void> m_watcher;
|
||||||
|
Reference in New Issue
Block a user