🥅 pmgr: Better handling of python version mismatch
Users now get a meaningful error message in both the plugin install log as well as a clickable FAQ link in the plugin management log notification. Works for pip and single file installs. Implements #4166
This commit is contained in:
1 parent
bb6b694fa7
commit
45cf5ddf44
2 files changed
+78
-3
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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 () {
|
||||
? '<i class="fa fa-check"></i>'
|
||||
: '<i class="fa fa-remove"></i>'
|
||||
}) +
|
||||
(step.result === false && step.faq
|
||||
? ' (<a href="" target="_blank" rel="noopener noreferer">' +
|
||||
gettext("Why?") +
|
||||
"</a>)"
|
||||
: "") +
|
||||
"</li>";
|
||||
|
||||
negativeResult = negativeResult || step.result === false;
|
||||
});
|
||||
text += "</ul></p>";
|
||||
|
||||
@@ -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"});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user