# HG changeset patch # User Bryan O'Sullivan # Date 1207780110 25200 # Node ID 4f7feeb6d6ee61eb791528a5e8289915649dd2c6 # Parent 315548fcc76bf82917143277b9f51484b9e36046# Parent a3175cd7dbec12eebc56a51800cd6368e939fbc5 Merge diff -r 315548fcc76b -r 4f7feeb6d6ee mercurial/util.py --- a/mercurial/util.py Tue Apr 08 18:40:11 2008 +0200 +++ b/mercurial/util.py Wed Apr 09 15:28:30 2008 -0700 @@ -15,7 +15,7 @@ from i18n import _ import cStringIO, errno, getpass, re, shutil, sys, tempfile import os, stat, threading, time, calendar, ConfigParser, locale, glob, osutil -import urlparse +import imp, urlparse # Python compatibility @@ -563,13 +563,29 @@ _hgexecutable = None +def main_is_frozen(): + """return True if we are a frozen executable. + + The code supports py2exe (most common, Windows only) and tools/freeze + (portable, not much used). + """ + return (hasattr(sys, "frozen") or # new py2exe + hasattr(sys, "importers") or # old py2exe + imp.is_frozen("__main__")) # tools/freeze + def hgexecutable(): """return location of the 'hg' executable. Defaults to $HG or 'hg' in the search path. """ if _hgexecutable is None: - set_hgexecutable(os.environ.get('HG') or find_exe('hg', 'hg')) + hg = os.environ.get('HG') + if hg: + set_hgexecutable(hg) + elif main_is_frozen(): + set_hgexecutable(sys.executable) + else: + set_hgexecutable(find_exe('hg', 'hg')) return _hgexecutable def set_hgexecutable(path):