<s> import os <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import ntpath <EOL> import posixpath <EOL> import os . path as op <EOL> from six import BytesIO <EOL> from subprocess import PIPE , STDOUT , Popen <EOL> from bento . utils . utils import pprint <EOL> distutils_code = """<STR_LIT>""" <EOL> setuptools_code = """<STR_LIT>""" <EOL> numpy_code = """<STR_LIT>""" <EOL> setuptools_numpy_code = """<STR_LIT>""" <EOL> can_run_code = """<STR_LIT>""" <EOL> def logged_run ( cmd , buffer ) : <EOL> """<STR_LIT>""" <EOL> pid = Popen ( cmd , stdout = PIPE , stderr = STDOUT ) <EOL> pid . wait ( ) <EOL> buffer . write ( pid . stdout . read ( ) ) <EOL> return pid . returncode <EOL> def _test ( code , setup_py , show_output , log ) : <EOL> d = tempfile . mkdtemp ( ) <EOL> try : <EOL> filename = op . join ( d , "<STR_LIT>" ) <EOL> cmd = [ sys . executable , filename ] <EOL> log . write ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( cmd ) ) <EOL> log . writelines ( [ "<STR_LIT>" % line for line in code . splitlines ( ) ] ) <EOL> fp = open ( filename , "<STR_LIT>" ) <EOL> try : <EOL> fp . write ( code ) <EOL> finally : <EOL> fp . close ( ) <EOL> buf = BytesIO ( ) <EOL> st = logged_run ( cmd , buf ) <EOL> log . write ( "<STR_LIT>" % st ) <EOL> val = buf . getvalue ( ) <EOL> if val : <EOL> log . writelines ( [ "<STR_LIT>" % line for line in val . splitlines ( ) ] ) <EOL> log . write ( "<STR_LIT:\n>" ) <EOL> else : <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT:\n>" ) <EOL> return st == <NUM_LIT:0> <EOL> finally : <EOL> shutil . rmtree ( d ) <EOL> def test_distutils ( setup_py , show_output , log ) : <EOL> odir = os . path . dirname ( os . path . abspath ( setup_py ) ) <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT>" ) <EOL> return _test ( distutils_code % { "<STR_LIT:filename>" : setup_py , "<STR_LIT>" : odir } , setup_py , <EOL> show_output , log ) <EOL> def test_setuptools ( setup_py , show_output , log ) : <EOL> odir = os . path . dirname ( os . path . abspath ( setup_py ) ) <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT>" ) <EOL> return _test ( setuptools_code % { "<STR_LIT:filename>" : setup_py , "<STR_LIT>" : odir } , setup_py , <EOL> show_output , log ) <EOL> def test_numpy ( setup_py , show_output , log ) : <EOL> odir = os . path . dirname ( os . path . abspath ( setup_py ) ) <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT>" ) <EOL> return _test ( numpy_code % { "<STR_LIT:filename>" : setup_py , "<STR_LIT>" : odir } , setup_py , <EOL> show_output , log ) <EOL> def test_setuptools_numpy ( setup_py , show_output , log ) : <EOL> odir = os . path . dirname ( os . path . abspath ( setup_py ) ) <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT>" ) <EOL> return _test ( setuptools_numpy_code % { "<STR_LIT:filename>" : setup_py , "<STR_LIT>" : odir } , setup_py , <EOL> show_output , log ) <EOL> def test_can_run ( setup_py , show_output , log ) : <EOL> odir = os . path . dirname ( os . path . abspath ( setup_py ) ) <EOL> log . write ( "<STR_LIT>" ) <EOL> log . write ( "<STR_LIT>" ) <EOL> return _test ( can_run_code % { "<STR_LIT:filename>" : setup_py , "<STR_LIT>" : odir } , setup_py , <EOL> show_output , log ) <EOL> def whole_test ( setup_py , verbose , log ) : <EOL> if verbose : <EOL> show_output = True <EOL> else : <EOL> show_output = False <EOL> if not test_can_run ( setup_py , show_output , log ) : <EOL> pass <EOL> if verbose : <EOL> pprint ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> use_distutils = test_distutils ( setup_py , show_output , log ) <EOL> if verbose : <EOL> pprint ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> use_setuptools = test_setuptools ( setup_py , show_output , log ) <EOL> if verbose : <EOL> pprint ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> use_numpy = test_numpy ( setup_py , show_output , log ) <EOL> if verbose : <EOL> pprint ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> use_setuptools_numpy = test_setuptools_numpy ( setup_py , show_output , log ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" % use_distutils ) <EOL> print ( "<STR_LIT>" % use_setuptools ) <EOL> print ( "<STR_LIT>" % use_numpy ) <EOL> print ( "<STR_LIT>" % use_setuptools_numpy ) <EOL> if use_distutils and not ( use_setuptools or use_numpy or use_setuptools_numpy ) : <EOL> return "<STR_LIT>" <EOL> elif use_setuptools and not ( use_numpy or use_setuptools_numpy ) : <EOL> return "<STR_LIT>" <EOL> elif use_numpy and not use_setuptools_numpy : <EOL> return "<STR_LIT>" <EOL> elif use_setuptools_numpy : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def canonalize_path ( path ) : <EOL> """<STR_LIT>""" <EOL> head , tail = ntpath . split ( path ) <EOL> lst = [ tail ] <EOL> while head and tail : <EOL> head , tail = ntpath . split ( head ) <EOL> lst . insert ( <NUM_LIT:0> , tail ) <EOL> lst . insert ( <NUM_LIT:0> , head ) <EOL> return posixpath . join ( * lst ) </s>
