Enable demandimport only in scripts, not in importable modules (issue605)
authorThomas Arendsen Hein <thomas@intevation.de>
Sat, 18 Aug 2007 11:37:08 +0200
changeset 5197 55860a45bbf281dfe9f8d081f9f1498064652151
parent 5196 86e95b93559afa8e16d5c13f306012d571775954
child 5198 74650bcacc09be967aa80fae3cb5ebf48808839e
push id1
push usergszorc@mozilla.com
push dateWed, 18 Mar 2015 16:34:57 +0000
Enable demandimport only in scripts, not in importable modules (issue605) This way other applications can choose if and when they want this feature, because it might be problematic if those applications rely on ImportError.
contrib/hg-ssh
contrib/hgwebdir.fcgi
hg
hgweb.cgi
hgwebdir.cgi
mercurial/hgweb/hgwebdir_mod.py
setup.py
--- a/contrib/hg-ssh
+++ b/contrib/hg-ssh
@@ -20,16 +20,19 @@ This allows pull/push over ssh to to the
 If all your repositories are subdirectories of a common directory, you can
 allow shorter paths with:
 command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2"
 
 You can use pattern matching of your normal shell, e.g.:
 command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}"
 """
 
+# enable importing on demand to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
 from mercurial import dispatch
 
 import sys, os
 
 cwd = os.getcwd()
 allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path)))
                  for path in sys.argv[1:]]
 orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?')
--- a/contrib/hgwebdir.fcgi
+++ b/contrib/hgwebdir.fcgi
@@ -1,12 +1,15 @@
 #!/usr/bin/env python
 #
 # An example CGI script to export multiple hgweb repos, edit as necessary
 
+# enable demandloading to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
 # send python tracebacks to the browser if an error occurs:
 import cgitb
 cgitb.enable()
 
 # adjust python path if not a system-wide install:
 #import sys
 #sys.path.insert(0, "/path/to/python/lib")
 
--- a/hg
+++ b/hg
@@ -2,10 +2,13 @@
 #
 # mercurial - scalable distributed SCM
 #
 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
+# enable importing on demand to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
 import mercurial.dispatch
 mercurial.dispatch.run()
--- a/hgweb.cgi
+++ b/hgweb.cgi
@@ -1,12 +1,15 @@
 #!/usr/bin/env python
 #
 # An example CGI script to use hgweb, edit as necessary
 
+# enable importing on demand to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
 # send python tracebacks to the browser if an error occurs:
 import cgitb
 cgitb.enable()
 
 # adjust python path if not a system-wide install:
 #import sys
 #sys.path.insert(0, "/path/to/python/lib")
 
--- a/hgwebdir.cgi
+++ b/hgwebdir.cgi
@@ -1,12 +1,15 @@
 #!/usr/bin/env python
 #
 # An example CGI script to export multiple hgweb repos, edit as necessary
 
+# enable importing on demand to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+
 # send python tracebacks to the browser if an error occurs:
 import cgitb
 cgitb.enable()
 
 # adjust python path if not a system-wide install:
 #import sys
 #sys.path.insert(0, "/path/to/python/lib")
 
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -1,17 +1,16 @@
 # hgweb/hgwebdir_mod.py - Web interface for a directory of repositories.
 #
 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
 #
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-from mercurial import demandimport; demandimport.enable()
 import os, mimetools, cStringIO
 from mercurial.i18n import gettext as _
 from mercurial import ui, hg, util, templater
 from common import get_mtime, staticfile, style_map, paritygen
 from hgweb_mod import hgweb
 
 # This is a stopgap
 class hgwebdir(object):
--- a/setup.py
+++ b/setup.py
@@ -9,18 +9,16 @@ import sys
 if not hasattr(sys, 'version_info') or sys.version_info < (2, 3, 0, 'final'):
     raise SystemExit, "Mercurial requires python 2.3 or later."
 
 import os
 from distutils.core import setup, Extension
 from distutils.command.install_data import install_data
 
 import mercurial.version
-import mercurial.demandimport
-mercurial.demandimport.enable = lambda: None
 
 extra = {}
 
 # py2exe needs to be installed to work
 try:
     import py2exe
 
     # Help py2exe to find win32com.shell