From d1b57be370656b8b536819ca8a95b45f414ae581 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Mon, 30 Nov 2020 20:00:04 +0100 Subject: [PATCH] Make python plugins optional during the build process --- .../thingmanagerimplementation.cpp | 10 +++++ libnymea-core/libnymea-core.pro | 43 ++++++++++++------- nymea.pro | 1 - 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/libnymea-core/integrations/thingmanagerimplementation.cpp b/libnymea-core/integrations/thingmanagerimplementation.cpp index fa164ab3..694fd9a3 100644 --- a/libnymea-core/integrations/thingmanagerimplementation.cpp +++ b/libnymea-core/integrations/thingmanagerimplementation.cpp @@ -33,7 +33,9 @@ #if QT_VERSION >= QT_VERSION_CHECK(5,12,0) #include "scriptintegrationplugin.h" #endif +#ifdef WITH_PYTHON #include "pythonintegrationplugin.h" +#endif #include "loggingcategories.h" #include "typeutils.h" @@ -98,7 +100,9 @@ ThingManagerImplementation::ThingManagerImplementation(HardwareManager *hardware // Make sure this is always emitted after plugins and things are loaded QMetaObject::invokeMethod(this, "onLoaded", Qt::QueuedConnection); +#ifdef WITH_PYTHON PythonIntegrationPlugin::initPython(); +#endif } ThingManagerImplementation::~ThingManagerImplementation() @@ -120,7 +124,9 @@ ThingManagerImplementation::~ThingManagerImplementation() } } +#ifdef WITH_PYTHON PythonIntegrationPlugin::deinitPython(); +#endif } QStringList ThingManagerImplementation::pluginSearchDirs() @@ -1293,6 +1299,7 @@ void ThingManagerImplementation::loadPlugins() qCWarning(dcThingManager()) << "Not loading JS plugin as JS plugin support is not included in this nymea instance."; #endif } else if (entry.startsWith("integrationplugin") && entry.endsWith(".py")) { +#ifdef WITH_PYTHON PythonIntegrationPlugin *p = new PythonIntegrationPlugin(this); bool ok = p->loadScript(fi.absoluteFilePath()); if (ok) { @@ -1300,6 +1307,9 @@ void ThingManagerImplementation::loadPlugins() } else { delete p; } +#else + qCWarning(dcThingManager()) << "Not loading Python plugin as Python plugin support is not included in this nymea instance.2"; +#endif } else { // Not a known plugin type continue; diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 0b00372f..cf336849 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -14,17 +14,22 @@ PKGCONFIG += nymea-mqtt nymea-networkmanager # For everything below python 3.8 we need to manually select one packagesExist(python3-embed) { PKGCONFIG += python3-embed + CONFIG += python } else:packagesExist(python-3.5) { # xenial, stretch PKGCONFIG += python-3.5 + CONFIG += python } else:packagesExist(python-3.6) { # bionic PKGCONFIG += python-3.6 + CONFIG += python } else:packagesExist(python-3.7) { # buster, eoan PKGCONFIG += python-3.7 + CONFIG += python } else { - error("Python development package not found.") + message("Python development package not found. Building without python support.") + CONFIG -= python } target.path = $$[QT_INSTALL_LIBS] @@ -38,20 +43,8 @@ RESOURCES += $$top_srcdir/icons.qrc \ HEADERS += nymeacore.h \ integrations/apikeysprovidersloader.h \ integrations/plugininfocache.h \ - integrations/python/pynymealogginghandler.h \ - integrations/python/pynymeamodule.h \ - integrations/python/pyparam.h \ - integrations/python/pystdouthandler.h \ - integrations/python/pything.h \ - integrations/python/pythingactioninfo.h \ - integrations/python/pythingdescriptor.h \ - integrations/python/pythingdiscoveryinfo.h \ - integrations/python/pythingpairinginfo.h \ - integrations/python/pythingsetupinfo.h \ - integrations/python/pyutils.h \ integrations/thingmanagerimplementation.h \ integrations/translator.h \ - integrations/pythonintegrationplugin.h \ experiences/experiencemanager.h \ ruleengine/ruleengine.h \ ruleengine/rule.h \ @@ -134,7 +127,6 @@ SOURCES += nymeacore.cpp \ integrations/plugininfocache.cpp \ integrations/thingmanagerimplementation.cpp \ integrations/translator.cpp \ - integrations/pythonintegrationplugin.cpp \ experiences/experiencemanager.cpp \ ruleengine/ruleengine.cpp \ ruleengine/rule.cpp \ @@ -210,11 +202,32 @@ SOURCES += nymeacore.cpp \ debugreportgenerator.cpp \ platform/platform.cpp \ - versionAtLeast(QT_VERSION, 5.12.0) { +message("Building with JS plugin support") HEADERS += \ integrations/scriptintegrationplugin.h SOURCES += \ integrations/scriptintegrationplugin.cpp } + +CONFIG(python) { +message("Building with Python plugin support") +DEFINES += WITH_PYTHON +HEADERS += \ + integrations/pythonintegrationplugin.h \ + integrations/python/pynymealogginghandler.h \ + integrations/python/pynymeamodule.h \ + integrations/python/pyparam.h \ + integrations/python/pystdouthandler.h \ + integrations/python/pything.h \ + integrations/python/pythingactioninfo.h \ + integrations/python/pythingdescriptor.h \ + integrations/python/pythingdiscoveryinfo.h \ + integrations/python/pythingpairinginfo.h \ + integrations/python/pythingsetupinfo.h \ + integrations/python/pyutils.h + +SOURCES += \ + integrations/pythonintegrationplugin.cpp +} diff --git a/nymea.pro b/nymea.pro index 4a8c3cda..52620458 100644 --- a/nymea.pro +++ b/nymea.pro @@ -84,7 +84,6 @@ message("Qt version:" $$[QT_VERSION]) message("Copyright $${COPYRIGHT_YEAR_FROM} - $${COPYRIGHT_YEAR_TO}") message("Building nymea version $${NYMEA_VERSION_STRING}") message("JSON-RPC API version $${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}") -message("REST API version $${REST_API_VERSION}") message("Source directory: $${top_srcdir}") message("Build directory: $${top_builddir}") message("Translations: $${TRANSLATIONS}")