|
23 | 23 | from importlib import import_module |
24 | 24 | from importlib.machinery import PathFinder |
25 | 25 | from os.path import join as pjoin |
| 26 | +import warnings |
26 | 27 |
|
27 | 28 | # This file is run as a script, and `import wrappers` is not zip-safe, so we |
28 | 29 | # include write_json() and read_json() from wrappers.py. |
@@ -368,20 +369,30 @@ def main(): |
368 | 369 |
|
369 | 370 | hook_input = read_json(pjoin(control_dir, "input.json")) |
370 | 371 |
|
371 | | - json_out = {"unsupported": False, "return_val": None} |
372 | | - try: |
373 | | - json_out["return_val"] = hook(**hook_input["kwargs"]) |
374 | | - except BackendUnavailable as e: |
375 | | - json_out["no_backend"] = True |
376 | | - json_out["traceback"] = e.traceback |
377 | | - json_out["backend_error"] = e.message |
378 | | - except GotUnsupportedOperation as e: |
379 | | - json_out["unsupported"] = True |
380 | | - json_out["traceback"] = e.traceback |
381 | | - except HookMissing as e: |
382 | | - json_out["hook_missing"] = True |
383 | | - json_out["missing_hook_name"] = e.hook_name or hook_name |
384 | | - |
| 372 | + with warnings.catch_warnings(record=True) as captured_warnings: |
| 373 | + json_out = {"unsupported": False, "return_val": None} |
| 374 | + try: |
| 375 | + json_out["return_val"] = hook(**hook_input["kwargs"]) |
| 376 | + except BackendUnavailable as e: |
| 377 | + json_out["no_backend"] = True |
| 378 | + json_out["traceback"] = e.traceback |
| 379 | + json_out["backend_error"] = e.message |
| 380 | + except GotUnsupportedOperation as e: |
| 381 | + json_out["unsupported"] = True |
| 382 | + json_out["traceback"] = e.traceback |
| 383 | + except HookMissing as e: |
| 384 | + json_out["hook_missing"] = True |
| 385 | + json_out["missing_hook_name"] = e.hook_name or hook_name |
| 386 | + |
| 387 | + json_out["warnings"] = [ |
| 388 | + { |
| 389 | + "message": str(w.message), |
| 390 | + "filename": w.filename, |
| 391 | + "lineno": w.lineno, |
| 392 | + } |
| 393 | + for w in captured_warnings |
| 394 | + if isinstance(w.category, type) and issubclass(w.category, UserWarning) |
| 395 | + ] |
385 | 396 | write_json(json_out, pjoin(control_dir, "output.json"), indent=2) |
386 | 397 |
|
387 | 398 |
|
|
0 commit comments