♻ Add central methods for getting python version

This commit is contained in:
Gina Häußge committed 2019-02-20 15:32:07 +01:00
1 parent 4a64bc6023
commit 45aa26f13e
3 files changed
+31 -5

No files matched your search

+2 -2
View File
@@ -7,7 +7,6 @@ __copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms
import copy
import logging
import os
import platform
import sys
import threading
import yaml
@@ -16,6 +15,7 @@ import psutil
from octoprint.plugin import EnvironmentDetectionPlugin
from octoprint.util.platform import get_os
from octoprint.util.version import get_python_version_string
class EnvironmentDetector(object):
@@ -70,7 +70,7 @@ class EnvironmentDetector(object):
# determine python version
try:
result["version"] = platform.python_version()
result["version"] = get_python_version_string()
except:
self._logger.exception("Error detecting python version")
@@ -27,7 +27,7 @@ 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.version import get_comparable_version, get_python_version_string
from octoprint.util.pip import LocalPipCaller
import octoprint.settings
@@ -174,13 +174,12 @@ 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(),
versions = dict(python=get_python_version_string(),
setuptools=pkg_resources.get_distribution("setuptools").version,
pip=local_pip.version_string)
supported = get_comparable_version(versions["python"]) >= get_comparable_version(MINIMUM_PYTHON) \
+27
View File
@@ -117,6 +117,33 @@ def is_octoprint_compatible(*compatibility_entries, **kwargs):
return True
def get_python_version_string():
from platform import python_version
version_string = python_version()
# Debian has the python version set to 2.7.15+ which is not PEP440 compliant (bug 914072)
if version_string.endswith("+"):
version_string = python_version[:-1]
return version_string
def get_python_version():
return get_comparable_version(get_python_version_string())
def is_python_compatible(compat, **kwargs):
if not compat:
return True
python_version = kwargs.get("python_version")
if python_version is None:
python_version = get_python_version_string()
s = pkg_resources.Requirement.parse("Python" + compat)
return python_version in s
def get_comparable_version(version_string, base=False):
if "-" in version_string:
version_string = version_string[:version_string.find("-")]