B { `j@sddlZddlZddlZddlZddlZddlZddlmZddlmZddl m Z m Z m Z m Z mZddlmZmZmZmZmZddlmZddlmZddlmZdd lmZmZdd lmZm Z m!Z!m"Z"m#Z#y ddl$Z$Wne%k rddl&Z$YnXda'e$(Z)e*Z+d d Z,d dZ-ddZ.e-ede.dKddZ/e-ede/dLddZ0e-ede0dMddZ1e-ede1dNddZ2e-ede2d d!Z3d"d#Z4e-ed$e4dOd%d&Z5e-ed'e5dPd)d*Z6d+dgfd,d-Z7e-ed.e7d/d0Z8e-ed1e8d2e d3<d4e d5<d6e d7<d8e d9<d:e d;<d7_9ej:d?krdd@e dA<e!rde;dBdCej9e_9e Zej?@dIe>dJZAeAdk reBeAdGe qWdS)RN)copy) ccompiler)compiler_classgen_lib_optionsget_default_compiler new_compiler CCompiler)DistutilsExecErrorDistutilsModuleErrorDistutilsPlatformError CompileErrorUnknownFileError)customize_compiler) LooseVersion)log)filepath_from_subprocess_outputforward_bytes_to_stdout) cyg2win32 is_sequencemingw32get_num_build_jobs_commandline_dep_stringc Cs|d}tj|sdSt|d}|}WdQRXt|||}|d}||krVdSd|dd} ddtj| dd D} y2t |j } x | D]}t |j | krdSqWWnt k rdSXd S) z Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool z.dTrNcSs"g|]}|dkr|ds|qS) :)endswith).0xr =/tmp/pip-unpacked-wheel-4iou4664/numpy/distutils/ccompiler.py Fsz _needs_build..)posixF) ospathexistsopen readlinesrjoinshlexsplitstatst_mtimeOSError) objcc_argsextra_postargspp_optsZdep_fileflinesZcmdlineZ last_cmdlinecontentsdepsZt_objr r r! _needs_build&s&      r7csfdd}t|||dS)Ncs|f||S)Nr )selfargskw)funcr r!Zz replace_method..)setattr)klass method_namer;mr )r;r!replace_methodXs rBcCsdS)z Does nothing here, but is called by the get_version method and can be overridden by subclasses. In particular it is redefined in the `FCompiler` class where more documentation can be found. Nr )r8r r r!CCompiler_find_executablescsrCfind_executablesc Cs|dkr"|}t|r"dt|}t|y&|jr@t|ntj|tjdWnJtj k r}z|j }|j }Wdd}~XYn t k rd}d}YnXdSt|rdt|}|jrt |td|rd}nd}td |||fdS) a Execute a command in a sub-process. Parameters ---------- cmd : str The command to execute. display : str or sequence of str, optional The text to add to the log file kept by `numpy.distutils`. If not given, `display` is equal to `cmd`. Returns ------- None Raises ------ DistutilsExecError If the command failed, i.e. the exit status was not 0. N )stderrr=sToo many open filesz2 Try rerunning setup command until build succeeds.rz)Command "%s" failed with exit status %d%s)rr)listrinfoverbose subprocess check_outputSTDOUTCalledProcessErroroutput returncoder.rresearchr )r8cmddisplayexcosmsgr r r!CCompiler_spawnqs2    rYspawnrc Cs|dkr d}g}x|D]}tjtj|\}}tj|d}|tj|d}|dr|dd}|d|} tjtj | } | ||d}||j krt d||f|rtj|}tj |||j } || qW|S)a Return the name of the object files for the given source files. Parameters ---------- source_filenames : list of str The list of paths to source files. Paths can be either relative or absolute, this is handled transparently. strip_dir : bool, optional Whether to strip the directory from the returned paths. If True, the file name prepended by `output_dir` is returned. Default is False. output_dir : str, optional If given, this path is prepended to the returned paths to the object files. Returns ------- obj_names : list of str The list of paths to the object files corresponding to the source files in `source_filenames`. Nrz..z"unknown file type '%s' (from '%s'))r$r%splitextnormpath splitdriveisabs startswithrfindbasenameabspathZsrc_extensionsr r)Z obj_extensionappend) r8Zsource_filenamesZ strip_dir output_dirZ obj_namessrc_namebaseextidZobj_namer r r!CCompiler_object_filenamess&     rlZobject_filenamesc  sLt} ttdkrt| aWdQRX|s0gSddlm} m} m} t | rg} x.single_compileZabsoftr[)rrpru threading SemaphoreZnumpy.distutils.fcompilerrmrnro isinstancegetattrrer) compiler_sorrIZ_setup_compileZ _get_cc_argsrHkeys compiler_typeritemslenZmultiprocessing.poolpoolZ ThreadPoolmapclose)r8sourcesrfmacros include_dirsdebug extra_preargsr1dependsjobsrmrnrorTZfcZfcompZccompZobjectsbuildryZobjects_to_buildZ f77_objectsZ other_objectsr/rxriZ build_itemsrVmultiprocessingrr )r0r1r2r8r!CCompiler_compilesd+                  rcompiler cstd|jjjjffdd}|dr<|j|drdxjD]\}}|||qLW|drxjD]}| |qtW|dr| |j j |dr| |j j |d r|j|d r|jd S) a Customize compiler using distutils command. Parameters ---------- cmd : class instance An instance inheriting from `distutils.cmd.Command`. ignore : sequence of str, optional List of `CCompiler` commands (without ``'set_'``) that should not be altered. Strings that are checked for are: ``('include_dirs', 'define', 'undef', 'libraries', 'library_dirs', 'rpath', 'link_objects')``. Returns ------- None zcustomize %s using %scst|ddk o|kS)N)r})attr)rSignorer r!allowsz&CCompiler_customize_cmd..allowrdefineundef libraries library_dirsrpath link_objectsN)rrI __class____name__Zset_include_dirsrrZ define_macrorZundefine_macroZ set_librariesrZset_library_dirsrZset_runtime_library_dirsrZset_link_objectsr)r8rSrrnamevaluemacror )rSrr!CCompiler_customize_cmdps&    rZ customize_cmdcsg}d}t|j}xdD]}||kr||qWx@|D]8}t||r.r) rHZ executablesrrehasattrr}maxrreprr))compilerpropsZmxrkeyvr4r )rr!_compiler_to_strings    rcCsXy |Wntk r YnXtjjdkrTtdt|jtt|tddS)z Print the compiler customizations to stdout. Parameters ---------- None Returns ------- None Notes ----- Printing is only done if the distutils log threshold is < 2. r\zP********************************************************************************N) get_version Exceptionr _global_log thresholdprintrr)r8r r r!CCompiler_show_customizations    rZshow_customizationc Cstd|jjt||ry|jdWnttfk rFYnXt |drd|j dkr|j s|j d drd\}}nd\}}|j d ||g|j d d |_ n8t |drtd |j ft |d std |jjt |dr*d|j dks"d|j dks"d|j dkr*d|_ntjdkrdd l}dd l}|}zvyTtj|d}t|d} | dWd QRX|j|g|dd|dgdd|_Wntk rd|_YnXWd ||Xd S)am Do any platform-specific customization of a compiler instance. This method calls `distutils.sysconfig.customize_compiler` for platform-specific customization, as well as optionally remove a flag to suppress spurious warnings in case C++ code is being compiled. Parameters ---------- dist : object This parameter is not used for anything. need_cxx : bool, optional Whether or not C++ has to be compiled. If so (True), the ``"-Wstrict-prototypes"`` option is removed to prevent spurious warnings. Default is False. Returns ------- None Notes ----- All the default options used by distutils can be extracted with:: from distutils import sysconfig sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO') z customize %sz-Wstrict-prototypesrccrgcc)rzg++)rzc++r[Nz#### %s ####### compiler_cxxzMissing compiler_cxx fix for zg++ZclangTr#zfile.cwzint a; z-MMDz-MFz.d)rfrF)rrIrrrr~rwAttributeError ValueErrorrrrrareplacewarnZ _auto_dependsr$rtempfileshutilmkdtempr%r)r'writerr rmtree) r8distZneed_cxxabrrZtmpdirfnr3r r r!CCompiler_customizesJ        rZ customize[-.\d]+csfdd}|S)aU Simple matching of version numbers, for use in CCompiler and FCompiler. Parameters ---------- pat : str, optional A regular expression matching version numbers. Default is ``r'[-.\d]+'``. ignore : str, optional A regular expression matching patterns to skip. Default is ``''``, in which case nothing is skipped. start : str, optional A regular expression matching the start of where to start looking for version numbers. Default is ``''``, in which case searching is started at the beginning of the version string given to `matcher`. Returns ------- matcher : callable A function that is appropriate to use as the ``.version_match`` attribute of a `CCompiler` class. `matcher` takes a single parameter, a version string. cs~|dd}d}r0t|}|s(dS|}xBt||d}|sNdSrnt|drn|}q2Pq2W|dS)NrrEr)rrQmatchendrRgroup)r8version_stringposrA)rpatstartr r!matcher?s   z%simple_version_match..matcherr )rrrrr )rrrr!simple_version_match%srFc s2|st|dr|jS|y |j}Wntk r:dSX|rH|dsLdSy |j}Wn@tk ry |jWntk rdSXfdd}YnXytj|tj d}WnJtj k r}z|j }|j }Wdd}~XYn(t k rd}d}YnXt|}d}d}||kr(||}|r(t|}||_|S) a Return compiler version, or None if compiler is not available. Parameters ---------- force : bool, optional If True, force a new determination of the version, even if the compiler already has a version attribute. Default is False. ok_status : list of int, optional The list of status values returned by the version look-up process for which a version string is returned. If the status value is not in `ok_status`, None is returned. Default is ``[0]``. Returns ------- version : str or None Version string, in the format of `distutils.version.LooseVersion`. rNrcs"t|}|sdS|d}|S)Nr)rQrr)rrAr)rr r!rxs   z&CCompiler_get_version..matcher)rFrGr=)rrrD version_cmdrZ version_matchZversion_patternrKrLrMrNrOrPr.rr) r8forceZ ok_statusrrrOrUstatusrr )rr!CCompiler_get_versionTsD      rrcCs|jdkr|St|}|jdg|jdd|_tjdrrd|jdkrr|jd|jdg|jdd|_n|jdg|jdd|_|S)z Return the C++ compiler. Parameters ---------- None Returns ------- cxx : class instance The C++ compiler, as a `CCompiler` instance. )msvcintelwintelemwrr[NaixZ ld_so_aixr\)rrrr~sysplatformra linker_so)r8cxxr r r!CCompiler_cxx_compilers rZ cxx_compiler)intelccompilerZIntelCCompilerz(Intel C Compiler for 32-bit applicationsintel)rZIntelItaniumCCompilerz7Intel C Itanium Compiler for Itanium-based applicationsintele)rZIntelEM64TCCompilerz(Intel C Compiler for 64-bit applicationsintelem)rZIntelCCompilerWz3Intel C Compiler for 32-bit applications on Windowsr)rZIntelEM64TCCompilerWz3Intel C Compiler for 64-bit applications on Windowsr)Z pathccompilerZPathScaleCCompilerz2PathScale Compiler for SiCortex-based applicationspathcc))zlinux.*r)zlinux.*r)zlinux.*r)zlinux.*r)ntr)rrwin32)Zmingw32ccompilerZMingw32CCompilerz>Mingw32 port of GNU C Compiler for Win32(for MSC built Python)rz+Setting mingw32 as default compiler for nt.))rrc Cs|dkrttjk}|dkr$tj}y"|dkr6t|}t|\}}}Wn8tk r~d|}|dk rr|d|}t|YnXd|}y t |Wnt k r"} znt | }t dt ||dd}y t |Wn8t k r} zt | }t d|Wdd} ~ XYnXWdd} ~ XYnXytj|} t| |} Wn&tk rdt d||fYnX| d||}||_td| |S) Nz5don't know how to compile C/C++ code on platform '%s'z with '%s' compilerznumpy.distutils.z,%s in numpy.distutils; trying from distutilsz4can't compile C/C++ code: unable to load module '%s'zBcan't compile C/C++ code: unable to find class '%s' in module '%s'znew_compiler returns %s)rZ get_thresholdINFOr$rrrKeyErrorr __import__ ImportErrorstrrIr rmodulesvarsrJr) platrrJdry_runr module_name class_namelong_descriptionrXemoduler?r r r!rsJ     ,  rcCsFt||||}g}x.|D]&}t|r4|t|q||qW|S)N)_distutils_gen_lib_optionsrextendrHre)rrruntime_library_dirsrrZlib_optsrjr r r!rs r)Zmsvc9rZ_msvcZbcppZcygwincZemxcZunixcz distutils.r)N)rr)NNNrNNN)r )r)rrr)NNNrr)Cr$rQrr*rsrKr distutilsrdistutils.ccompilerrrrrrdistutils.errorsr r r r r distutils.sysconfigrZdistutils.versionrZnumpy.distutilsrZnumpy.distutils.exec_commandrrZnumpy.distutils.misc_utilrrrrrrzrZdummy_threadingruLockrpsetrqr7rBrCrYrlrrrrrrrrZ_default_compilersrrIZ_distutils_new_compilerrZ_ccrget_mr>r r r r!s      2   ?  -    ) #  Q  /C      (