From 964ccd96550831cf56b4d6420d274ce5bc55118c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Wed, 13 Mar 2019 21:28:48 +0100 Subject: [PATCH] MDL-64994 analytics: Improve the Python package version check Use the new method to check that the installed Python package has high enough yet still API-compatible version. --- lib/mlbackend/python/classes/processor.php | 17 ++++++++++++++--- .../python/lang/en/mlbackend_python.php | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/mlbackend/python/classes/processor.php b/lib/mlbackend/python/classes/processor.php index cda1173dcd8..fa6bfe51cd7 100644 --- a/lib/mlbackend/python/classes/processor.php +++ b/lib/mlbackend/python/classes/processor.php @@ -78,7 +78,9 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso // Execute it sending the standard error to $output. $result = exec($cmd . ' 2>&1', $output, $exitcode); - if ($result === self::REQUIRED_PIP_PACKAGE_VERSION) { + $vercheck = self::check_pip_package_version($result); + + if ($vercheck === 0) { return true; } @@ -87,8 +89,17 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso } if ($result) { - $a = (object)array('installed' => $result, 'required' => self::REQUIRED_PIP_PACKAGE_VERSION); - return get_string('packageinstalledshouldbe', 'mlbackend_python', $a); + $a = [ + 'installed' => $result, + 'required' => self::REQUIRED_PIP_PACKAGE_VERSION, + ]; + + if ($vercheck < 0) { + return get_string('packageinstalledshouldbe', 'mlbackend_python', $a); + + } else if ($vercheck > 0) { + return get_string('packageinstalledtoohigh', 'mlbackend_python', $a); + } } return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd); diff --git a/lib/mlbackend/python/lang/en/mlbackend_python.php b/lib/mlbackend/python/lang/en/mlbackend_python.php index 1a1bb4f4bc7..f5bcb727fca 100644 --- a/lib/mlbackend/python/lang/en/mlbackend_python.php +++ b/lib/mlbackend/python/lang/en/mlbackend_python.php @@ -23,6 +23,7 @@ */ $string['packageinstalledshouldbe'] = '"moodlemlbackend" python package should be updated. The required version is "{$a->required}" and the installed version is "{$a->installed}"'; +$string['packageinstalledtoohigh'] = '"moodlemlbackend" python package is not compatible with this Moodle version. The required version is "{$a->required}" or higher as long as it is API-compatible. The installed version "{$a->installed}" is too high.'; $string['pluginname'] = 'Python machine learning backend'; $string['privacy:metadata'] = 'The Python machine learning backend plugin does not store any personal data.'; $string['pythonpackagenotinstalled'] = '"moodlemlbackend" python package is not installed or there is a problem with it. Please execute "{$a}" from command line interface for more info'; -- 2.43.0