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 <module>
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 "<frozen zipimport>", 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
--- a/mercurial/utils/resourceutil.py Wed Apr 13 14:25:13 2022 -0400
+++ b/mercurial/utils/resourceutil.py Wed Apr 13 14:37:57 2022 -0400
@@ -61,6 +61,10 @@
# 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)