diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py --- a/mercurial/utils/resourceutil.py +++ b/mercurial/utils/resourceutil.py @@ -8,7 +8,6 @@ # GNU General Public License version 2 or any later version. -import _imp import os import sys @@ -24,7 +23,12 @@ def mainfrozen(): return ( hasattr(sys, "frozen") # new py2exe or hasattr(sys, "importers") # old py2exe - or _imp.is_frozen("__main__") # tools/freeze + or getattr( + getattr(sys.modules.get('__main__'), '__spec__', None), + 'origin', + None, + ) + == 'frozen' # tools/freeze ) @@ -44,7 +48,6 @@ if mainfrozen() and getattr(sys, "frozen assert dirs[0] == b"mercurial" return os.path.join(_rootpath, *dirs[1:]) - else: datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__))) _rootpath = os.path.dirname(datapath) @@ -90,7 +93,6 @@ except (ImportError, AttributeError): for p in os.listdir(path): yield pycompat.fsencode(p) - else: from .. import encoding