diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index 02a3cd815c8..0184a2c8b4c 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -180,21 +180,20 @@ if localenv['python2_package'] == 'full': # Use 3to2 to convert examples from Python 3 syntax if env['python_convert_examples']: - def convert_example(target, source, env): - shutil.copyfile(source[0].abspath, target[0].abspath) - subprocess.call(env['threetotwo_cmd'] + ['--no-diff', '-n', '-w','-x', 'str', - '-f', 'all', '-f', 'printfunction', '-x', 'print', - '-x', 'open', target[0].abspath]) - for subdir in subdirs('cantera/examples'): - dirpath = pjoin('cantera', 'examples', subdir) - for filename in os.listdir(dirpath): - if not filename.endswith('.py'): - continue - targetdir = '../../build/python2/cantera/examples' - a = build(py2env.Command(pjoin(targetdir, subdir, filename), - pjoin(dirpath, filename), - convert_example)) - py2env.Depends(mod, a) + a = build(py2env.Command('#build/python2/cantera/examples', 'cantera/examples', + Copy("$TARGET", "$SOURCE"))) + from textwrap import dedent + # In these next few things, the double quotes are necessary + # so the command line is processed properly + threetotwo_options = ['--no-diff', '-n', '-w', '-x', 'str', '-x', 'print', '-x', 'open', + '-f', 'all', '-f', 'printfunction'] + threetotwo_options = ', '.join(["'{}'"]*len(threetotwo_options)).format(*threetotwo_options) + ex_loc = "'build/python2/cantera/examples'" + convert_script = dedent("""\ + $python2_cmd_esc -c "from lib3to2.main import main; main('lib3to2.fixes', [{opts}, {loc}])" + """.format(opts=threetotwo_options, loc=ex_loc)) + b = build(py2env.AddPostAction(a, convert_script)) + py2env.Depends(mod, b) add_dependencies(mod, ext) install_module(py2env['python2_prefix'], py2_version)