]> granicus.if.org Git - python/commitdiff
Issue #17177: Stop using imp with py_compile
authorBrett Cannon <brett@python.org>
Sat, 15 Jun 2013 18:07:21 +0000 (14:07 -0400)
committerBrett Cannon <brett@python.org>
Sat, 15 Jun 2013 18:07:21 +0000 (14:07 -0400)
Lib/py_compile.py
Lib/test/test_py_compile.py

index cee35a5b6b1121311e17a0947867417fcfe63fad..9919debca041f80a405cacc874672844d41efd44 100644 (file)
@@ -3,9 +3,9 @@
 This module has intimate knowledge of the format of .pyc files.
 """
 
-import imp
 import importlib._bootstrap
 import importlib.machinery
+import importlib.util
 import os
 import os.path
 import sys
@@ -105,9 +105,10 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1):
     """
     if cfile is None:
         if optimize >= 0:
-            cfile = imp.cache_from_source(file, debug_override=not optimize)
+            cfile = importlib.util.cache_from_source(file,
+                                                     debug_override=not optimize)
         else:
-            cfile = imp.cache_from_source(file)
+            cfile = importlib.util.cache_from_source(file)
     if os.path.islink(cfile):
         msg = ('{} is a symlink and will be changed into a regular file if '
                'import writes a byte-compiled file to it')
index 9f341bdf8c0a9b1ef9ba8ffbe714efe2d0229451..2ad9c3a0002aa26029ea82b24e39326bc70dba0a 100644 (file)
@@ -1,4 +1,4 @@
-import imp
+import importlib.util
 import os
 import py_compile
 import shutil
@@ -14,7 +14,7 @@ class PyCompileTests(unittest.TestCase):
         self.directory = tempfile.mkdtemp()
         self.source_path = os.path.join(self.directory, '_test.py')
         self.pyc_path = self.source_path + 'c'
-        self.cache_path = imp.cache_from_source(self.source_path)
+        self.cache_path = importlib.util.cache_from_source(self.source_path)
         self.cwd_drive = os.path.splitdrive(os.getcwd())[0]
         # In these tests we compute relative paths.  When using Windows, the
         # current working directory path and the 'self.source_path' might be