Read about our upcoming Code of Conduct on this issue

Commit bc58f49e authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

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
parent 02fe8dedab8c
......@@ -22,6 +22,7 @@ from . import (
)
from .utils import (
procutil,
resourceutil,
stringutil,
)
......@@ -48,7 +49,7 @@ def pythonhook(ui, repo, htype, hname, funcname, args, throw):
)
modname = funcname[:d]
oldpaths = sys.path
if procutil.mainfrozen():
if resourceutil.mainfrozen():
# binary installs require sys.path manipulation
modpath, modfile = os.path.split(modname)
if modpath and modfile:
......
......@@ -24,7 +24,7 @@ from . import (
util,
)
from .utils import (
procutil,
resourceutil,
stringutil,
)
......@@ -786,7 +786,7 @@ def _plainapplepython():
"""
if (
not pycompat.isdarwin
or procutil.mainfrozen()
or resourceutil.mainfrozen()
or not pycompat.sysexecutable
):
return False
......
......@@ -54,6 +54,7 @@ from . import (
from .utils import (
compression,
procutil,
resourceutil,
stringutil,
)
......@@ -1823,7 +1824,7 @@ def pathto(root, n1, n2):
# the location of data files matching the source code
if procutil.mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
if resourceutil.mainfrozen() and getattr(sys, 'frozen', None) != 'macosx_app':
# executable version (py2exe) doesn't support __file__
datapath = os.path.dirname(pycompat.sysexecutable)
else:
......
......@@ -11,7 +11,6 @@ from __future__ import absolute_import
import contextlib
import errno
import imp
import io
import os
import signal
......@@ -32,6 +31,9 @@ from .. import (
pycompat,
)
# Import like this to keep import-checker happy
from ..utils import resourceutil
osutil = policy.importmod('osutil')
stderr = pycompat.stderr
......@@ -254,19 +256,6 @@ def filter(s, cmd):
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 @@ def hgexecutable():
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 @@ def hgcmd():
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']]
......
# resourceutil.py - utility for looking up resources
#
# Copyright 2005 K. Thananchayan <thananck@yahoo.com>
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import imp
import sys
from .. import pycompat
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment