Proxy to execute_interpreter Iterates over defined interpreter until one that runs the input/script is found Return a 3-tuple with the following elements: - JSON decoded output of the executed script - name of the interpreter as defined in aura config - path/command to the
(*, metadata=None, **kwargs)
| 25 | |
| 26 | |
| 27 | def run_with_interpreters(*, metadata=None, **kwargs): |
| 28 | """ |
| 29 | Proxy to execute_interpreter |
| 30 | Iterates over defined interpreter until one that runs the input/script is found |
| 31 | |
| 32 | Return a 3-tuple with the following elements: |
| 33 | - JSON decoded output of the executed script |
| 34 | - name of the interpreter as defined in aura config |
| 35 | - path/command to the interpreter as defined in aura config |
| 36 | |
| 37 | In case an interpreter that is able to execute the input script was not found, all tuple elements are set to None |
| 38 | """ |
| 39 | if metadata and metadata.get("interpreter_path"): |
| 40 | return execute_interpreter( |
| 41 | interpreter=metadata["interpreter_path"], |
| 42 | **kwargs |
| 43 | ) |
| 44 | |
| 45 | interpreters = list(config.CFG["interpreters"].items()) |
| 46 | executor_exception = None |
| 47 | |
| 48 | for name, interpreter in interpreters: |
| 49 | # If interpreter is not directly an executable, find out it's location via `witch` lookup |
| 50 | if interpreter != "native" and not os.path.isfile(interpreter): |
| 51 | interpreter = which(interpreter) |
| 52 | |
| 53 | try: |
| 54 | output = execute_interpreter(interpreter=interpreter, **kwargs) |
| 55 | if output is not None: |
| 56 | if metadata is not None: |
| 57 | metadata["interpreter_name"] = name |
| 58 | metadata["interpreter_path"] = interpreter |
| 59 | |
| 60 | return output |
| 61 | except PythonExecutorError as exc: |
| 62 | executor_exception = exc |
| 63 | continue |
| 64 | |
| 65 | if executor_exception is not None: |
| 66 | raise executor_exception |
| 67 | |
| 68 | |
| 69 | def execute_interpreter(*, command: List[str], interpreter: str, stdin=None, native_callback: Optional[Callable]=None): |
nothing calls this directly
no test coverage detected