✨ SWU: Optional pip auto update

Since we can't guarantee for compatibility with future versions of pip
we'll stick to the updater for that being opt-in.
This commit is contained in:
Gina Häußge committed 2019-11-08 14:48:29 +01:00
1 parent 09bb74b6c6
commit ee9d5048e2
5 files changed
+62 -4

No files matched your search

@@ -352,6 +352,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
data["octoprint_type"] = None
data["octoprint_branch_mappings"] = []
data["pip_enable_check"] = "pip" in checks
return data
def on_settings_save(self, data):
@@ -377,6 +379,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
)
updated_octoprint_check_config = False
update_pip_check_config = False
if "octoprint_checkout_folder" in data:
self._settings.set(["checks", "octoprint", "checkout_folder"], data["octoprint_checkout_folder"], defaults=defaults, force=True)
@@ -421,6 +424,18 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._settings.set(["checks", "octoprint", "prerelease_channel"], None, defaults=defaults, force=True)
updated_octoprint_check_config = True
if "pip_enable_check" in data:
checks = self._settings.get(["checks"], merged=True)
if data["pip_enable_check"] in octoprint.settings.valid_boolean_trues:
checks["pip"] = dict(type="pypi_release",
package="pip",
pip="pip=={target_version}")
elif "pip" in checks:
del checks["pip"]
self._settings.set(["checks"], checks, force=True)
self._settings.save()
update_pip_check_config = True
if updated_octoprint_check_config:
self._refresh_configured_checks = True
try:
@@ -429,6 +444,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
pass
self._version_cache_dirty = True
if update_pip_check_config:
self._refresh_configured_checks = True
try:
del self._version_cache["pip"]
except KeyError:
pass
self._version_cache_dirty = True
def get_settings_version(self):
return 6
@@ -903,6 +926,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
to_be_updated.remove("octoprint")
tmp = ["octoprint"] + to_be_updated
to_be_updated = tmp
if "pip" in to_be_updated:
to_be_updated.remove("pip")
tmp = ["pip"] + to_be_updated
to_be_updated = tmp
updater_thread = threading.Thread(target=self._update_worker, args=(populated_checks, to_be_updated, force))
updater_thread.daemon = False
@@ -941,7 +968,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
if "restart" in check:
target_restart_type = check["restart"]
elif "pip" in check:
elif "pip" in check and target != "pip":
target_restart_type = "octoprint"
else:
target_restart_type = None
@@ -1095,13 +1122,14 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
raise exceptions.RestartFailed()
def _populated_check(self, target, check):
from flask_babel import gettext
if not "type" in check:
raise exceptions.UnknownCheckType()
result = dict(check)
if target == "octoprint":
from flask_babel import gettext
from octoprint.util.version import is_released_octoprint_version, is_stable_octoprint_version
@@ -1160,6 +1188,23 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
# we force python unequality check for pip installs, to be able to downgrade
result["release_compare"] = "python_unequal"
elif target == "pip":
import pkg_resources
displayName = check.get("displayName")
if displayName is None:
# displayName missing or set to None
displayName = gettext("pip")
result["displayName"] = to_unicode(displayName, errors="replace")
displayVersion = check.get("displayVersion")
if displayVersion is None:
# displayVersion missing or set to None
distribution = pkg_resources.get_distribution("pip")
if distribution:
displayVersion = distribution.version
result["displayVersion"] = to_unicode(displayVersion, errors="replace")
else:
result["displayName"] = to_unicode(check.get("displayName"), errors="replace")
if result["displayName"] is None:
@@ -53,6 +53,7 @@ $(function() {
self.config_pipTarget = ko.observable();
self.config_checkType = ko.observable();
self.config_releaseChannel = ko.observable();
self.config_pipEnableCheck = ko.observable();
self.error_checkoutFolder = ko.pureComputed(function() {
return self.config_checkType() === "git_commit"
@@ -164,7 +165,8 @@ $(function() {
octoprint_release_channel: self.config_releaseChannel(),
octoprint_checkout_folder: self.config_checkoutFolder(),
octoprint_tracked_branch: self.config_trackedBranch(),
octoprint_pip_target: self.config_pipTarget()
octoprint_pip_target: self.config_pipTarget(),
pip_enable_check: self.config_pipEnableCheck()
}
}
};
@@ -201,6 +203,8 @@ $(function() {
self.config_checkoutFolder(self.settings.settings.plugins.softwareupdate.octoprint_checkout_folder());
self.config_trackedBranch(self.settings.settings.plugins.softwareupdate.octoprint_tracked_branch());
self.config_pipTarget(self.settings.settings.plugins.softwareupdate.octoprint_pip_target());
self.config_pipEnableCheck(self.settings.settings.plugins.softwareupdate.pip_enable_check());
};
self._copyConfigBack = function() {
@@ -0,0 +1,8 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: config_pipEnableCheck"> {{ _('Enable <code>pip</code> update checks') }}
<span class="help-block">{{ _('If you check this, OctoPrint will also notify you of updates of the <code>pip</code> tool used by OctoPrint to install plugins and updates and allow you to update it through OctoPrint. <code>pip</code> is outside of the control of the OctoPrint maintainer, so enable at your own risk.') }}</span>
</label>
</div>
</div>
@@ -1,5 +1,5 @@
<div class="control-group" data-bind="visible: config_checkType() === 'github_release' || config_checkType() === 'github_commit'">
<label class="control-label">{{ _('<code>pip</code> target') }}</label>
<label class="control-label">{{ _('OctoPrint <code>pip</code> target') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: config_pipTarget">
<span class="help-block">{{ _('You should normally not have to change this.') }}</span>
@@ -105,6 +105,7 @@
{% include "snippets/plugins/softwareupdate/checkoutFolder.jinja2" %}
{% include "snippets/plugins/softwareupdate/releaseChannel.jinja2" %}
{% include "snippets/plugins/softwareupdate/pipTarget.jinja2" %}
{% include "snippets/plugins/softwareupdate/pipEnableCheck.jinja2" %}
<div class="control-group">
<label class="control-label">{{ _('Version cache TTL') }}</label>
<div class="controls">