From 0f818a313d51f7b98c86b7f9070a18d78cabae01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 22 Jun 2015 13:03:23 +0200 Subject: [PATCH] Software Update: Default to pkg_resources for version comparison That's also able to cope with 0.3a and similar "non-semantic" version schemes. Semantic version comparison can still be forced by setting the compare_type in the check to "semantic". Strict equality check can be set similarly by using the value "unequal". --- .../version_checks/github_release.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/version_checks/github_release.py b/src/octoprint/plugins/softwareupdate/version_checks/github_release.py index 94823eef..0d2abf69 100644 --- a/src/octoprint/plugins/softwareupdate/version_checks/github_release.py +++ b/src/octoprint/plugins/softwareupdate/version_checks/github_release.py @@ -48,11 +48,19 @@ def _is_current(release_information, compare_type, custom=None): if release_information["remote"]["value"] is None: return True - if not compare_type in ("semantic", "unequal", "custom") or compare_type == "custom" and custom is None: - compare_type = "semantic" + if not compare_type in ("python", "semantic", "unequal", "custom") or compare_type == "custom" and custom is None: + compare_type = "python" try: - if compare_type == "semantic": + if compare_type == "python": + import pkg_resources + + local_version = pkg_resources.parse_version(release_information["local"]["value"]) + remote_version = pkg_resources.parse_version(release_information["remote"]["value"]) + + return local_version >= remote_version + + elif compare_type == "semantic": import semantic_version local_version = semantic_version.Version(release_information["local"]["value"]) @@ -79,7 +87,7 @@ def get_latest(target, check, custom_compare=None): current = check["current"] remote_name, remote_tag = _get_latest_release(check["user"], check["repo"], include_prerelease=check["prerelease"] == True if "prerelease" in check else False) - compare_type = check["release_compare"] if "release_compare" in check else "semantic" + compare_type = check["release_compare"] if "release_compare" in check else "python" information =dict( local=dict(name=current, value=current),