From 2a29acdbaf8e5a82deb7a59028da39be12661aab Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 1 Feb 2024 14:14:38 +0100 Subject: [PATCH] Python: Use setup function for build related factories Change-Id: I3b1faad8a5f3ead1332941d31509c3efd3806f78 Reviewed-by: David Schulz --- .../python/pythonbuildconfiguration.cpp | 92 +++++++++++-------- src/plugins/python/pythonbuildconfiguration.h | 13 +-- src/plugins/python/pythonplugin.cpp | 5 +- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/src/plugins/python/pythonbuildconfiguration.cpp b/src/plugins/python/pythonbuildconfiguration.cpp index 9728dc44515..eb31d27401e 100644 --- a/src/plugins/python/pythonbuildconfiguration.cpp +++ b/src/plugins/python/pythonbuildconfiguration.cpp @@ -44,14 +44,6 @@ using namespace Utils; namespace Python::Internal { -PySideBuildStepFactory::PySideBuildStepFactory() -{ - registerStep(PySideBuildStep::id()); - setSupportedProjectType(PythonProjectId); - setDisplayName(Tr::tr("Run PySide6 project tool")); - setFlags(BuildStep::UniqueStep); -} - PySideBuildStep::PySideBuildStep(BuildStepList *bsl, Id id) : AbstractProcessStep(bsl, id) { @@ -245,6 +237,25 @@ private: DetailsWidget *m_configureDetailsWidget; }; +class PySideBuildStepFactory final : public BuildStepFactory +{ +public: + PySideBuildStepFactory() + { + registerStep(PySideBuildStep::id()); + setSupportedProjectType(PythonProjectId); + setDisplayName(Tr::tr("Run PySide6 project tool")); + setFlags(BuildStep::UniqueStep); + } +}; + +void setupPySideBuildStep() +{ + static PySideBuildStepFactory thePySideBuildStepFactory; +} + +// PythonBuildConfiguration + PythonBuildConfiguration::PythonBuildConfiguration(Target *target, const Id &id) : BuildConfiguration(target, id) , m_buildSystem(std::make_unique(this)) @@ -378,38 +389,47 @@ std::optional PythonBuildConfiguration::venv() const return m_venv; } -PythonBuildConfigurationFactory::PythonBuildConfigurationFactory() +class PythonBuildConfigurationFactory final : public BuildConfigurationFactory { - registerBuildConfiguration("Python.PySideBuildConfiguration"); - setSupportedProjectType(PythonProjectId); - setSupportedProjectMimeTypeName(Constants::C_PY_PROJECT_MIME_TYPE); - setBuildGenerator([](const Kit *k, const FilePath &projectPath, bool forSetup) { - if (std::optional python = PythonKitAspect::python(k)) { - BuildInfo base; - base.buildDirectory = projectPath.parentDir(); - base.displayName = python->name; - base.typeName = Tr::tr("Global Python"); - base.showBuildDirConfigWidget = false; +public: + PythonBuildConfigurationFactory() + { + registerBuildConfiguration("Python.PySideBuildConfiguration"); + setSupportedProjectType(PythonProjectId); + setSupportedProjectMimeTypeName(Constants::C_PY_PROJECT_MIME_TYPE); + setBuildGenerator([](const Kit *k, const FilePath &projectPath, bool forSetup) { + if (std::optional python = PythonKitAspect::python(k)) { + BuildInfo base; + base.buildDirectory = projectPath.parentDir(); + base.displayName = python->name; + base.typeName = Tr::tr("Global Python"); + base.showBuildDirConfigWidget = false; - if (isVenvPython(python->command) || !venvIsUsable(python->command)) - return QList{base}; + if (isVenvPython(python->command) || !venvIsUsable(python->command)) + return QList{base}; - base.enabledByDefault = false; + base.enabledByDefault = false; - BuildInfo venv; - const FilePath venvBase = projectPath.parentDir() / ".qtcreator" - / FileUtils::fileSystemFriendlyName(python->name + "venv"); - venv.buildDirectory = venvBase; - int i = 2; - while (venv.buildDirectory.exists()) - venv.buildDirectory = venvBase.stringAppended('_' + QString::number(i++)); - venv.displayName = python->name + Tr::tr(" Virtual Environment"); - venv.typeName = venvTypeName(); - venv.extraInfo = QVariantMap{{"createVenv", forSetup}}; - return QList{base, venv}; - } - return QList{}; - }); + BuildInfo venv; + const FilePath venvBase = projectPath.parentDir() / ".qtcreator" + / FileUtils::fileSystemFriendlyName(python->name + "venv"); + venv.buildDirectory = venvBase; + int i = 2; + while (venv.buildDirectory.exists()) + venv.buildDirectory = venvBase.stringAppended('_' + QString::number(i++)); + venv.displayName = python->name + Tr::tr(" Virtual Environment"); + venv.typeName = venvTypeName(); + venv.extraInfo = QVariantMap{{"createVenv", forSetup}}; + return QList{base, venv}; + } + return QList{}; + }); + } +}; + +void setupPythonBuildConfiguration() +{ + static PythonBuildConfigurationFactory thePythonBuildConfigurationFactory; } } // Python::Internal diff --git a/src/plugins/python/pythonbuildconfiguration.h b/src/plugins/python/pythonbuildconfiguration.h index a4d9440bdb1..61b87b4c670 100644 --- a/src/plugins/python/pythonbuildconfiguration.h +++ b/src/plugins/python/pythonbuildconfiguration.h @@ -46,12 +46,6 @@ private: QList m_extraCompilers; }; -class PySideBuildStepFactory : public ProjectExplorer::BuildStepFactory -{ -public: - PySideBuildStepFactory(); -}; - class PythonBuildConfiguration : public ProjectExplorer::BuildConfiguration { Q_OBJECT @@ -77,10 +71,7 @@ private: std::unique_ptr m_buildSystem; }; -class PythonBuildConfigurationFactory : public ProjectExplorer::BuildConfigurationFactory -{ -public: - PythonBuildConfigurationFactory(); -}; +void setupPySideBuildStep(); +void setupPythonBuildConfiguration(); } // namespace Python::Internal diff --git a/src/plugins/python/pythonplugin.cpp b/src/plugins/python/pythonplugin.cpp index 99334992e49..db914afc083 100644 --- a/src/plugins/python/pythonplugin.cpp +++ b/src/plugins/python/pythonplugin.cpp @@ -44,8 +44,6 @@ class PythonPluginPrivate { public: PythonRunConfigurationFactory runConfigFactory; - PySideBuildStepFactory buildStepFactory; - PythonBuildConfigurationFactory buildConfigFactory; SimpleTargetRunnerFactory runWorkerFactory{{runConfigFactory.runConfigurationId()}}; SimpleDebugRunnerFactory debugRunWorkerFactory{{runConfigFactory.runConfigurationId()}, {ProjectExplorer::Constants::DAP_PY_DEBUG_RUN_MODE}}; PythonSettings settings; @@ -76,6 +74,9 @@ private: setupPythonEditorFactory(this); + setupPySideBuildStep(); + setupPythonBuildConfiguration(); + setupPythonOutputParser(); KitManager::setIrrelevantAspects(KitManager::irrelevantAspects()