diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 9a6ad46a4..ff5076610 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -109,6 +109,7 @@ def map_repository_entry(entry): already_installed_string = "Requirement already satisfied (use --upgrade to upgrade)" success_string = "Successfully installed" failure_string = "Could not install" +python_mismatch_string = "requires a different Python:" class PluginManagerPlugin( @@ -958,6 +959,22 @@ class PluginManagerPlugin( self._send_result_notification("install", result) return result + if any(map(lambda x: python_mismatch_string in x, stderr)): + self._logger.error( + "Installing the plugin from {} failed, pip reported a Python version mismatch".format( + source + ) + ) + result = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Pip reported a Python version mismatch", + "faq": "https://faq.octoprint.org/plugin-python-mismatch", + } + self._send_result_notification("install", result) + return result + try: result_line = list( filter( @@ -1112,6 +1129,42 @@ class PluginManagerPlugin( destination = os.path.join(self._settings.global_get_basefolder("plugins"), name) plugin_id, _ = os.path.splitext(name) + # check python compatibility + PYTHON_MISMATCH = { + "result": False, + "source": source, + "source_type": source_type, + "reason": "Plugin could not be installed", + "faq": "https://faq.octoprint.org/plugin-python-mismatch", + } + + try: + metadata = octoprint.plugin.core.parse_plugin_metadata(path) + except SyntaxError: + self._logger.exception( + "Installing plugin from {} failed, there's a Python version mismatch".format( + source + ) + ) + result = PYTHON_MISMATCH + self._send_result_notification("install", result) + return result + + pythoncompat = metadata.get( + octoprint.plugin.core.ControlProperties.attr_pythoncompat, + octoprint.plugin.core.ControlProperties.default_pythoncompat, + ) + if not is_python_compatible(pythoncompat): + self._logger.exception( + "Installing plugin from {} failed, there's a Python version mismatch".format( + source + ) + ) + result = PYTHON_MISMATCH + self._send_result_notification("install", result) + return result + + # copy plugin try: self._log_call("cp {} {}".format(path, destination)) shutil.copy(path, destination) diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index 6248965f2..df00acc10 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -1217,7 +1217,7 @@ $(function () { if (response.result) { self._markDone(); } else { - self._markDone(response.reason); + self._markDone(response.reason, response.faq); } self._displayPluginManagementNotification(response, action, plugin); @@ -1233,7 +1233,8 @@ $(function () { self.logContents.steps.push({ action: action, plugin: plugin, - result: response.result + result: response.result, + faq: response.faq }); var title = gettext("Plugin management log"); @@ -1252,6 +1253,7 @@ $(function () { steps = steps.slice(steps.length - 5); } + var negativeResult = false; _.each(steps, function (step) { var line = undefined; @@ -1293,7 +1295,14 @@ $(function () { ? '' : '' }) + + (step.result === false && step.faq + ? ' (' + + gettext("Why?") + + ")" + : "") + ""; + + negativeResult = negativeResult || step.result === false; }); text += "

"; @@ -1385,6 +1394,8 @@ $(function () { type = "warning"; } + if (negativeResult) type = "error"; + var options = { title: title, text: text, @@ -1432,11 +1443,22 @@ $(function () { self.workingDialog.modal({keyboard: false, backdrop: "static", show: true}); }; - self._markDone = function (error) { + self._markDone = function (error, faq) { self.working(false); if (error) { self.loglines.push({line: gettext("Error!"), stream: "error"}); self.loglines.push({line: error, stream: "error"}); + if (faq) { + self.loglines.push({ + line: _.sprintf( + gettext( + "You can find more info on this issue in the FAQ at %(url)s" + ), + {url: faq} + ), + stream: "error" + }); + } } else { self.loglines.push({line: gettext("Done!"), stream: "message"}); }