windows: disable pager when packaged with py2exe
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 13 Apr 2022 15:02:01 -0400
changeset 49075 7afa96d3b484
parent 49074 4ba27acdea63
child 49076 9c8d67a3af5e
windows: disable pager when packaged with py2exe With Windows and py3, all output that got directed to the pager was lost. It can be worked around by the user piping to `more`, but that's easy to forget, and can be dangerous if `hg diff` or similar incorrectly shows no changes. The problem appears to be the new WindowsConsoleIO in py3.6[1]. We've worked around it with PyOxidizer by setting the `Py_LegacyWindowsStdioFlag` interpreter option, and worked around it with `hg.bat` and `exewrapper.c` by internally setting `PYTHONLEGACYWINDOWSSTDIO=1`. Unfortunately, py2exe doesn't appear to be able to set the interpreter option, and somehow seems to also ignore the environment variable. The latter isn't a good fix anyway, since setting it in the environment would affect other python programs too. We can't install a global config for this because a config closer to the user (e.g. from before pager was turned on by default) can override it. [1] https://peps.python.org/pep-0528/ Differential Revision: https://phab.mercurial-scm.org/D12556
mercurial/ui.py
--- a/mercurial/ui.py	Wed Apr 13 14:37:57 2022 -0400
+++ b/mercurial/ui.py	Wed Apr 13 15:02:01 2022 -0400
@@ -1432,6 +1432,14 @@
             # HGPLAINEXCEPT=pager, and the user didn't specify --debug.
             return
 
+        # py2exe doesn't appear to be able to use legacy I/O, and nothing is
+        # output to the pager for paged commands.  Piping to `more` in cmd.exe
+        # works, but is easy to forget.  Just disable pager for py2exe, but
+        # leave it working for pyoxidizer and exewrapper builds.
+        if pycompat.iswindows and getattr(sys, "frozen", None) == "console_exe":
+            self.debug(b"pager is unavailable with py2exe packaging\n")
+            return
+
         pagercmd = self.config(b'pager', b'pager', rcutil.fallbackpager)
         if not pagercmd:
             return