-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPython3RunBox.php
More file actions
128 lines (114 loc) · 4.04 KB
/
Python3RunBox.php
File metadata and controls
128 lines (114 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace App\Helpers\ExerciseConfig\Pipeline\Box;
use App\Exceptions\ExerciseConfigException;
use App\Helpers\ExerciseConfig\Compilation\CompilationParams;
use App\Helpers\ExerciseConfig\Pipeline\Ports\Port;
use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta;
use App\Helpers\ExerciseConfig\VariableTypes;
/**
* Box which represents execution python script.
* @DEPRECATED - use ScriptExecutionBox instead
*/
class Python3RunBox extends ExecutionBox
{
/** Type key */
public static $BOX_TYPE = "python3";
public static $PYTHON3_BINARY = "/usr/bin/env";
public static $PYTHON3_VERSION = "python3";
public static $DEFAULT_NAME = "Python3 Execution";
private static $initialized = false;
private static $defaultInputPorts;
private static $defaultOutputPorts;
/**
* Static initializer.
* @throws ExerciseConfigException
*/
public static function init()
{
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port((new PortMeta())->setName(self::$RUNNER_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$SOURCE_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)),
new Port((new PortMeta())->setName(self::$STDIN_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$INPUT_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$ENTRY_POINT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$EXTRA_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
);
self::$defaultOutputPorts = array(
new Port((new PortMeta())->setName(self::$STDOUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$OUTPUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
}
}
/**
* ElfExecutionBox constructor.
* @param BoxMeta $meta
*/
public function __construct(BoxMeta $meta)
{
parent::__construct($meta);
}
/**
* Get type of this box.
* @return string
*/
public function getType(): string
{
return self::$BOX_TYPE;
}
/**
* Get default input ports for this box.
* @return array
* @throws ExerciseConfigException
*/
public function getDefaultInputPorts(): array
{
self::init();
return self::$defaultInputPorts;
}
/**
* Get default output ports for this box.
* @return array
* @throws ExerciseConfigException
*/
public function getDefaultOutputPorts(): array
{
self::init();
return self::$defaultOutputPorts;
}
/**
* Get default name of this box.
* @return string
*/
public function getDefaultName(): string
{
return self::$DEFAULT_NAME;
}
/**
* Compile box into set of low-level tasks.
* @param CompilationParams $params
* @return array
* @throws ExerciseConfigException
*/
public function compile(CompilationParams $params): array
{
$task = $this->compileBaseTask($params);
$task->setCommandBinary(self::$PYTHON3_BINARY);
$entry = $this->getInputPortValue(self::$ENTRY_POINT_KEY)->getValue();
$runner = $this->getInputPortValue(self::$RUNNER_FILE_PORT_KEY)->getValue();
$args = [self::$PYTHON3_VERSION, $runner, $entry];
if ($this->hasInputPortValue(self::$ARGS_PORT_KEY)) {
$args = array_merge($args, $this->getInputPortValue(self::$ARGS_PORT_KEY)->getValue());
}
$task->setCommandArguments($args);
return [$task];
}
}