| 218 | |
| 219 | class PythonReader(Reader): |
| 220 | def parse(self, file_path: Path) -> str: |
| 221 | logger.info(f"Executing and reading Python file from {file_path}.") |
| 222 | execution_result = "" |
| 223 | error = "" |
| 224 | file_content = "" |
| 225 | try: |
| 226 | completed_process = subprocess.run(["python", file_path], capture_output=True, text=True, check=True) |
| 227 | execution_result = "Output:\n" + completed_process.stdout |
| 228 | except subprocess.CalledProcessError as e: |
| 229 | error = "Error:\n" + e.stderr |
| 230 | except Exception as e: |
| 231 | logger.info(f"Error executing Python file: {e}") |
| 232 | |
| 233 | try: |
| 234 | with open(file_path, "r") as file: |
| 235 | file_content = "\nFile Content:\n" + file.read() |
| 236 | except Exception as e: |
| 237 | logger.info(f"Error reading Python file: {e}") |
| 238 | return file_content, execution_result, error |
| 239 | |
| 240 | |
| 241 | class IMGReader(Reader): |