From 27ca697b43458c76fd7e079c2a6395fbb5b6126e Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Fri, 24 Jul 2015 14:22:28 -0700 Subject: Add Python version test to detect {} in version strings. - {} is not compatible with Python 2.6 --- lib/spack/external/pyqver2.py | 12 ++++++++++++ lib/spack/spack/test/python_version.py | 17 +++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/spack/external/pyqver2.py b/lib/spack/external/pyqver2.py index cd45bf948f..4a16e2811e 100755 --- a/lib/spack/external/pyqver2.py +++ b/lib/spack/external/pyqver2.py @@ -165,12 +165,24 @@ class NodeChecker(object): def rollup(n): if isinstance(n, compiler.ast.Name): return n.name + elif isinstance(n, compiler.ast.Const): + return type(n.value).__name__ elif isinstance(n, compiler.ast.Getattr): r = rollup(n.expr) if r: return r + "." + n.attrname name = rollup(node.node) if name: + # Special handling for empty format strings, which aren't + # allowed in Python 2.6 + if name in ('unicode.format', 'str.format'): + n = node.node + if isinstance(n, compiler.ast.Getattr): + n = n.expr + if isinstance(n, compiler.ast.Const): + if '{}' in n.value: + self.add(node, (2,7), name + ' with {} format string') + v = Functions.get(name) if v is not None: self.add(node, v, name) diff --git a/lib/spack/spack/test/python_version.py b/lib/spack/spack/test/python_version.py index 5b803b4cf3..5779d31ed2 100644 --- a/lib/spack/spack/test/python_version.py +++ b/lib/spack/spack/test/python_version.py @@ -41,13 +41,10 @@ spack_max_version = (2,6) class PythonVersionTest(unittest.TestCase): - def spack_python_files(self): + def pyfiles(self, *search_paths): # first file is the spack script. yield spack.spack_file - # Next files are all the source files and package files. - search_paths = [spack.lib_path, spack.var_path] - # Iterate through the whole spack source tree. for path in search_paths: for root, dirnames, filenames in os.walk(path): @@ -56,16 +53,20 @@ class PythonVersionTest(unittest.TestCase): yield os.path.join(root, filename) - def all_package_py_files(self): + def package_py_files(self): for name in spack.db.all_package_names(): yield spack.db.filename_for_package_name(name) - def check_python_versions(self, files): + def check_python_versions(self, *files): # dict version -> filename -> reasons all_issues = {} for fn in files: + if fn != '/Users/gamblin2/src/spack/var/spack/packages/vim/package.py': + continue + print fn + with open(fn) as pyfile: versions = pyqver2.get_versions(pyfile.read()) for ver, reasons in versions.items(): @@ -101,8 +102,8 @@ class PythonVersionTest(unittest.TestCase): def test_core_module_compatibility(self): - self.check_python_versions(self.spack_python_files()) + self.check_python_versions(*self.pyfiles(spack.lib_path)) def test_package_module_compatibility(self): - self.check_python_versions(self.all_package_py_files()) + self.check_python_versions(*self.pyfiles(spack.packages_path)) -- cgit v1.2.3-60-g2f50