Skip to content

Commit

Permalink
Run 3to2 converter directly rather than by script
Browse files Browse the repository at this point in the history
Take advantage of the fact that the 3to2 converter recurses by default
to avoid spawning a bunch of subprocesses. Also, don't depend on the
location of the 3to2 script and just use the library directly.
  • Loading branch information
bryanwweber committed Nov 17, 2017
1 parent c501b2e commit 5e0685b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions interfaces/cython/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5e0685b

Please sign in to comment.