From 17c89f82373769f1ba3150e9490ab8b7035c1cef Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 10 Sep 2014 22:33:09 +0000 Subject: [PATCH] Allow auto conversion of Python examples on Windows 3to2 cannot be called as an executable on Windows, but it can be called as a script. Assume that the 3to2 script is installed in PYTHONROOT\Scripts, which is the default for installation by pip. Cherry-pick of trunk r3113. --- SConstruct | 7 ++++++- interfaces/cython/SConscript | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index 6c5e2d5ee..daf25e1ca 100644 --- a/SConstruct +++ b/SConstruct @@ -929,7 +929,12 @@ if env['python_package'] in ('full','default','new'): # See http://pypi.python.org/pypi/3to2 if env['python_package'] == 'new': try: - ret = getCommandOutput('3to2','-l') + 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') + else: + ret = getCommandOutput('3to2', '-l') except OSError: ret = '' if 'print' in ret: diff --git a/interfaces/cython/SConscript b/interfaces/cython/SConscript index e3cf7e28e..c5f96adb1 100644 --- a/interfaces/cython/SConscript +++ b/interfaces/cython/SConscript @@ -213,7 +213,14 @@ if localenv['python_package'] == 'new': if env['python_convert_examples']: def convert_example(target, source, env): shutil.copyfile(source[0].abspath, target[0].abspath) - subprocess.call(['3to2', '--no-diff', '-n', '-w','-x', 'str', + 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', + '-f', 'all', '-f', 'printfunction', '-x', 'print', + '-x', 'open', target[0].abspath]) + else: + subprocess.call(['3to2', '--no-diff', '-n', '-w','-x', 'str', '-f', 'all', '-f', 'printfunction', '-x', 'print', '-x', 'open', target[0].abspath])