Add Python version test to detect {} in version strings.
- {} is not compatible with Python 2.6
This commit is contained in:
parent
1e2f421faa
commit
27ca697b43
12
lib/spack/external/pyqver2.py
vendored
12
lib/spack/external/pyqver2.py
vendored
@ -165,12 +165,24 @@ def visitCallFunc(self, node):
|
||||
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)
|
||||
|
@ -41,13 +41,10 @@
|
||||
|
||||
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 @@ def spack_python_files(self):
|
||||
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 @@ def check_python_versions(self, files):
|
||||
|
||||
|
||||
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))
|
||||
|
Loading…
Reference in New Issue
Block a user