<s> import os <EOL> import os . path as osp <EOL> import textwrap <EOL> import subprocess <EOL> try : <EOL> subprocess . check_output <EOL> except AttributeError : <EOL> def check_output ( * popenargs , ** kwargs ) : <EOL> r"""<STR_LIT>""" <EOL> if '<STR_LIT>' in kwargs : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> process = subprocess . Popen ( stdout = subprocess . PIPE , * popenargs , ** kwargs ) <EOL> output , unused_err = process . communicate ( ) <EOL> retcode = process . poll ( ) <EOL> if retcode : <EOL> cmd = kwargs . get ( "<STR_LIT:args>" ) <EOL> if cmd is None : <EOL> cmd = popenargs [ <NUM_LIT:0> ] <EOL> raise subprocess . CalledProcessError ( retcode , cmd , output = output ) <EOL> return output <EOL> subprocess . check_output = check_output <EOL> pass <EOL> import waflib . Utils <EOL> import waflib . Logs as msg <EOL> from waflib . Configure import conf <EOL> _heptooldir = osp . dirname ( osp . abspath ( __file__ ) ) <EOL> def options ( ctx ) : <EOL> ctx . load ( '<STR_LIT>' , tooldir = _heptooldir ) <EOL> ctx . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = "<STR_LIT>" ) <EOL> return <EOL> def configure ( ctx ) : <EOL> ctx . load ( '<STR_LIT>' , tooldir = _heptooldir ) <EOL> return <EOL> @ conf <EOL> def find_python ( ctx , ** kwargs ) : <EOL> ctx . load ( '<STR_LIT>' , tooldir = _heptooldir ) <EOL> if ctx . env . HWAF_FOUND_PYTHON and not kwargs . get ( '<STR_LIT>' , False ) : <EOL> return <EOL> if not ctx . env . HWAF_FOUND_C_COMPILER : <EOL> ctx . fatal ( '<STR_LIT>' ) <EOL> pass <EOL> if not ctx . env . HWAF_FOUND_CXX_COMPILER : <EOL> ctx . fatal ( '<STR_LIT>' ) <EOL> pass <EOL> pyversion = kwargs . get ( "<STR_LIT:version>" , None ) <EOL> path_list = waflib . Utils . to_list ( kwargs . get ( '<STR_LIT>' , [ ] ) ) <EOL> if getattr ( ctx . options , '<STR_LIT>' , None ) : <EOL> topdir = ctx . options . with_python <EOL> topdir = ctx . hwaf_subst_vars ( topdir ) <EOL> path_list . append ( osp . join ( topdir , "<STR_LIT>" ) ) <EOL> pass <EOL> kwargs [ '<STR_LIT>' ] = path_list <EOL> ctx . find_program ( '<STR_LIT>' , var = '<STR_LIT>' , ** kwargs ) <EOL> ctx . hwaf_declare_runtime_env ( '<STR_LIT>' ) <EOL> try : <EOL> ctx . check_cxx ( <EOL> msg = "<STR_LIT>" , <EOL> okmsg = "<STR_LIT>" , <EOL> features = "<STR_LIT>" , <EOL> fragment = textwrap . dedent ( <EOL> '''<STR_LIT>''' ) , <EOL> mandatory = True , <EOL> ) <EOL> except waflib . Errors . ConfigurationError : <EOL> ctx . env . append_unique ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , ] ) <EOL> pass <EOL> ctx . load ( '<STR_LIT>' ) <EOL> if pyversion : <EOL> ctx . check_python_version ( pyversion ) <EOL> save_flags = { } <EOL> for n in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> save_flags [ n ] = ctx . env [ n ] [ : ] <EOL> if ctx . is_darwin ( ) : <EOL> for n in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> ctx . env [ n ] = [ ] <EOL> for v in save_flags [ n ] : <EOL> if v not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> ctx . env . append_unique ( n , [ v ] ) <EOL> pass <EOL> ctx . check_python_headers ( ) <EOL> for n in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> ctx . env [ n ] = save_flags [ n ] [ : ] <EOL> pass <EOL> pylibdir = ctx . env [ '<STR_LIT>' ] <EOL> cmd = ctx . hwaf_subst_vars ( '<STR_LIT>' ) <EOL> for arg in [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] : <EOL> o = subprocess . check_output ( <EOL> [ cmd , arg [ <NUM_LIT:0> ] ] <EOL> ) <EOL> o = str ( o ) <EOL> ctx . parse_flags ( o , '<STR_LIT>' ) <EOL> pylibdir = waflib . Utils . to_list ( ctx . env [ '<STR_LIT>' ] ) [ : ] <EOL> ctx . copy_uselib_defs ( dst = '<STR_LIT>' , src = '<STR_LIT>' ) <EOL> defines = [ x for x in ctx . env [ "<STR_LIT>" ] <EOL> if not ( x . startswith ( "<STR_LIT>" ) or <EOL> x . startswith ( "<STR_LIT>" ) ) ] <EOL> ctx . env [ "<STR_LIT>" ] = defines <EOL> ctx . env [ "<STR_LIT>" ] = [ <EOL> k for k in ctx . env [ "<STR_LIT>" ] <EOL> if not ( x in ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> ] <EOL> for py in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> for k in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> ctx . env . append_unique ( "<STR_LIT>" % py , "<STR_LIT>" % ( k , ctx . env . get_flat ( k ) ) ) <EOL> pass <EOL> pass <EOL> if pylibdir and ( osp . exists ( osp . join ( pylibdir [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' % ctx . env [ '<STR_LIT>' ] ) ) <EOL> or <EOL> osp . exists ( osp . join ( pylibdir [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' % ctx . env [ '<STR_LIT>' ] ) ) ) : <EOL> ctx . env [ '<STR_LIT>' ] = pylibdir [ : ] <EOL> else : <EOL> pass <EOL> if ctx . is_darwin ( ) : <EOL> for n in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> args = [ ] <EOL> indices = [ ] <EOL> for i , a in enumerate ( ctx . env [ '<STR_LIT>' % n ] ) : <EOL> if a == '<STR_LIT>' : <EOL> indices . append ( i ) <EOL> indices . append ( i + <NUM_LIT:1> ) <EOL> args = [ a for i , a in enumerate ( ctx . env [ '<STR_LIT>' % n ] ) <EOL> if not ( i in indices ) ] <EOL> ctx . env [ '<STR_LIT>' % n ] = args [ : ] <EOL> arch_flag = [ ] <EOL> if ctx . is_darwin ( ) : <EOL> if ctx . is_32b ( ) : arch_flag = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : arch_flag = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> elif ctx . is_linux ( ) : <EOL> if ctx . is_32b ( ) : arch_flag = [ '<STR_LIT>' , ] <EOL> else : arch_flag = [ '<STR_LIT>' , ] <EOL> elif ctx . is_freebsd ( ) : <EOL> if ctx . is_32b ( ) : arch_flag = [ '<STR_LIT>' , ] <EOL> else : arch_flag = [ '<STR_LIT>' , ] <EOL> else : <EOL> pass <EOL> for n in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> ctx . env . append_unique ( '<STR_LIT>' % n , arch_flag ) <EOL> ctx . env [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> cmd = [ ctx . env . PYTHON_CONFIG , "<STR_LIT>" ] <EOL> lines = ctx . cmd_and_log ( cmd ) . split ( ) <EOL> ctx . env [ "<STR_LIT>" ] = lines [ <NUM_LIT:0> ] <EOL> ctx . env [ "<STR_LIT>" ] = [ l . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> for l in ctx . env [ "<STR_LIT>" ] ] <EOL> import sys <EOL> fname = sys . modules [ '<STR_LIT>' ] . __file__ <EOL> if fname . endswith ( '<STR_LIT>' ) : fname = fname [ : - <NUM_LIT:1> ] <EOL> ctx . hwaf_export_module ( ctx . root . find_node ( fname ) . abspath ( ) ) <EOL> ctx . env . HWAF_FOUND_PYTHON = <NUM_LIT:1> <EOL> return <EOL> @ conf <EOL> def find_python_module ( ctx , module_name , condition = '<STR_LIT>' , ** kwargs ) : <EOL> ctx . load ( '<STR_LIT>' , tooldir = _heptooldir ) <EOL> if not ctx . env . CXX and not ctx . env . CC : <EOL> msg . fatal ( '<STR_LIT>' ) <EOL> pass <EOL> if not ctx . env . HWAF_FOUND_PYTHON : <EOL> ctx . find_python ( ) <EOL> pass <EOL> found = False <EOL> os_env = dict ( os . environ ) <EOL> try : <EOL> ctx . env . stash ( ) <EOL> env = ctx . _get_env_for_subproc ( ) <EOL> for k , v in env . items ( ) : <EOL> os . environ [ k ] = v <EOL> pass <EOL> ctx . check_python_module ( module_name , condition ) <EOL> found = True <EOL> except ctx . errors . ConfigurationError : <EOL> os . environ = os_env <EOL> ctx . env . revert ( ) <EOL> found = False <EOL> pass <EOL> finally : <EOL> os . environ = os_env <EOL> pass <EOL> if not found and kwargs . get ( '<STR_LIT>' , True ) : <EOL> ctx . fatal ( "<STR_LIT>" % module_name ) <EOL> return </s>
