Use more correct paths to byte-compiled Python modules with Python 3.2
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sat, 14 Aug 2010 18:04:03 +0000 (20:04 +0200)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Gentoo.Org>
Sat, 14 Aug 2010 18:04:03 +0000 (20:04 +0200)
and remove empty __pycache__ directories.

pym/portage/tests/lint/test_compile_modules.py

index 2e5ab7e2df6552231c62c756e7594d49eaf8a4e5..5b86fcfb2d7bda90c69a54b9b59a5e50e1cfe316 100644 (file)
@@ -1,6 +1,7 @@
-# Copyright 2009 Gentoo Foundation
+# Copyright 2009-2010 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import imp
 import itertools
 import stat
 
@@ -45,6 +46,18 @@ class CompileModulesTestCase(TestCase):
                                                do_compile = True
                                                cfile += '.py'
                                if do_compile:
-                                       cfile += (__debug__ and 'c' or 'o')
+                                       try:
+                                               # Python >=3.2
+                                               cfile = imp.cache_from_source(cfile)
+                                       except AttributeError:
+                                               cfile += (__debug__ and 'c' or 'o')
                                        py_compile.compile(x, cfile=cfile, doraise=True)
                                        os.unlink(cfile)
+                                       cfile_parent_dir = os.path.dirname(cfile)
+                                       if os.path.basename(cfile_parent_dir) == '__pycache__':
+                                               # Python >=3.2
+                                               try:
+                                                       os.rmdir(cfile_parent_dir)
+                                               except OSError:
+                                                       # __pycache__ directory is non-empty.
+                                                       pass