o 6a2@sddlZddlZddlZddlmZgdZedZGdddeZ GdddeZ d d Z d d Z Gd ddZ GdddZddZddZddZddZdCddZdCddZiZdCddZedkrSdd lmZddlZeZejd!d"d#d$d%ejd&d'd#d(d%ejd)d*d+d,ejd-d.d#d/d%ejd0d1d2d,ejd3d4d#d2d%ejd5d6d7d,eej\ZZ e!e d8kre"d9ej#red:Z$e$D]Z%ee%Z&e'd;e&j(e&j(e&j)fqe d<Z*ej+,d=Z-e-ree*d>d?e-gZ&nee*d>d?gZ&ej.rej.Z.nd@Z.ej/r&e0dAej/Z1e1se"dBe12d<Z(e12d8Z3e3e&j4e(<ej5r1e'e&5e.ej6reZdZdZdddZddZddd Zdd d Zd d ZdS)ra$ Object containing build information about a library. Parameters ---------- name : str The library name. description : str Description of the library. version : str Version string. sections : dict The sections of the configuration file for the library. The keys are the section headers, the values the text under each header. vars : class instance A `VariableSet` instance, which contains ``(name, value)`` pairs for variables defined in the configuration file for the library. requires : sequence, optional The required libraries for the library to be installed. Notes ----- All input parameters (except "sections" which is a method) are available as attributes of the same name. NcCs4||_||_|r ||_ng|_||_||_||_dSr )name descriptionrequiresversion _sectionsvars)rr2r3r5sectionsr7r4rrrrgs zLibraryInfo.__init__cCt|jS)z Return the section headers of the config file. Parameters ---------- None Returns ------- keys : list of str The list of section headers. )listr6keysrrrrr8rzLibraryInfo.sectionsdefaultcC|j|j|d}t|S)Ncflagsr7 interpolater6r1rsectionr0rrrr?zLibraryInfo.cflagscCr>)Nlibsr@rBrrrrErDzLibraryInfo.libscCsVd|jd|jg}|jr|dn |dd|j|d|jd|S)NzName: %szDescription: %sz Requires:z Requires: %s,z Version: %s )r2r3r4r(joinr5)rmrrrrs   zLibraryInfo.__str__r )r=) rrrrrr8r?rErrrrrrLs    rc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)ra Container object for the variables defined in a config file. `VariableSet` can be used as a plain dictionary, with the variable names as keys. Parameters ---------- d : dict Dict of items in the "variables" section of the configuration file. cCs0tdd|D|_i|_i|_|dS)NcSsg|]\}}||fqSrr).0kvrrr z(VariableSet.__init__..)dictitems _raw_data_re_re_sub _init_parse)rr+rrrrs zVariableSet.__init__cCs$|jD] \}}|||qdSr )rQrP_init_parse_var)rrKrLrrrrTszVariableSet._init_parsecCs"td||j|<||j|<dS)Nz\$\{%s\})recompilerRrSrr2valuerrrrUszVariableSet._init_parse_varcs>fdd}t|r||}||kr |S|}t|s |S)Ncs,jD]}j|j||}q|Sr )rRr;subrS)rYrKrrr _interpolatesz-VariableSet.interpolate.._interpolate)_VARsearch)rrYr[nvaluerrrrAs   zVariableSet.interpolatecCr9)z Return the list of variable names. Parameters ---------- None Returns ------- names : list of str The names of all variables in the `VariableSet` instance. )r:rQr;rrrr variablesr<zVariableSet.variablescCs |j|Sr )rQ)rr2rrr __getitem__rzVariableSet.__getitem__cCs||j|<|||dSr )rQrUrXrrr __setitem__s zVariableSet.__setitem__N) rrrrrrTrUrAr_r`rarrrrrs  rcCsR|ds tdt|d}dD] }||vrtd|qd|vr'g|d<|S)NmetazNo meta section found !)r2r3r5z6Option %s (section [meta]) is mandatory, but not foundr4) has_sectionrrOrP)configr+rKrrr parse_metas recCs:|ds tdi}|dD]\}}|||<qt|S)Nr_zNo variables section found !)rcrrPr)rdr+r2rYrrrparse_variabless  rfcCsttfSr )meta_dr)rdrrrparse_sectionsricCsd|S)Nz%s.inir)pkg_namerrrpkg_to_filenamerjrlcs|r fdd|D}ng}t}||}t|dks%tdt|t|}i}|dr@|dD] \}}t|||<q5dd| D} i} i} | D]$} i} | | dra| | d| | <|| D]\}}|| |<qf| | | <qO||| | fS)Ncsg|] }tj|qSr)ospathrH)rJr+filenamerrrMsz parse_config..zCould not find file(s) %sr_cSsg|]}|dvr|qS))rbr_r)rJsrrrrMrNr4) rreadr&rstrrercrPr1r8 has_optionget)rpdirs filenamesrdnrbr7r2rYsecsr8r4rrr+rror parse_configs.       r{csfdd|\}}}}d|vr:d|vr:|d}|tjvr*td||dftj|}ttj|j|d<t|d|d|d|t |d S) Ncst|\}}}}|D]8\}}t|\}}} } |D] \} } | |vr+| || <q| |D]\} }|rD||| d|7<q2q ||||fS)Nz %s)r{rPrl)frbr7r8reqsrnamervaluenmetanvars nsectionsnreqsrKrLonameovalue _read_configrwrrrs z&_read_config_imp.._read_configpkgdirpkgnamez-You should import %s to get information on %sr2r3r5)r2r3r5r8r7) sysmodules ValueErrorr1rmrndirname__file__rr)rxrwrbr7r8r}rmodrrr_read_config_imps   rcCs8zt|WStytt||}|t|<|YSw)a Return library info for a package from its configuration file. Parameters ---------- pkgname : str Name of the package (should match the name of the .ini file, without the extension, e.g. foo for the file foo.ini). dirs : sequence, optional If given, should be a sequence of directories - usually including the NumPy base directory - where to look for npy-pkg-config files. Returns ------- pkginfo : class instance The `LibraryInfo` instance containing the build information. Raises ------ PkgNotFound If the package is not found. See Also -------- misc_util.get_info, misc_util.get_pkg_info Examples -------- >>> npymath_info = np.distutils.npy_pkg_config.read_config('npymath') >>> type(npymath_info) >>> print(npymath_info) Name: npymath Description: Portable, core math library implementing C99 standard Requires: Version: 0.1 #random )_CACHEKeyErrorrrl)rrwrLrrrrFs'  r__main__) OptionParserz--cflagsr? store_truez*output all preprocessor and compiler flags)destactionhelpz--libsrEzoutput all linker flagsz --use-sectionrCz/use this section instead of default for options)rrz --versionr5zoutput versionz--atleast-version min_versionzMinimal versionz --list-alllist_allz--define-variabledefine_variablez%Replace variable with the given valuer$z(Expect package name on the command line:z*.iniz %s %s - %srqNPY_PKG_CONFIG_PATHznumpy/core/lib/npy-pkg-config.r=z([\S]+)=([\S]+)zH--define-variable option should be of the form --define-variable=foo=barr )9rrVrm configparserr__all__rWr\IOErrorrrrr1rrrerfrirlr{rrrroptparserglobparser add_option parse_argsargvoptionsargsr&rrfilesr|infoprintr2r3rkenvironrvr+rCrr]rIgrouprYr7r?rEr5rrrrrs   *HD   $(  3            ;