From 2024d0f08a2577475ea29b3ff85db01eb077f972 Mon Sep 17 00:00:00 2001 From: "Bryan W. Weber" Date: Fri, 9 Dec 2016 14:54:42 -0500 Subject: [PATCH] [SCons] Fix calling 3to2 on Windows with conda 3to2 package Fixes #408 --- SConstruct | 13 +++++++++++-- interfaces/cython/SConscript | 4 +--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 1581f392b..4c439113c 100644 --- a/SConstruct +++ b/SConstruct @@ -1096,7 +1096,15 @@ if env['python_package'] in ('full','default'): if env['OS'] == 'Windows': python_dir = os.path.dirname(which(env['python_cmd'])) threetotwo_cmd = pjoin(python_dir, 'Scripts', '3to2') - ret = getCommandOutput(env['python_cmd'], threetotwo_cmd, '-l') + # Conda installs 3to2 as an EXE file that can be executed directly + # but pip installs only a script. Try executing the EXE file first, + # and if it fails because the file doesn't exist, try the script + try: + ret = getCommandOutput(threetotwo_cmd, '-l') + env['threetotwo_cmd'] = [threetotwo_cmd] + except WindowsError: + ret = getCommandOutput(env['python_cmd'], threetotwo_cmd, '-l') + env['threetotwo_cmd'] = [env['python_cmd'], threetotwo_cmd] else: ret = getCommandOutput('3to2' '-l') except (OSError, subprocess.CalledProcessError) as err: @@ -1108,7 +1116,8 @@ if env['python_package'] in ('full','default'): env['python_convert_examples'] = True else: env['python_convert_examples'] = False - print """WARNING: Couldn't find '3to2'. Python examples will not work correctly.""" + print ("WARNING: Couldn't find the 3to2 package. " + "Python 2 examples will not work correctly.") else: env['python_module_loc'] = '' diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index 6a7023acc..5fec21aa7 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -185,9 +185,7 @@ if localenv['python_package'] == 'full': def convert_example(target, source, env): shutil.copyfile(source[0].abspath, target[0].abspath) if env['OS'] == 'Windows': - python_dir = os.path.dirname(which(env['python_cmd'])) - threetotwo_cmd = pjoin(python_dir, 'Scripts', '3to2') - subprocess.call([env['python_cmd'], threetotwo_cmd, '--no-diff', '-n', '-w','-x', 'str', + subprocess.call(env['threetotwo_cmd'] + ['--no-diff', '-n', '-w','-x', 'str', '-f', 'all', '-f', 'printfunction', '-x', 'print', '-x', 'open', target[0].abspath]) else: