Bug 1554186: Fix Python 3 negative import level error r=glandium
authorKagami Sascha Rosylight <saschanaz@outlook.com>
Wed, 29 May 2019 07:58:19 +0000
changeset 476018 f29667d1037ad49dd68a5bfc0c96f2411fd3391f
parent 476017 9ac9f25a433955dadc8d9e02f277e16f71829baf
child 476019 346ed53489fcfffa4d7feb39be153a3e60fc99cd
push id36083
push usernerli@mozilla.com
push dateWed, 29 May 2019 15:58:28 +0000
treeherdermozilla-central@2bb77ed1fcc5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1554186
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1554186: Fix Python 3 negative import level error r=glandium Negative value for import level is obsolete in Python 3, which was used on Py2 for implicit relative import. This change ensures the level value to be >=0 on Py3 to fix test failures. Differential Revision: https://phabricator.services.mozilla.com/D32497
build/mach_bootstrap.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -383,16 +383,19 @@ class ImportHook(object):
         # Assume the source directory is the parent directory of the one
         # containing this file.
         self._source_dir = os.path.normcase(os.path.abspath(
             os.path.dirname(os.path.dirname(__file__)))) + os.sep
         self._modules = set()
 
     def __call__(self, name, globals=None, locals=None, fromlist=None,
                  level=-1):
+        if sys.version_info[0] >= 3 and level < 0:
+            level = 0
+
         # name might be a relative import. Instead of figuring out what that
         # resolves to, which is complex, just rely on the real import.
         # Since we don't know the full module name, we can't check sys.modules,
         # so we need to keep track of which modules we've already seen to avoid
         # to stat() them again when they are imported multiple times.
         module = self._original_import(name, globals, locals, fromlist, level)
 
         # Some tests replace modules in sys.modules with non-module instances.