diff --git a/setup.py b/setup.py index 3582c90a8..75fc67962 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,9 @@ import octoprint_setuptools #----------------------------------------------------------------------------------------------------------------------- +# Supported python versions +PYTHON_REQUIRES = ">=2.7.3,<3" # TODO change to >=2.7.9,<3 in 1.3.11 + # Requirements for our application INSTALL_REQUIRES = [ "flask>=1.0.2,<1.1", @@ -79,9 +82,6 @@ EXTRA_REQUIRES = dict( ] ) -# Additional requirements for setup -SETUP_REQUIRES = [] - # Dependency links for any of the aforementioned dependencies DEPENDENCY_LINKS = [] @@ -154,10 +154,10 @@ def params(): long_description = read_file_contents(os.path.join(here, "README.md")) long_description_content_type = "text/markdown" + python_requires = PYTHON_REQUIRES install_requires = INSTALL_REQUIRES extras_require = EXTRA_REQUIRES dependency_links = DEPENDENCY_LINKS - setup_requires = SETUP_REQUIRES classifiers = [ "Development Status :: 5 - Production/Stable", diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 2166d293b..c6a08208e 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -27,9 +27,16 @@ from flask_babel import gettext from octoprint.server.util.flask import restricted_access, with_revalidation_checking, check_etag from octoprint.server import admin_permission, VERSION, REVISION, BRANCH from octoprint.util import dict_merge, to_unicode +from octoprint.util.version import get_comparable_version +from octoprint.util.pip import LocalPipCaller import octoprint.settings +MINIMUM_PYTHON = "2.7.9" +MINIMUM_SETUPTOOLS = "5.5.1" +MINIMUM_PIP = "9.0.1" + + ##~~ Plugin @@ -43,7 +50,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, COMMIT_TRACKING_TYPES = ("github_commit", "bitbucket_commit") - DATA_FORMAT_VERSION = "v3" + DATA_FORMAT_VERSION = "v4" # noinspection PyMissingConstructor def __init__(self): @@ -62,6 +69,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_dirty = False self._version_cache_timestamp = None + self._environment_supported = False + self._environment_versions = dict() + self._environment_ready = threading.Event() + self._console_logger = None def initialize(self): @@ -92,6 +103,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # the server startup def fetch_data(): self.get_current_versions() + self._check_environment() thread = threading.Thread(target=fetch_data) thread.daemon = True @@ -165,6 +177,24 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, return self._configured_checks + def _check_environment(self): + from platform import python_version + import pkg_resources + + local_pip = LocalPipCaller() + + # check python and setuptools version + versions = dict(python=python_version(), + setuptools=pkg_resources.get_distribution("setuptools").version, + pip=local_pip.version_string) + supported = get_comparable_version(versions["python"]) >= get_comparable_version(MINIMUM_PYTHON) \ + and get_comparable_version(versions["setuptools"]) >= get_comparable_version(MINIMUM_SETUPTOOLS) \ + and get_comparable_version(versions["pip"]) >= get_comparable_version(MINIMUM_PIP) + + self._environment_supported = supported + self._environment_versions = versions + self._environment_ready.set() + def _load_version_cache(self): if not os.path.isfile(self._version_cache_path): return @@ -483,11 +513,17 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, force = flask.request.values.get("force", "false") in octoprint.settings.valid_boolean_trues def view(): + self._environment_ready.wait() + try: information, update_available, update_possible = self.get_current_versions(check_targets=check_targets, force=force) - return flask.jsonify(dict(status="inProgress" if self._update_in_progress else "updatePossible" if update_available and update_possible else "updateAvailable" if update_available else "current", + return flask.jsonify(dict(status="inProgress" if self._update_in_progress else "updatePossible" if update_available and update_possible and self._environment_supported else "updateAvailable" if update_available else "current", information=information, - timestamp=self._version_cache_timestamp)) + timestamp=self._version_cache_timestamp, + environment=dict(supported=self._environment_supported, + versions=[dict(name=gettext("Python"), current=self._environment_versions.get("python", "unknown"), minimum=MINIMUM_PYTHON), + dict(name=gettext("pip"), current=self._environment_versions.get("pip", "unknown"), minimum=MINIMUM_PIP), + dict(name=gettext("setuptools"), current=self._environment_versions.get("setuptools", "unknown"), minimum=MINIMUM_SETUPTOOLS)]))) except exceptions.ConfigurationInvalid as e: return flask.make_response("Update not properly configured, can't proceed: %s" % e.message, 500) @@ -514,6 +550,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, hash.update(str(data.get("online", None))) hash.update(",".join(targets)) + + hash.update(str(self._environment_supported)) hash.update(str(self._version_cache_timestamp)) hash.update(str(self._connectivity_checker.online)) hash.update(str(self._update_in_progress)) @@ -536,6 +574,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, # do not update while a print job is running return flask.make_response("Printer is currently printing or paused", 409) + if not self._environment_supported: + return flask.make_response("Direct updates are not supported in this Python environment", 409) + if not "application/json" in flask.request.headers["Content-Type"]: return flask.make_response("Expected content-type JSON", 400) @@ -646,6 +687,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, continue target_information, target_update_available, target_update_possible, target_online, target_error = future.result() + target_update_possible = target_update_possible and self._environment_supported target_information = dict_merge(dict(local=dict(name="?", value="?"), remote=dict(name="?", value="?", @@ -779,6 +821,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, :param targets: an iterable defining the targets to update, if not supplied defaults to all targets """ + if not self._environment_supported: + self._logger.error("Direct updates are unsupported in this environment") + return [], dict() + targets = kwargs.get("targets", kwargs.get("check_targets", None)) checks = self._get_configured_checks() diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index d0484a5b8..b9aee68cc 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -116,6 +116,9 @@ $(function() { && !self.octoprintReleasedVersion(); }); + self.environmentSupported = ko.observable(true); + self.environmentVersions = ko.observableArray([]); + self.cacheTimestamp = ko.observable(); self.cacheTimestampText = ko.pureComputed(function() { return formatDate(self.cacheTimestamp()); @@ -132,6 +135,10 @@ $(function() { && (!self.config_checkoutFolder() || self.config_checkoutFolder().trim() === ''); }); + self.enableUpdate = ko.pureComputed(function() { + return !self.updateInProgress && self.environmentSupported(); + }); + self.enable_configSave = ko.pureComputed(function() { return self.config_checkType() === "github_release" || (self.config_checkType() === "git_commit" && !self.error_checkoutFolder()); @@ -300,6 +307,9 @@ $(function() { var octoprint = data.information["octoprint"]; self.octoprintReleasedVersion(!octoprint || octoprint.released_version); + self.environmentSupported(data.environment.supported); + self.environmentVersions(data.environment.versions); + if (data.status === "inProgress") { self._markWorking(gettext("Updating..."), gettext("Updating, please wait.")); return; @@ -314,7 +324,7 @@ $(function() { _.each(self.versions.items(), function(update_info) { if (update_info.updateAvailable) { text += "
" + gettext("Those components marked with can be updated directly.") + "
"; + if (!self.environmentSupported()) { + text += "" + gettext("This version of the Python environment is not supported for direct updates.") + "
"; + } else { + text += "" + gettext("Those components marked with can be updated directly.") + "
"; + } if (!self.loginState.isAdmin()) { text += "" + gettext("To have updates applied, get in touch with an administrator of this OctoPrint instance.") + "
"; diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 index df803fd92..13b5c5313 100644 --- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 +++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 @@ -15,6 +15,23 @@ Documentation. {% endtrans %} ++ This version of the Python environment is not supported for direct updates. +
++ To reduce the likelihood of running into update problems in outdated environments, the following minimal + versions are required to use this updater to update OctoPrint or any installed plugins: +
+{% endtrans %} ++ Please take a look at this FAQ entry on how to proceed. +
+{% endtrans %}