Commit 391663ce authored by Mark Nelson's avatar Mark Nelson
Browse files

MDL-59995 core_admin: added setting to define Python bin path

parent 32f9550e
......@@ -12,6 +12,8 @@ $temp->add(new admin_setting_configexecutable('pathtodu', new lang_string('patht
$temp->add(new admin_setting_configexecutable('aspellpath', new lang_string('aspellpath', 'admin'), new lang_string('edhelpaspellpath'), ''));
$temp->add(new admin_setting_configexecutable('pathtodot', new lang_string('pathtodot', 'admin'), new lang_string('pathtodot_help', 'admin'), ''));
$temp->add(new admin_setting_configexecutable('pathtogs', new lang_string('pathtogs', 'admin'), new lang_string('pathtogs_help', 'admin'), '/usr/bin/gs'));
$temp->add(new admin_setting_configexecutable('pathtopython', new lang_string('pathtopython', 'admin'),
new lang_string('pathtopythondesc', 'admin'), ''));
$ADMIN->add('server', $temp);
......
......@@ -835,6 +835,8 @@ $string['pathtopgdumpinvalid'] = 'Invalid path to pg_dump - either wrong path or
$string['pathtopsql'] = 'Path to psql';
$string['pathtopsqldesc'] = 'This is only necessary to enter if you have more than one psql on your system (for example if you have more than one version of postgresql installed)';
$string['pathtopsqlinvalid'] = 'Invalid path to psql - either wrong path or not executable';
$string['pathtopython'] = 'Path to Python';
$string['pathtopythondesc'] = 'Path to your executable Python binary.';
$string['pcreunicodewarning'] = 'It is strongly recommended to use PCRE PHP extension that is compatible with Unicode characters.';
$string['perfdebug'] = 'Performance info';
$string['performance'] = 'Performance';
......
......@@ -40,15 +40,38 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
*/
const REQUIRED_PIP_PACKAGE_VERSION = '0.0.2';
/**
* The path to the Python bin.
*
* @var string
*/
protected $pathtopython;
/**
* The constructor.
*/
public function __construct() {
global $CFG;
// Set the python location if there is a value.
if (!empty($CFG->pathtopython)) {
$this->pathtopython = $CFG->pathtopython;
}
}
/**
* Is the plugin ready to be used?.
*
* @return bool
* @return bool|string Returns true on success, a string detailing the error otherwise
*/
public function is_ready() {
if (empty($this->pathtopython)) {
$settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths'));
return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out());
}
// Check the installed pip package version.
$cmd = 'python -m moodlemlbackend.version';
$cmd = "{$this->pathtopython} -m moodlemlbackend.version";
$output = null;
$exitcode = null;
......@@ -84,7 +107,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.training ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.training " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath);
......@@ -125,7 +148,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.prediction ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.prediction " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath);
......@@ -168,7 +191,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regresso
// Obtain the physical route to the file.
$datasetpath = $this->get_file_path($dataset);
$cmd = 'python -m moodlemlbackend.evaluation ' .
$cmd = "{$this->pathtopython} -m moodlemlbackend.evaluation " .
escapeshellarg($uniqueid) . ' ' .
escapeshellarg($outputdir) . ' ' .
escapeshellarg($datasetpath) . ' ' .
......
......@@ -25,3 +25,4 @@
$string['packageinstalledshouldbe'] = '"moodlemlbackend" python package should be updated. The required version is "{$a->required}" and the installed version is "{$a->installed}"';
$string['pluginname'] = 'Python machine learning backend';
$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';
$string['pythonpathnotdefined'] = 'The path to your executable Python binary has not been defined. Please visit "{$a}" to set it.';
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment