comparison mercurial/debugcommands.py @ 49972:88b81dc2d82b

debugshell: allow TortoiseHg builds to exit with the usual `quit()` command I've long been annoyed that `quit()` only randomly worked to exit the interpreter. When that happens, Ctrl+C doesn't work either (it simply prints "KeyboardInterrupt"), so then you have to `import sys` and `sys.exit()`. But it turns out that the behavior isn't random and it depended on which `hg.exe` was picked up on PATH first, because py2exe disables site initialization. I wasn't able to persuade the maintainer to allow an opt-in to initialization[1], but this works around it so that the behavior is now consistent however `hg.exe` is built. TortoiseHg 6.3.3 will be the first build that includes the site package, so handle the ImportError. [1] https://github.com/py2exe/py2exe/issues/154
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 06 Jan 2023 11:38:13 -0500
parents c84844cd523a
children 8f76a41ee465
comparison
equal deleted inserted replaced
49971:07792fd1837f 49972:88b81dc2d82b
3798 imported_objects = { 3798 imported_objects = {
3799 'ui': ui, 3799 'ui': ui,
3800 'repo': repo, 3800 'repo': repo,
3801 } 3801 }
3802 3802
3803 # py2exe disables initialization of the site module, which is responsible
3804 # for arranging for ``quit()`` to exit the interpreter. Manually initialize
3805 # the stuff that site normally does here, so that the interpreter can be
3806 # quit in a consistent manner, whether run with pyoxidizer, exewrapper.c,
3807 # py.exe, or py2exe.
3808 if getattr(sys, "frozen", None) == 'console_exe':
3809 try:
3810 import site
3811
3812 site.setcopyright()
3813 site.sethelper()
3814 site.setquit()
3815 except ImportError:
3816 site = None # Keep PyCharm happy
3817
3803 code.interact(local=imported_objects) 3818 code.interact(local=imported_objects)
3804 3819
3805 3820
3806 @command( 3821 @command(
3807 b'debug-revlog-stats', 3822 b'debug-revlog-stats',