Python: Remove pluginInstance() and convert users

Change-Id: I43179961cdee855b710fc082568a7d0d9a0f0719
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2024-02-01 16:37:40 +01:00
parent f589ed7f1e
commit ca2a4f771f
11 changed files with 33 additions and 56 deletions

View File

@@ -15,7 +15,7 @@ add_qtc_plugin(Python
pythonindenter.cpp pythonindenter.h
pythonkitaspect.h pythonkitaspect.cpp
pythonlanguageclient.cpp pythonlanguageclient.h
pythonplugin.cpp pythonplugin.h
pythonplugin.cpp
pythonproject.cpp pythonproject.h
pythonrunconfiguration.cpp pythonrunconfiguration.h
pythonscanner.cpp pythonscanner.h

View File

@@ -3,7 +3,6 @@
#include "pipsupport.h"
#include "pythonplugin.h"
#include "pythontr.h"
#include "pythonutils.h"
@@ -220,9 +219,16 @@ QFuture<PipPackageInfo> Pip::info(const PipPackage &package)
return Utils::asyncRun(infoImpl, package, m_python);
}
Pip::Pip(const Utils::FilePath &python)
: QObject(pluginInstance())
static QObject *thePipGuard = nullptr;
Pip::Pip(const FilePath &python)
: QObject(thePipGuard)
, m_python(python)
{}
void setupPipSupport(QObject *guard)
{
thePipGuard = guard;
}
} // Python::Internal

View File

@@ -91,4 +91,6 @@ private:
QTimer m_killTimer;
};
void setupPipSupport(QObject *guard);
} // Python::Internal

View File

@@ -4,7 +4,6 @@
#include "pyside.h"
#include "pipsupport.h"
#include "pythonplugin.h"
#include "pythontr.h"
#include "pythonutils.h"
@@ -36,23 +35,17 @@ namespace Python::Internal {
const char installPySideInfoBarId[] = "Python::InstallPySide";
PySideInstaller *PySideInstaller::instance()
{
static PySideInstaller *instance = new PySideInstaller; // FIXME: Leaks.
return instance;
}
void PySideInstaller::checkPySideInstallation(const FilePath &python,
TextEditor::TextDocument *document)
{
document->infoBar()->removeInfo(installPySideInfoBarId);
if (QPointer<QFutureWatcher<bool>> watcher = instance()->m_futureWatchers.value(document))
if (QPointer<QFutureWatcher<bool>> watcher = pySideInstaller().m_futureWatchers.value(document))
watcher->cancel();
if (!python.exists())
return;
const QString pySide = importedPySide(document->plainText());
if (pySide == "PySide2" || pySide == "PySide6")
instance()->runPySideChecker(python, pySide, document);
pySideInstaller().runPySideChecker(python, pySide, document);
}
bool PySideInstaller::missingPySideInstallation(const FilePath &pythonPath,
@@ -80,9 +73,7 @@ QString PySideInstaller::importedPySide(const QString &text)
return match.captured(2);
}
PySideInstaller::PySideInstaller()
: QObject(pluginInstance())
{}
PySideInstaller::PySideInstaller() = default;
void PySideInstaller::installPyside(const FilePath &python,
const QString &pySide,
@@ -228,4 +219,10 @@ void PySideInstaller::runPySideChecker(const FilePath &python,
m_futureWatchers[document] = watcher;
}
PySideInstaller &pySideInstaller()
{
static PySideInstaller thePySideInstaller;
return thePySideInstaller;
}
} // Python::Internal

View File

@@ -27,7 +27,6 @@ class PySideInstaller : public QObject
Q_OBJECT
public:
static PySideInstaller *instance();
static void checkPySideInstallation(const Utils::FilePath &python,
TextEditor::TextDocument *document);
@@ -36,6 +35,7 @@ signals:
private:
PySideInstaller();
friend PySideInstaller &pySideInstaller();
void installPyside(const Utils::FilePath &python,
const QString &pySide, TextEditor::TextDocument *document);
@@ -53,4 +53,6 @@ private:
QHash<TextEditor::TextDocument *, QPointer<QFutureWatcher<bool>>> m_futureWatchers;
};
PySideInstaller &pySideInstaller();
} // Python::Internal

View File

@@ -42,7 +42,6 @@ QtcPlugin {
"pythonlanguageclient.cpp",
"pythonlanguageclient.h",
"pythonplugin.cpp",
"pythonplugin.h",
"pythonproject.cpp",
"pythonproject.h",
"pythonrunconfiguration.cpp",

View File

@@ -264,7 +264,7 @@ PythonBuildConfiguration::PythonBuildConfiguration(Target *target, const Id &id)
updateCacheAndEmitEnvironmentChanged();
connect(PySideInstaller::instance(),
connect(&pySideInstaller(),
&PySideInstaller::pySideInstalled,
this,
&PythonBuildConfiguration::handlePythonUpdated);

View File

@@ -1,8 +1,7 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "pythonplugin.h"
#include "pipsupport.h"
#include "pythonbuildconfiguration.h"
#include "pythonconstants.h"
#include "pythoneditor.h"
@@ -33,30 +32,11 @@ using namespace Utils;
namespace Python::Internal {
static QObject *m_instance = nullptr;
QObject *pluginInstance()
{
return m_instance;
}
class PythonPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Python.json")
public:
PythonPlugin()
{
m_instance = this;
}
~PythonPlugin() final
{
m_instance = nullptr;
}
private:
void initialize() final
{
setupPythonEditorFactory(this);
@@ -72,6 +52,8 @@ private:
setupPythonSettings(this);
setupPythonWizard();
setupPipSupport(this);
KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()
+ QSet<Id>{PythonKitAspect::id()});

View File

@@ -1,12 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <QObject>
namespace Python::Internal {
QObject *pluginInstance();
} // Python::Internal

View File

@@ -5,7 +5,6 @@
#include "pythonconstants.h"
#include "pythonkitaspect.h"
#include "pythonplugin.h"
#include "pythontr.h"
#include "pythonutils.h"
@@ -619,7 +618,7 @@ static QString defaultPylsConfiguration()
return QString::fromUtf8(QJsonDocument(configuration).toJson());
}
static void disableOutdatedPylsNow()
void PythonSettings::disableOutdatedPylsNow()
{
using namespace LanguageClient;
const QList<BaseSettings *>
@@ -635,14 +634,14 @@ static void disableOutdatedPylsNow()
}
}
static void disableOutdatedPyls()
void PythonSettings::disableOutdatedPyls()
{
using namespace ExtensionSystem;
if (PluginManager::isInitializationDone()) {
disableOutdatedPylsNow();
} else {
QObject::connect(PluginManager::instance(), &PluginManager::initializationDone,
pluginInstance(), &disableOutdatedPylsNow);
this, &PythonSettings::disableOutdatedPylsNow);
}
}

View File

@@ -59,6 +59,8 @@ public slots:
void listDetectedPython(const QString &detectionSource, QString *logMessage);
private:
void disableOutdatedPyls();
void disableOutdatedPylsNow();
void fixupPythonKits();
void initFromSettings(Utils::QtcSettings *settings);
void writeToSettings(Utils::QtcSettings *settings);