19 lines
843 B
PHP
19 lines
843 B
PHP
<?php
|
|
|
|
require_once "Utils.php";
|
|
|
|
class PythonUtils
|
|
{
|
|
private const VENV = Utils::WORKSPACE_DIR . DIRECTORY_SEPARATOR . "venv";
|
|
|
|
public static function execPy(string $script, array $args): void
|
|
{
|
|
$venv = getcwd() . DIRECTORY_SEPARATOR . self::VENV; // compose full venv path
|
|
$ws = getcwd() . DIRECTORY_SEPARATOR . Utils::WORKSPACE_DIR; // compose full workspace path
|
|
|
|
//$source_cmd = "source " . $venv . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "activate";
|
|
$flattened_args = join(" ", array_map(fn($arg) => "'$arg'", $args)); // prepare arguments for use on command line
|
|
$python_cmd = "bash $ws" . DIRECTORY_SEPARATOR . "py_exec.sh \"$ws" . DIRECTORY_SEPARATOR . $script . "\" " . $flattened_args . " 2>&1";
|
|
$ret = shell_exec($python_cmd); // execute python script
|
|
}
|
|
} |