testCompileModules(): Use builtins.compile() instead of py_compile.compile()
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Wed, 20 Feb 2013 19:53:53 +0000 (20:53 +0100)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Wed, 20 Feb 2013 19:53:53 +0000 (20:53 +0100)
to avoid replacing /dev/null character device with a regular file when
using Python 3.4 (http://bugs.python.org/issue17222).

pym/portage/tests/lint/test_compile_modules.py

index f90a6665a2d9246bbfb88f5d4d14d50324c6edc1..1d44e6828639dd37859ad7a0a870823c3cdbadfa 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2009-2010 Gentoo Foundation
+# Copyright 2009-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import itertools
@@ -10,8 +10,6 @@ from portage import os
 from portage import _encodings
 from portage import _unicode_decode, _unicode_encode
 
-import py_compile
-
 class CompileModulesTestCase(TestCase):
 
        def testCompileModules(self):
@@ -34,13 +32,13 @@ class CompileModulesTestCase(TestCase):
                                        do_compile = True
                                else:
                                        # Check for python shebang
-                                       f = open(_unicode_encode(x,
-                                               encoding=_encodings['fs'], errors='strict'), 'rb')
-                                       line = _unicode_decode(f.readline(),
-                                               encoding=_encodings['content'], errors='replace')
-                                       f.close()
-                                       if line[:2] == '#!' and \
-                                               'python' in line:
+                                       with open(_unicode_encode(x,
+                                               encoding=_encodings['fs'], errors='strict'), 'rb') as f:
+                                               line = _unicode_decode(f.readline(),
+                                                       encoding=_encodings['content'], errors='replace')
+                                       if line[:2] == '#!' and 'python' in line:
                                                do_compile = True
                                if do_compile:
-                                       py_compile.compile(x, cfile='/dev/null', doraise=True)
+                                       with open(_unicode_encode(x,
+                                               encoding=_encodings['fs'], errors='strict'), 'rb') as f:
+                                               compile(f.read(), x, 'exec')