|  | 
| 1 | 1 | # TODO: rename this | 
| 2 | 2 | 
 | 
|  | 3 | +import os | 
| 3 | 4 | import pathlib | 
|  | 5 | +import sys | 
|  | 6 | +import traceback | 
| 4 | 7 | import typing as T | 
| 5 | 8 | 
 | 
| 6 | 9 | from hatchling.plugin import hookimpl | 
| @@ -52,9 +55,45 @@ def initialize(self, version: str, build_data: T.Dict[str, T.Any]) -> None: | 
| 52 | 55 |         trampoline_build_path = stage0_build_path / "trampolines" | 
| 53 | 56 |         trampoline_meson_build = trampoline_build_path / "meson.build" | 
| 54 | 57 | 
 | 
| 55 |  | -        eps = gen_meson_to_file( | 
| 56 |  | -            project_root, stage0_meson_build, stage1_meson_build, trampoline_meson_build | 
| 57 |  | -        ) | 
|  | 58 | +        try: | 
|  | 59 | +            eps = gen_meson_to_file( | 
|  | 60 | +                project_root, | 
|  | 61 | +                stage0_meson_build, | 
|  | 62 | +                stage1_meson_build, | 
|  | 63 | +                trampoline_meson_build, | 
|  | 64 | +            ) | 
|  | 65 | +        except Exception as e: | 
|  | 66 | +            # Reading the stack trace is annoying, most of the time the exception content | 
|  | 67 | +            # is enough to figure out what you did wrong. | 
|  | 68 | +            if os.environ.get("SEMIWRAP_ERROR_VERBOSE") == "1": | 
|  | 69 | +                raise | 
|  | 70 | + | 
|  | 71 | +            msg = [ | 
|  | 72 | +                "ERROR: exception occurred when processing `pyproject.toml`", | 
|  | 73 | +                "", | 
|  | 74 | +            ] | 
|  | 75 | + | 
|  | 76 | +            msg += traceback.format_exception_only(e, show_group=True) | 
|  | 77 | +            cause = e.__context__ | 
|  | 78 | +            while cause is not None: | 
|  | 79 | +                if "prepare_metadata_for_build_editable" in str(cause): | 
|  | 80 | +                    break | 
|  | 81 | + | 
|  | 82 | +                el = traceback.format_exception_only(cause, show_group=True) | 
|  | 83 | +                el[0] = f"- caused by {el[0]}" | 
|  | 84 | +                msg += el | 
|  | 85 | + | 
|  | 86 | +                if cause.__suppress_context__: | 
|  | 87 | +                    break | 
|  | 88 | + | 
|  | 89 | +                cause = cause.__context__ | 
|  | 90 | + | 
|  | 91 | +            msg.append( | 
|  | 92 | +                "Set environment variable SEMIWRAP_ERROR_VERBOSE=1 for stacktrace" | 
|  | 93 | +            ) | 
|  | 94 | + | 
|  | 95 | +            print("\n".join(msg), file=sys.stderr) | 
|  | 96 | +            sys.exit(1) | 
| 58 | 97 | 
 | 
| 59 | 98 |         if eps: | 
| 60 | 99 |             # .. not documented but it works? | 
|  | 
0 commit comments