From e7e2cca62abfcffdb7d322731a5c5f71f630a4ae Mon Sep 17 00:00:00 2001 From: Netkas Date: Wed, 7 Dec 2022 22:59:15 -0500 Subject: [PATCH] Added Python3Runner https://git.n64.cc/nosial/ncc/-/issues/32 --- .../Classes/PythonExtension/Python3Runner.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ncc/Classes/PythonExtension/Python3Runner.php diff --git a/src/ncc/Classes/PythonExtension/Python3Runner.php b/src/ncc/Classes/PythonExtension/Python3Runner.php new file mode 100644 index 0000000..94b5447 --- /dev/null +++ b/src/ncc/Classes/PythonExtension/Python3Runner.php @@ -0,0 +1,53 @@ +Execute->Target = null; + $execution_unit->ExecutionPolicy = $policy; + $execution_unit->Data = Base64::encode(IO::fread($path)); + + return $execution_unit; + } + + /** + * @inheritDoc + */ + public static function getFileExtension(): string + { + return '.py'; + } + + /** + * @inheritDoc + */ + public static function prepareProcess(ExecutionPointer $pointer): Process + { + $python_bin = PathFinder::findRunner(Runners::python3); + + if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0) + return new Process(array_merge([$python_bin, $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options)); + return new Process([$python_bin, $pointer->FilePointer]); + } + } \ No newline at end of file