hgmo: delay import mozbuildinfo module; r?glob draft
authorGregory Szorc <gps@mozilla.com>
Fri, 31 Mar 2017 13:43:36 -0700
changeset 10596 f3a0d18c647d9b40b2607c747adfaba9a2e5a78d
parent 10595 ba73c94e8eb5f8609dba757b98fc456bc0b70e9b
child 10597 c4250dd5507b8d8d371fcfbc19fe54b12a88306f
push id1596
push userbmo:gps@mozilla.com
push dateFri, 31 Mar 2017 21:38:22 +0000
reviewersglob
hgmo: delay import mozbuildinfo module; r?glob Without this change, an upcoming commit that removes the bundleclone extension from hgweb breaks the hgmo extension. After much head scratching, I tracked this down to Mercurial's demand importer and a bug in bundleclone. The bundleclone extension uses the legacy, non-context-manager API for disabling the demand importer when performing a module presence test. Instead of restoring the previous state of the demand importer, after this operation, it always calls "demandimport.enable()" thus ensuring it is enabled. When the bundleclone extension is removed, the hgmo extension is loaded with the demand importer disabled. (We stopped enabling the demand importer in WSGI processes in 287fd5985aa2.) This caused the mozbuildinfo module import to fail because it attempts to import mozbuild and mozpack modules which don't exist in the hgweb virtualenv. This caused the hgmo module load to fail and hgweb to effectively break. The fix for this on hgmo's side is to delay import the module containing unknown modules until they are actually needed. A fix for bundleclone won't be pursued because the extension is effectively deprecated and will be removed from use shortly. MozReview-Commit-ID: E5LK1nfoA68
hgext/hgmo/__init__.py
--- a/hgext/hgmo/__init__.py
+++ b/hgext/hgmo/__init__.py
@@ -106,17 +106,16 @@ from mercurial.hgweb.protocol import (
 )
 
 
 OUR_DIR = os.path.dirname(__file__)
 ROOT = os.path.normpath(os.path.join(OUR_DIR, '..', '..'))
 execfile(os.path.join(OUR_DIR, '..', 'bootstrap.py'))
 
 import mozautomation.commitparser as commitparser
-import mozhg.mozbuildinfo as mozbuildinfo
 
 
 minimumhgversion = '4.0'
 testedwith = '4.0'
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
@@ -579,16 +578,21 @@ def servehgmo(orig, ui, repo, *args, **k
 
 
 @command('mozbuildinfo', [
     ('r', 'rev', '.', _('revision to query'), _('REV')),
     ('', 'pipemode', False, _('accept arguments from stdin')),
     ], _('show files info from moz.build files'),
     optionalrepo=True)
 def mozbuildinfocommand(ui, repo, *paths, **opts):
+    # This module imports modules not available to the hgweb virtualenv.
+    # Delay importing it so it doesn't interfere with operation outside the
+    # moz.build evaluation context.
+    import mozhg.mozbuildinfo as mozbuildinfo
+
     if opts['pipemode']:
         data = json.loads(ui.fin.read())
 
         repo = hg.repository(ui, path=data['repo'])
         ctx = repo[data['node']]
         paths = data['paths']
     else:
         ctx = repo[opts['rev']]