forked from qt-creator/qt-creator
Python: Use a separate PythonInterpreterAspect
... and move interpreter related code there. Change-Id: I108a4bdfa7c3f2078da164ce13e897a18ebdadde Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -119,26 +119,38 @@ private:
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class PythonRunConfigurationPrivate
|
class PythonInterpreterAspect final : public InterpreterAspect
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PythonRunConfigurationPrivate(PythonRunConfiguration *rc)
|
PythonInterpreterAspect(PythonRunConfiguration *rc)
|
||||||
: q(rc)
|
: q(rc)
|
||||||
{}
|
{
|
||||||
~PythonRunConfigurationPrivate()
|
connect(this, &InterpreterAspect::changed,
|
||||||
|
this, &PythonInterpreterAspect::currentInterpreterChanged);
|
||||||
|
currentInterpreterChanged();
|
||||||
|
|
||||||
|
connect(PySideInstaller::instance(), &PySideInstaller::pySideInstalled, this,
|
||||||
|
[this](const FilePath &python) {
|
||||||
|
if (python == currentInterpreter().command)
|
||||||
|
checkForPySide(python);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
~PythonInterpreterAspect()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_extraCompilers);
|
qDeleteAll(m_extraCompilers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForPySide(const Utils::FilePath &python);
|
void checkForPySide(const FilePath &python);
|
||||||
void checkForPySide(const Utils::FilePath &python, const QString &pySidePackageName);
|
void checkForPySide(const FilePath &python, const QString &pySidePackageName);
|
||||||
void handlePySidePackageInfo(const PipPackageInfo &pySideInfo,
|
void handlePySidePackageInfo(const PipPackageInfo &pySideInfo,
|
||||||
const Utils::FilePath &python,
|
const FilePath &python,
|
||||||
const QString &requestedPackageName);
|
const QString &requestedPackageName);
|
||||||
void updateExtraCompilers();
|
void updateExtraCompilers();
|
||||||
void currentInterpreterChanged();
|
void currentInterpreterChanged();
|
||||||
|
|
||||||
Utils::FilePath m_pySideUicPath;
|
FilePath m_pySideUicPath;
|
||||||
|
|
||||||
PythonRunConfiguration *q;
|
PythonRunConfiguration *q;
|
||||||
QList<PySideUicExtraCompiler *> m_extraCompilers;
|
QList<PySideUicExtraCompiler *> m_extraCompilers;
|
||||||
@@ -148,15 +160,11 @@ public:
|
|||||||
|
|
||||||
PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
|
PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
|
||||||
: RunConfiguration(target, id)
|
: RunConfiguration(target, id)
|
||||||
, d(new PythonRunConfigurationPrivate(this))
|
|
||||||
{
|
{
|
||||||
auto interpreterAspect = addAspect<InterpreterAspect>();
|
auto interpreterAspect = addAspect<PythonInterpreterAspect>(this);
|
||||||
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
||||||
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
|
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
|
||||||
|
|
||||||
connect(interpreterAspect, &InterpreterAspect::changed, this,
|
|
||||||
[this] { d->currentInterpreterChanged(); });
|
|
||||||
|
|
||||||
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
|
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
|
||||||
interpreterAspect, &InterpreterAspect::updateInterpreters);
|
interpreterAspect, &InterpreterAspect::updateInterpreters);
|
||||||
|
|
||||||
@@ -219,27 +227,17 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
|
||||||
connect(target, &Target::buildSystemUpdated, this, [this]() { d->updateExtraCompilers(); });
|
connect(target, &Target::buildSystemUpdated, this, [this, interpreterAspect] { interpreterAspect->updateExtraCompilers(); });
|
||||||
d->currentInterpreterChanged();
|
|
||||||
|
|
||||||
connect(PySideInstaller::instance(), &PySideInstaller::pySideInstalled, this,
|
|
||||||
[this](const FilePath &python) {
|
|
||||||
if (python == aspect<InterpreterAspect>()->currentInterpreter().command)
|
|
||||||
d->checkForPySide(python);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PythonRunConfiguration::~PythonRunConfiguration()
|
PythonRunConfiguration::~PythonRunConfiguration() = default;
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PythonRunConfigurationPrivate::checkForPySide(const FilePath &python)
|
void PythonInterpreterAspect::checkForPySide(const FilePath &python)
|
||||||
{
|
{
|
||||||
checkForPySide(python, "PySide6-Essentials");
|
checkForPySide(python, "PySide6-Essentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonRunConfigurationPrivate::checkForPySide(const FilePath &python,
|
void PythonInterpreterAspect::checkForPySide(const FilePath &python,
|
||||||
const QString &pySidePackageName)
|
const QString &pySidePackageName)
|
||||||
{
|
{
|
||||||
const PipPackage package(pySidePackageName);
|
const PipPackage package(pySidePackageName);
|
||||||
@@ -252,7 +250,7 @@ void PythonRunConfigurationPrivate::checkForPySide(const FilePath &python,
|
|||||||
ExtensionSystem::PluginManager::futureSynchronizer()->addFuture(future);
|
ExtensionSystem::PluginManager::futureSynchronizer()->addFuture(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonRunConfigurationPrivate::handlePySidePackageInfo(const PipPackageInfo &pySideInfo,
|
void PythonInterpreterAspect::handlePySidePackageInfo(const PipPackageInfo &pySideInfo,
|
||||||
const Utils::FilePath &python,
|
const Utils::FilePath &python,
|
||||||
const QString &requestedPackageName)
|
const QString &requestedPackageName)
|
||||||
{
|
{
|
||||||
@@ -308,9 +306,9 @@ void PythonRunConfigurationPrivate::handlePySidePackageInfo(const PipPackageInfo
|
|||||||
pySideBuildStep->updatePySideProjectPath(pythonTools.pySideProjectPath);
|
pySideBuildStep->updatePySideProjectPath(pythonTools.pySideProjectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonRunConfigurationPrivate::currentInterpreterChanged()
|
void PythonInterpreterAspect::currentInterpreterChanged()
|
||||||
{
|
{
|
||||||
const FilePath python = q->aspect<InterpreterAspect>()->currentInterpreter().command;
|
const FilePath python = currentInterpreter().command;
|
||||||
checkForPySide(python);
|
checkForPySide(python);
|
||||||
|
|
||||||
for (FilePath &file : q->project()->files(Project::AllFiles)) {
|
for (FilePath &file : q->project()->files(Project::AllFiles)) {
|
||||||
@@ -326,10 +324,10 @@ void PythonRunConfigurationPrivate::currentInterpreterChanged()
|
|||||||
|
|
||||||
QList<PySideUicExtraCompiler *> PythonRunConfiguration::extraCompilers() const
|
QList<PySideUicExtraCompiler *> PythonRunConfiguration::extraCompilers() const
|
||||||
{
|
{
|
||||||
return d->m_extraCompilers;
|
return static_cast<PythonInterpreterAspect *>(aspect<InterpreterAspect>())->m_extraCompilers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonRunConfigurationPrivate::updateExtraCompilers()
|
void PythonInterpreterAspect::updateExtraCompilers()
|
||||||
{
|
{
|
||||||
QList<PySideUicExtraCompiler *> oldCompilers = m_extraCompilers;
|
QList<PySideUicExtraCompiler *> oldCompilers = m_extraCompilers;
|
||||||
m_extraCompilers.clear();
|
m_extraCompilers.clear();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
namespace Python::Internal {
|
namespace Python::Internal {
|
||||||
|
|
||||||
class PythonRunConfigurationPrivate;
|
|
||||||
class PySideUicExtraCompiler;
|
class PySideUicExtraCompiler;
|
||||||
|
|
||||||
class PythonRunConfiguration : public ProjectExplorer::RunConfiguration
|
class PythonRunConfiguration : public ProjectExplorer::RunConfiguration
|
||||||
@@ -20,9 +19,6 @@ public:
|
|||||||
~PythonRunConfiguration() override;
|
~PythonRunConfiguration() override;
|
||||||
|
|
||||||
QList<PySideUicExtraCompiler *> extraCompilers() const;
|
QList<PySideUicExtraCompiler *> extraCompilers() const;
|
||||||
|
|
||||||
private:
|
|
||||||
PythonRunConfigurationPrivate *d = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PythonRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory
|
class PythonRunConfigurationFactory : public ProjectExplorer::RunConfigurationFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user