<s> from __future__ import print_function , absolute_import <EOL> import os <EOL> import sys <EOL> import imp <EOL> import json <EOL> import string <EOL> import shutil <EOL> import subprocess <EOL> import tempfile <EOL> from distutils . dep_util import newer_group <EOL> from distutils . core import Extension <EOL> from distutils . errors import DistutilsExecError <EOL> from distutils . ccompiler import new_compiler <EOL> from distutils . sysconfig import customize_compiler , get_config_vars <EOL> from distutils . command . build_ext import build_ext as _build_ext <EOL> def check_dependencies ( dependencies ) : <EOL> def module_exists ( dep ) : <EOL> try : <EOL> imp . find_module ( dep ) <EOL> return True <EOL> except ImportError : <EOL> return False <EOL> for dep in dependencies : <EOL> if len ( dep ) == <NUM_LIT:1> : <EOL> import_name , pkg_name = dep [ <NUM_LIT:0> ] , dep [ <NUM_LIT:0> ] <EOL> elif len ( dep ) == <NUM_LIT:2> : <EOL> import_name , pkg_name = dep <EOL> else : <EOL> raise ValueError ( dep ) <EOL> if not module_exists ( import_name ) : <EOL> lines = [ <EOL> '<STR_LIT:->' * <NUM_LIT:50> , <EOL> '<STR_LIT>' % import_name , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % pkg_name , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % pkg_name , <EOL> '<STR_LIT:->' * <NUM_LIT:50> , <EOL> ] <EOL> print ( os . linesep . join ( lines ) , file = sys . stderr ) <EOL> class CompilerDetection ( object ) : <EOL> _DONT_REMOVE_ME = get_config_vars ( ) <EOL> def __init__ ( self , disable_openmp ) : <EOL> cc = new_compiler ( ) <EOL> customize_compiler ( cc ) <EOL> self . msvc = cc . compiler_type == '<STR_LIT>' <EOL> self . _print_compiler_version ( cc ) <EOL> if disable_openmp : <EOL> self . openmp_enabled = False <EOL> else : <EOL> self . openmp_enabled , openmp_needs_gomp = self . _detect_openmp ( ) <EOL> self . sse3_enabled = self . _detect_sse3 ( ) if not self . msvc else True <EOL> self . sse41_enabled = self . _detect_sse41 ( ) if not self . msvc else True <EOL> self . compiler_args_sse2 = [ '<STR_LIT>' ] if not self . msvc else [ '<STR_LIT>' ] <EOL> self . compiler_args_sse3 = [ '<STR_LIT>' ] if ( self . sse3_enabled and not self . msvc ) else [ ] <EOL> self . compiler_args_sse41 , self . define_macros_sse41 = [ ] , [ ] <EOL> if self . sse41_enabled : <EOL> self . define_macros_sse41 = [ ( '<STR_LIT>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , <NUM_LIT:1> ) ] <EOL> if not self . msvc : <EOL> self . compiler_args_sse41 = [ '<STR_LIT>' ] <EOL> if self . openmp_enabled : <EOL> self . compiler_libraries_openmp = [ ] <EOL> if self . msvc : <EOL> self . compiler_args_openmp = [ '<STR_LIT>' ] <EOL> else : <EOL> self . compiler_args_openmp = [ '<STR_LIT>' ] <EOL> if openmp_needs_gomp : <EOL> self . compiler_libraries_openmp = [ '<STR_LIT>' ] <EOL> else : <EOL> self . compiler_libraries_openmp = [ ] <EOL> self . compiler_args_openmp = [ ] <EOL> if self . msvc : <EOL> self . compiler_args_opt = [ '<STR_LIT>' ] <EOL> else : <EOL> self . compiler_args_opt = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> print ( ) <EOL> def _print_compiler_version ( self , cc ) : <EOL> print ( "<STR_LIT>" ) <EOL> try : <EOL> if self . msvc : <EOL> if not cc . initialized : <EOL> cc . initialize ( ) <EOL> cc . spawn ( [ cc . cc ] ) <EOL> else : <EOL> cc . spawn ( [ cc . compiler [ <NUM_LIT:0> ] ] + [ '<STR_LIT>' ] ) <EOL> except DistutilsExecError : <EOL> pass <EOL> def hasfunction ( self , funcname , include = None , libraries = None , extra_postargs = None ) : <EOL> part1 = '''<STR_LIT>''' % { <EOL> '<STR_LIT>' : json . dumps ( funcname ) , <EOL> '<STR_LIT>' : json . dumps ( include ) , <EOL> '<STR_LIT>' : json . dumps ( libraries or [ ] ) , <EOL> '<STR_LIT>' : json . dumps ( extra_postargs ) } <EOL> part2 = '''<STR_LIT>''' <EOL> tmpdir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> try : <EOL> curdir = os . path . abspath ( os . curdir ) <EOL> os . chdir ( tmpdir ) <EOL> with open ( '<STR_LIT>' , '<STR_LIT:w>' ) as f : <EOL> f . write ( part1 + part2 ) <EOL> proc = subprocess . Popen ( <EOL> [ sys . executable , '<STR_LIT>' ] , <EOL> stderr = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> proc . communicate ( ) <EOL> status = proc . wait ( ) <EOL> finally : <EOL> os . chdir ( curdir ) <EOL> shutil . rmtree ( tmpdir ) <EOL> return status == <NUM_LIT:0> <EOL> def _print_support_start ( self , feature ) : <EOL> print ( '<STR_LIT>' . format ( feature ) , end = '<STR_LIT:U+0020>' ) <EOL> def _print_support_end ( self , feature , status ) : <EOL> if status is True : <EOL> print ( '<STR_LIT>' . format ( feature ) ) <EOL> else : <EOL> print ( '<STR_LIT>' . format ( feature ) ) <EOL> def _detect_openmp ( self ) : <EOL> self . _print_support_start ( '<STR_LIT>' ) <EOL> hasopenmp = self . hasfunction ( '<STR_LIT>' , extra_postargs = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> needs_gomp = hasopenmp <EOL> if not hasopenmp : <EOL> hasopenmp = self . hasfunction ( '<STR_LIT>' , libraries = [ '<STR_LIT>' ] ) <EOL> needs_gomp = hasopenmp <EOL> self . _print_support_end ( '<STR_LIT>' , hasopenmp ) <EOL> return hasopenmp , needs_gomp <EOL> def _detect_sse3 ( self ) : <EOL> "<STR_LIT>" <EOL> self . _print_support_start ( '<STR_LIT>' ) <EOL> result = self . hasfunction ( '<STR_LIT>' , <EOL> include = '<STR_LIT>' , <EOL> extra_postargs = [ '<STR_LIT>' ] ) <EOL> self . _print_support_end ( '<STR_LIT>' , result ) <EOL> return result <EOL> def _detect_sse41 ( self ) : <EOL> "<STR_LIT>" <EOL> self . _print_support_start ( '<STR_LIT>' ) <EOL> result = self . hasfunction ( '<STR_LIT>' , <EOL> include = '<STR_LIT>' , <EOL> extra_postargs = [ '<STR_LIT>' ] ) <EOL> self . _print_support_end ( '<STR_LIT>' , result ) <EOL> return result <EOL> def git_version ( ) : <EOL> def _minimal_ext_cmd ( cmd ) : <EOL> env = { } <EOL> for k in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> v = os . environ . get ( k ) <EOL> if v is not None : <EOL> env [ k ] = v <EOL> env [ '<STR_LIT>' ] = '<STR_LIT:C>' <EOL> env [ '<STR_LIT>' ] = '<STR_LIT:C>' <EOL> env [ '<STR_LIT>' ] = '<STR_LIT:C>' <EOL> out = subprocess . Popen ( <EOL> cmd , stdout = subprocess . PIPE , env = env ) . communicate ( ) [ <NUM_LIT:0> ] <EOL> return out <EOL> try : <EOL> out = _minimal_ext_cmd ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> GIT_REVISION = out . strip ( ) . decode ( '<STR_LIT:ascii>' ) <EOL> except OSError : <EOL> GIT_REVISION = '<STR_LIT>' <EOL> return GIT_REVISION <EOL> def write_version_py ( version , isreleased , filename ) : <EOL> cnt = """<STR_LIT>""" <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> git_revision = git_version ( ) <EOL> else : <EOL> git_revision = '<STR_LIT>' <EOL> if isreleased : <EOL> full_version = version <EOL> short_version = version <EOL> else : <EOL> full_version = ( "<STR_LIT>" <EOL> . format ( version = version , git_revision = git_revision ) ) <EOL> short_version = version <EOL> with open ( filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( cnt . format ( version = version , <EOL> short_version = short_version , <EOL> full_version = full_version , <EOL> git_revision = git_revision , <EOL> release = isreleased ) ) <EOL> class StaticLibrary ( Extension ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . export_include = kwargs . pop ( '<STR_LIT>' , [ ] ) <EOL> Extension . __init__ ( self , * args , ** kwargs ) <EOL> class build_ext ( _build_ext ) : <EOL> def build_extension ( self , ext ) : <EOL> if isinstance ( ext , StaticLibrary ) : <EOL> self . build_static_extension ( ext ) <EOL> else : <EOL> _build_ext . build_extension ( self , ext ) <EOL> def build_static_extension ( self , ext ) : <EOL> from distutils import log <EOL> sources = ext . sources <EOL> if sources is None or not isinstance ( sources , ( list , tuple ) ) : <EOL> raise DistutilsSetupError ( <EOL> ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) % ext . name ) <EOL> sources = list ( sources ) <EOL> ext_path = self . get_ext_fullpath ( ext . name ) <EOL> depends = sources + ext . depends <EOL> if not ( self . force or newer_group ( depends , ext_path , '<STR_LIT>' ) ) : <EOL> log . debug ( "<STR_LIT>" , ext . name ) <EOL> return <EOL> else : <EOL> log . info ( "<STR_LIT>" , ext . name ) <EOL> extra_args = ext . extra_compile_args or [ ] <EOL> macros = ext . define_macros [ : ] <EOL> for undef in ext . undef_macros : <EOL> macros . append ( ( undef , ) ) <EOL> objects = self . compiler . compile ( sources , <EOL> output_dir = self . build_temp , <EOL> macros = macros , <EOL> include_dirs = ext . include_dirs , <EOL> debug = self . debug , <EOL> extra_postargs = extra_args , <EOL> depends = ext . depends ) <EOL> self . _built_objects = objects [ : ] <EOL> if ext . extra_objects : <EOL> objects . extend ( ext . extra_objects ) <EOL> extra_args = ext . extra_link_args or [ ] <EOL> language = ext . language or self . compiler . detect_language ( sources ) <EOL> libname = os . path . splitext ( os . path . basename ( ext_path ) ) [ <NUM_LIT:0> ] <EOL> output_dir = os . path . dirname ( ext_path ) <EOL> if ( self . compiler . static_lib_format . startswith ( '<STR_LIT>' ) and <EOL> libname . startswith ( '<STR_LIT>' ) ) : <EOL> libname = libname [ <NUM_LIT:3> : ] <EOL> if not os . path . exists ( output_dir ) : <EOL> os . makedirs ( output_dir ) <EOL> self . compiler . create_static_lib ( objects , <EOL> output_libname = libname , <EOL> output_dir = output_dir , <EOL> target_lang = language ) <EOL> for item in ext . export_include : <EOL> shutil . copy ( item , output_dir ) </s>
