commit:     70a41bd4404cccc502a3eacf6335c8d2c9503129
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 30 22:53:50 2015 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Feb  1 09:06:41 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=70a41bd4

test_compile_modules: skip files that require newer Python version

Support skipping Python modules and scripts that require newer Python
version than currently used during compile tests. Add a metadata db that
can be used to store additional information about Python files, and
store the required language version there.

---
 pym/portage/tests/lint/metadata.py             | 11 +++++++++++
 pym/portage/tests/lint/test_compile_modules.py | 13 +++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/pym/portage/tests/lint/metadata.py 
b/pym/portage/tests/lint/metadata.py
new file mode 100644
index 0000000..e3f90cb
--- /dev/null
+++ b/pym/portage/tests/lint/metadata.py
@@ -0,0 +1,11 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+module_metadata = {
+}
+
+script_metadata = {
+       'socks5-server.py': {
+               'required_python': '3.3',
+       },
+}

diff --git a/pym/portage/tests/lint/test_compile_modules.py 
b/pym/portage/tests/lint/test_compile_modules.py
index 4826cad..51eb8cd 100644
--- a/pym/portage/tests/lint/test_compile_modules.py
+++ b/pym/portage/tests/lint/test_compile_modules.py
@@ -4,9 +4,11 @@
 import errno
 import itertools
 import stat
+import sys
 
 from portage.const import PORTAGE_BIN_PATH, PORTAGE_PYM_PATH, 
PORTAGE_PYM_PACKAGES
 from portage.tests import TestCase
+from portage.tests.lint.metadata import module_metadata, script_metadata
 from portage import os
 from portage import _encodings
 from portage import _unicode_decode, _unicode_encode
@@ -30,6 +32,17 @@ class CompileModulesTestCase(TestCase):
                                st = os.lstat(x)
                                if not stat.S_ISREG(st.st_mode):
                                        continue
+
+                               bin_path = os.path.relpath(x, PORTAGE_BIN_PATH)
+                               mod_path = os.path.relpath(x, PORTAGE_PYM_PATH)
+
+                               meta = module_metadata.get(mod_path) or 
script_metadata.get(bin_path)
+                               if meta:
+                                       req_py = tuple(int(x) for x
+                                                       in 
meta.get('required_python', '0.0').split('.'))
+                                       if sys.version_info < req_py:
+                                               continue
+
                                do_compile = False
                                if x[-3:] == '.py':
                                        do_compile = True

Reply via email to