(
self,
config: PythonRunnerConfig,
script_path: Path,
workspace: Path,
node: Node,
)
| 114 | return path |
| 115 | |
| 116 | def _run_process( |
| 117 | self, |
| 118 | config: PythonRunnerConfig, |
| 119 | script_path: Path, |
| 120 | workspace: Path, |
| 121 | node: Node, |
| 122 | ) -> _ExecutionResult: |
| 123 | cmd = [config.interpreter] |
| 124 | if config.args: |
| 125 | cmd.extend(config.args) |
| 126 | cmd.append(str(script_path)) |
| 127 | env = os.environ.copy() |
| 128 | env.update(config.env or {}) |
| 129 | env.update( |
| 130 | { |
| 131 | "MAC_CODE_WORKSPACE": str(workspace), |
| 132 | "MAC_CODE_SCRIPT": str(script_path), |
| 133 | "MAC_NODE_ID": node.id, |
| 134 | } |
| 135 | ) |
| 136 | try: |
| 137 | completed = subprocess.run( |
| 138 | cmd, |
| 139 | cwd=str(workspace), |
| 140 | capture_output=True, |
| 141 | check=False, |
| 142 | timeout=config.timeout_seconds, |
| 143 | ) |
| 144 | except subprocess.TimeoutExpired as exc: |
| 145 | return _ExecutionResult( |
| 146 | success=False, |
| 147 | stdout="", |
| 148 | stderr=exc.stdout.decode(config.encoding, errors="replace") if exc.stdout else "", |
| 149 | exit_code=None, |
| 150 | error=f"Script did not finish within {config.timeout_seconds}s", |
| 151 | ) |
| 152 | except FileNotFoundError: |
| 153 | return _ExecutionResult( |
| 154 | success=False, |
| 155 | stdout="", |
| 156 | stderr="", |
| 157 | exit_code=None, |
| 158 | error=f"Interpreter {config.interpreter} not found", |
| 159 | ) |
| 160 | stdout = completed.stdout.decode(config.encoding, errors="replace") |
| 161 | stderr = completed.stderr.decode(config.encoding, errors="replace") |
| 162 | return _ExecutionResult( |
| 163 | success=completed.returncode == 0, |
| 164 | stdout=stdout, |
| 165 | stderr=stderr, |
| 166 | exit_code=completed.returncode, |
| 167 | ) |
| 168 | |
| 169 | def _build_failure_message( |
| 170 | self, |
no test coverage detected