Blob Blame History Raw
# Bug 1669471 - Get rid of `DeprecationWarning` in `file_generate.py` r=firefox-build-system-reviewers,mhentges
# `imp` is deprecated since Python 3.4 and later Python versions are very noisy about printing `DeprecationWarning`s; instead, use its replacement, `importlib`.

--- a/python/mozbuild/mozbuild/action/file_generate.py
+++ b/python/mozbuild/mozbuild/action/file_generate.py
@@ -9,7 +9,7 @@
 from __future__ import absolute_import, print_function
 
 import argparse
-import imp
+import importlib.util
 import os
 import six
 import sys
@@ -56,9 +56,9 @@
     # Since we're invoking the script in a roundabout way, we provide this
     # bit of convenience.
     sys.path.append(os.path.dirname(script))
-    with open(script, 'r') as fh:
-        module = imp.load_module('script', fh, script,
-                                 ('.py', 'r', imp.PY_SOURCE))
+    spec = importlib.util.spec_from_file_location('script', script)
+    module = importlib.util.module_from_spec(spec)
+    spec.loader.exec_module(module)
     method = args.method_name
     if not hasattr(module, method):
         print('Error: script "{0}" is missing a {1} method'.format(script, method),