comparison mercurial/util.py @ 27765:f1fb93eebb1d

util: adjust hgexecutable() to handle frozen Mercurial on OS X sys.executable is "$appbundle/Contents/MacOS/python" when Mercurial is bundled in a frozen app bundle on OS X, so that isn't appropriate. It appears that this was only visible for things launched via util.system(), like external hooks, where $HG was set wrong. It appears that Mercurial also uses 'sys.modules['__main__'].__file__' (here) and 'sys.argv[0]' (in platform.gethgcmd()) to figure out the command to spawn. In both cases, this points to "$appbundle/Contents/Resources/hg", which invokes the system python since "/usr/bin/env python" is on the shebang line. On my system with a screwed up python install, I get an error importing the os module if this script is invoked. We could take the dirname of sys.executable and join 'hg' instead of this if we want to be paranoid, but py2app boostrap is setting the environment variable since 0.1.6 (current version is 0.9), so it seems safe and we might as well use it.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 10 Jan 2016 17:56:08 -0500
parents dd0c5f4d1b53
children 198f78a52a2f
comparison
equal deleted inserted replaced
27764:dd0c5f4d1b53 27765:f1fb93eebb1d
905 hg = os.environ.get('HG') 905 hg = os.environ.get('HG')
906 mainmod = sys.modules['__main__'] 906 mainmod = sys.modules['__main__']
907 if hg: 907 if hg:
908 _sethgexecutable(hg) 908 _sethgexecutable(hg)
909 elif mainfrozen(): 909 elif mainfrozen():
910 _sethgexecutable(sys.executable) 910 if getattr(sys, 'frozen', None) == 'macosx_app':
911 # Env variable set by py2app
912 _sethgexecutable(os.environ['EXECUTABLEPATH'])
913 else:
914 _sethgexecutable(sys.executable)
911 elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg': 915 elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg':
912 _sethgexecutable(mainmod.__file__) 916 _sethgexecutable(mainmod.__file__)
913 else: 917 else:
914 exe = findexe('hg') or os.path.basename(sys.argv[0]) 918 exe = findexe('hg') or os.path.basename(sys.argv[0])
915 _sethgexecutable(exe) 919 _sethgexecutable(exe)