diff mercurial/utils/procutil.py @ 43712:664e24207728

procutil: move mainfrozen() to new resourceutil.py The i18n module practically depends on procutil for mainfrozen() but since procutil depends on i18n, it would be a circular dependency if i18n depended directly on procutil. The cycle is currently resolved by having the higher-level util module calculate the "datapath" and inject it into i18n. Extracting mainfrozen() to a new module lets us clean up the dependencies. Differential Revision: https://phab.mercurial-scm.org/D7433
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 14 Nov 2019 11:52:22 -0800
parents 38387f9e4d22
children be8552f25cab
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Thu Nov 14 17:36:01 2019 -0800
+++ b/mercurial/utils/procutil.py	Thu Nov 14 11:52:22 2019 -0800
@@ -11,7 +11,6 @@
 
 import contextlib
 import errno
-import imp
 import io
 import os
 import signal
@@ -32,6 +31,9 @@
     pycompat,
 )
 
+# Import like this to keep import-checker happy
+from ..utils import resourceutil
+
 osutil = policy.importmod('osutil')
 
 stderr = pycompat.stderr
@@ -254,19 +256,6 @@
     return pipefilter(s, cmd)
 
 
-def mainfrozen():
-    """return True if we are a frozen executable.
-
-    The code supports py2exe (most common, Windows only) and tools/freeze
-    (portable, not much used).
-    """
-    return (
-        pycompat.safehasattr(sys, "frozen")
-        or pycompat.safehasattr(sys, "importers")  # new py2exe
-        or imp.is_frozen("__main__")  # old py2exe
-    )  # tools/freeze
-
-
 _hgexecutable = None
 
 
@@ -280,7 +269,7 @@
         mainmod = sys.modules['__main__']
         if hg:
             _sethgexecutable(hg)
-        elif mainfrozen():
+        elif resourceutil.mainfrozen():
             if getattr(sys, 'frozen', None) == 'macosx_app':
                 # Env variable set by py2app
                 _sethgexecutable(encoding.environ[b'EXECUTABLEPATH'])
@@ -456,7 +445,7 @@
     to avoid things opening new shell windows like batch files, so we
     get either the python call or current executable.
     """
-    if mainfrozen():
+    if resourceutil.mainfrozen():
         if getattr(sys, 'frozen', None) == 'macosx_app':
             # Env variable set by py2app
             return [encoding.environ[b'EXECUTABLEPATH']]