Issue 25621: ast.literal_eval() fails on docstrings (original) (raw)

ast.literal_eval fails when there is docstrings in the file.

I used the file attached and this code in our CI server:

def is_installable_module(path): """return False if the path doesn't contain an installable odoo module, and the full path to the module manifest otherwise""" manifest_path = is_module(path) if manifest_path: manifest = ast.literal_eval(open(manifest_path).read()) if manifest.get('installable', True): return manifest_path return False

I get the following error message: Traceback (most recent call last):

File "/home/travis/maintainer-quality-tools/travis/test_flake8", line 14, in

for addon in get_modules(os.path.abspath('.')):

File "/home/travis/maintainer-quality-tools/travis/getaddons.py", line 53, in get_modules

if is_installable_module(os.path.join(path, x))]

File "/home/travis/maintainer-quality-tools/travis/getaddons.py", line 38, in is_installable_module

manifest = ast.literal_eval(open(manifest_path).read())

File "/usr/lib/python2.7/ast.py", line 49, in literal_eval

node_or_string = parse(node_or_string, mode='eval')

File "/usr/lib/python2.7/ast.py", line 37, in parse

return compile(source, filename, mode, PyCF_ONLY_AST)

File "", line 22

{

^

SyntaxError: invalid syntax

https://github.com/OCA/knowledge/pull/75 https://github.com/OCA/maintainer-quality-tools/blob/master/travis/getaddons.py#L33 https://travis-ci.org/OCA/knowledge/jobs/90332842