# HG changeset patch # User Matt Harbison # Date 2022-04-13 18:37:57 # Node ID 3e8134f74d4d1305bbd0580e9cceeed324f8d085 # Parent 11fc5d8a4411f47cff83ee33e4b70777b834f99a resourceutil: force filesystem access to resources when using py2exe I don't know why it doesn't work, but it avoids this fatal error on startup: > hg debugshell Traceback (most recent call last): File "hg", line 58, in File "mercurial\dispatch.pyc", line 143, in run File "mercurial\dispatch.pyc", line 232, in dispatch File "mercurial\dispatch.pyc", line 254, in _rundispatch File "mercurial\ui.pyc", line 316, in load File "mercurial\rcutil.pyc", line 98, in rccomponents File "mercurial\rcutil.pyc", line 68, in default_rc_resources File "mercurial\utils\resourceutil.pyc", line 102, in contents File "", line 775, in contents AssertionError I assume the py2 version of py2exe never hit this because `importlib.resources` failed to import. Differential Revision: https://phab.mercurial-scm.org/D12554 diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py --- a/mercurial/utils/resourceutil.py +++ b/mercurial/utils/resourceutil.py @@ -61,6 +61,10 @@ try: # Force loading of the resources module resources.open_binary # pytype: disable=module-attr + # py2exe raises an AssertionError if uses importlib.resources + if getattr(sys, "frozen", None) in ("console_exe", "windows_exe"): + raise ImportError + except (ImportError, AttributeError): # importlib.resources was not found (almost definitely because we're on a # Python version before 3.7)