# HG changeset patch # User Julien Cristau # Date 1446053970 0 # Node ID 3d948d35d94fdd6c0d9f2df0b4e44c8e0673f4a1 # Parent b4beaf0bccea668636b2e22df00e2f6c9434f212 [migration] re-try without print_function when compiling a script fails As part of the python3 porting we added the __future__.print_function import to cubicweb.migration. That started affecting all migration scripts it runs, which may not be prepared. So if compiling a script results in SyntaxError, try again without the print_function flag. Closes #7935030 diff -r b4beaf0bccea -r 3d948d35d94f migration.py --- a/migration.py Wed Sep 23 15:32:17 2015 +0200 +++ b/migration.py Wed Oct 28 17:39:30 2015 +0000 @@ -26,6 +26,7 @@ import tempfile from os.path import exists, join, basename, splitext from itertools import chain +from warnings import warn from six import string_types @@ -350,7 +351,14 @@ pyname = splitext(basename(migrscript))[0] scriptlocals['__name__'] = pyname with open(migrscript, 'rb') as fobj: - code = compile(fobj.read(), migrscript, 'exec') + fcontent = fobj.read() + try: + code = compile(fcontent, migrscript, 'exec') + except SyntaxError: + # try without print_function + code = compile(fcontent, migrscript, 'exec', 0, True) + warn('[3.22] script %r should be updated to work with print_function' + % migrscript, DeprecationWarning) exec(code, scriptlocals) if funcname is not None: try: