From f3fb3fb348dea23a857338c6397098453aad90ba Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 14 Aug 2010 20:04:03 +0200 Subject: [PATCH] Use more correct paths to byte-compiled Python modules with Python 3.2 and remove empty __pycache__ directories. --- pym/portage/tests/lint/test_compile_modules.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pym/portage/tests/lint/test_compile_modules.py b/pym/portage/tests/lint/test_compile_modules.py index 2e5ab7e2d..5b86fcfb2 100644 --- a/pym/portage/tests/lint/test_compile_modules.py +++ b/pym/portage/tests/lint/test_compile_modules.py @@ -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 -- 2.26.2