1importos 2importplatform 3importsubprocess 4importsys 5frompathlibimportPath 6 7from.importpdb 8 910defset_breakpoint_hook():11"""12 If a `plain dev` process is running, set a13 breakpoint hook to trigger a remote debugger.14 """1516ifnotos.environ.get("PLAIN_DEV"):17# Only want to set the breakpoint hook if18# we're in a process managed by `plain dev`19return2021def_breakpoint():22system=platform.system()2324ifsystem=="Darwin":25pwd=Path.cwd()26script=f"""27 tell application "Terminal"28 activate29 do script "cd {pwd} && plain dev debug"30 end tell31 """32subprocess.run(["osascript","-e",script])33else:34raiseOSError("Unsupported operating system")3536pdb.set_trace(37# Make sure the debugger starts outside of this38frame=sys._getframe().f_back,39)4041sys.breakpointhook=_breakpoint