summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-03-27 18:49:52 -0700
committerZac Medico <zmedico@gentoo.org>2010-03-27 18:49:52 -0700
commitd536979fdc49e23c44ad2d5d16daad630c987a38 (patch)
treee0fb4400dbd14faed6814f87fd1718c26c902be7
parent346c01d70b6f09b6bd042e0dff6b2184bd42a779 (diff)
downloadportage-d536979fdc49e23c44ad2d5d16daad630c987a38.tar.gz
portage-d536979fdc49e23c44ad2d5d16daad630c987a38.tar.bz2
portage-d536979fdc49e23c44ad2d5d16daad630c987a38.zip
Add support for probing shebangs and compiling python scripts that don't
end with py.
-rw-r--r--pym/portage/tests/lint/test_compile_modules.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/pym/portage/tests/lint/test_compile_modules.py b/pym/portage/tests/lint/test_compile_modules.py
index ec6edfa9b..c6e68946e 100644
--- a/pym/portage/tests/lint/test_compile_modules.py
+++ b/pym/portage/tests/lint/test_compile_modules.py
@@ -1,22 +1,49 @@
# Copyright 2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-from portage.const import PORTAGE_PYM_PATH
+import itertools
+import stat
+
+from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH
from portage.tests import TestCase
from portage import os
from portage import _encodings
-from portage import _unicode_decode
+from portage import _unicode_decode, _unicode_encode
import py_compile
class CompileModulesTestCase(TestCase):
def testCompileModules(self):
- for parent, dirs, files in os.walk(PORTAGE_PYM_PATH):
+ for parent, dirs, files in itertools.chain(
+ os.walk(PORTAGE_BIN_PATH),
+ os.walk(PORTAGE_PYM_PATH)):
parent = _unicode_decode(parent,
encoding=_encodings['fs'], errors='strict')
for x in files:
x = _unicode_decode(x,
encoding=_encodings['fs'], errors='strict')
+ if x[-4:] in ('.pyc', '.pyo'):
+ continue
+ x = os.path.join(parent, x)
+ st = os.lstat(x)
+ if not stat.S_ISREG(st.st_mode):
+ continue
+ do_compile = False
+ cfile = x
if x[-3:] == '.py':
- py_compile.compile(os.path.join(parent, x), doraise=True)
+ 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:
+ do_compile = True
+ cfile += '.py'
+ if do_compile:
+ cfile += (__debug__ and 'c' or 'o')
+ py_compile.compile(x, cfile=cfile, doraise=True)