comparison mercurial/utils/resourceutil.py @ 50753:847f703a4d13 stable

utils: imp module is removed in Python 3.12 - get is_frozen() from _imp imp has been deprecated for a long time, and has finally been removed in Python 3.12 . The successor importlib is using the same internal _imp module as imp, but doesn't expose it's is_frozen. Using the internal function directly seems like the cleanest solution. Another alternative to imp.is_frozen("__main__") is sys.modules['__main__'].__spec__.origin == 'frozen' but that seems even more internal and fragile.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 27 Jun 2023 13:05:03 +0200
parents 330d88217b83
children d718eddf01d9
comparison
equal deleted inserted replaced
50752:b9eb65a1ec14 50753:847f703a4d13
6 # 6 #
7 # This software may be used and distributed according to the terms of the 7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version. 8 # GNU General Public License version 2 or any later version.
9 9
10 10
11 import imp 11 import _imp
12 import os 12 import os
13 import sys 13 import sys
14 14
15 from .. import pycompat 15 from .. import pycompat
16 16
22 (portable, not much used). 22 (portable, not much used).
23 """ 23 """
24 return ( 24 return (
25 pycompat.safehasattr(sys, "frozen") # new py2exe 25 pycompat.safehasattr(sys, "frozen") # new py2exe
26 or pycompat.safehasattr(sys, "importers") # old py2exe 26 or pycompat.safehasattr(sys, "importers") # old py2exe
27 or imp.is_frozen("__main__") # tools/freeze 27 or _imp.is_frozen("__main__") # tools/freeze
28 ) 28 )
29 29
30 30
31 # the location of data files matching the source code 31 # the location of data files matching the source code
32 if mainfrozen() and getattr(sys, "frozen", None) != "macosx_app": 32 if mainfrozen() and getattr(sys, "frozen", None) != "macosx_app":