<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , print_function <EOL> import os <EOL> import sys <EOL> import subprocess <EOL> import distutils <EOL> from distutils . sysconfig import customize_compiler <EOL> from numpy . distutils . ccompiler import new_compiler <EOL> from numpy . distutils . core import setup <EOL> import distutils . bcppcompiler <EOL> def dummy_dist ( ) : <EOL> distutils . core . _setup_stop_after = "<STR_LIT>" <EOL> dist = setup ( name = "<STR_LIT>" ) <EOL> distutils . core . _setup_stop_after = None <EOL> return dist <EOL> def create_compiler_instance ( dist ) : <EOL> opts = dist . command_options . get ( '<STR_LIT>' , None ) <EOL> compiler_name = '<STR_LIT>' <EOL> if opts : <EOL> comp = opts . get ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> compiler_name = comp [ <NUM_LIT:1> ] <EOL> if not compiler_name : <EOL> compiler_name = None <EOL> compiler = new_compiler ( compiler = compiler_name ) <EOL> customize_compiler ( compiler ) <EOL> return compiler <EOL> def compiler_exe_name ( compiler ) : <EOL> exe_name = '<STR_LIT>' <EOL> if hasattr ( compiler , "<STR_LIT>" ) : <EOL> exe_name = compiler . compiler [ <NUM_LIT:0> ] <EOL> elif hasattr ( compiler , "<STR_LIT>" ) : <EOL> exe_name = compiler . cc <EOL> elif compiler . __class__ is distutils . bcppcompiler . BCPPCompiler : <EOL> exe_name = '<STR_LIT>' <EOL> return exe_name <EOL> def compiler_exe_path ( exe_name ) : <EOL> exe_path = None <EOL> if os . path . exists ( exe_name ) : <EOL> exe_path = exe_name <EOL> else : <EOL> path_string = os . environ [ '<STR_LIT>' ] <EOL> path_string = os . path . expandvars ( path_string ) <EOL> path_string = os . path . expanduser ( path_string ) <EOL> paths = path_string . split ( os . pathsep ) <EOL> for path in paths : <EOL> path = os . path . join ( path , exe_name ) <EOL> if os . path . exists ( path ) : <EOL> exe_path = path <EOL> break <EOL> path = path + '<STR_LIT>' <EOL> if os . path . exists ( path ) : <EOL> exe_path = path <EOL> break <EOL> return exe_path <EOL> def check_sum ( file ) : <EOL> from hashlib import sha256 <EOL> try : <EOL> f = open ( file , '<STR_LIT:r>' ) <EOL> bytes = f . read ( - <NUM_LIT:1> ) <EOL> except IOError : <EOL> bytes = '<STR_LIT>' <EOL> chk_sum = sha256 ( bytes ) <EOL> return chk_sum . hexdigest ( ) [ : <NUM_LIT:32> ] <EOL> def get_compiler_dir ( compiler_name ) : <EOL> """<STR_LIT>""" <EOL> compiler_type = choose_compiler ( compiler_name ) <EOL> configure_sys_argv ( compiler_type ) <EOL> dist = dummy_dist ( ) <EOL> compiler_obj = create_compiler_instance ( dist ) <EOL> exe_name = compiler_exe_name ( compiler_obj ) <EOL> exe_path = compiler_exe_path ( exe_name ) <EOL> if not exe_path : <EOL> raise ValueError ( "<STR_LIT>" % compiler_name ) <EOL> chk_sum = check_sum ( exe_path ) <EOL> restore_sys_argv ( ) <EOL> return '<STR_LIT>' + chk_sum <EOL> def choose_compiler ( compiler_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if not compiler_name : <EOL> compiler_name = '<STR_LIT>' <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> if not compiler_name : <EOL> if msvc_exists ( ) : <EOL> compiler_name = '<STR_LIT>' <EOL> elif gcc_exists ( ) : <EOL> compiler_name = '<STR_LIT>' <EOL> elif compiler_name == '<STR_LIT>' : <EOL> compiler_name = '<STR_LIT>' <EOL> else : <EOL> if compiler_name == '<STR_LIT>' : <EOL> compiler_name = '<STR_LIT>' <EOL> return compiler_name <EOL> old_argv = [ ] <EOL> def configure_sys_argv ( compiler_name ) : <EOL> global old_argv <EOL> try : <EOL> old_argv = sys . argv [ : ] <EOL> except AttributeError : <EOL> pass <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' + compiler_name ] <EOL> def restore_sys_argv ( ) : <EOL> sys . argv = old_argv <EOL> def gcc_exists ( name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> result = <NUM_LIT:0> <EOL> cmd = '<STR_LIT>' % name <EOL> try : <EOL> p = subprocess . Popen ( [ str ( name ) , '<STR_LIT>' ] , shell = True , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> str_result = p . stdout . read ( ) <EOL> if '<STR_LIT>' in str_result : <EOL> result = <NUM_LIT:1> <EOL> except : <EOL> result = not os . system ( cmd ) <EOL> return result <EOL> def msvc_exists ( ) : <EOL> """<STR_LIT>""" <EOL> result = <NUM_LIT:0> <EOL> try : <EOL> p = subprocess . Popen ( [ '<STR_LIT>' ] , shell = True , <EOL> stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> str_result = p . stdout . read ( ) <EOL> if '<STR_LIT>' in str_result : <EOL> result = <NUM_LIT:1> <EOL> except : <EOL> import distutils . msvccompiler <EOL> try : <EOL> version = distutils . msvccompiler . get_devstudio_versions ( ) <EOL> except : <EOL> version = distutils . msvccompiler . get_build_version ( ) <EOL> if version : <EOL> result = <NUM_LIT:1> <EOL> return result <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> """<STR_LIT>""" <EOL> path = get_compiler_dir ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , path ) <EOL> print ( ) <EOL> try : <EOL> path = get_compiler_dir ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , path ) <EOL> except ValueError : <EOL> pass </s>
