a :jg2@sddlZddlZddlZddlmZgdZedZGdddeZ GdddeZ d d Z d d Z Gd ddZ GdddZddZddZddZddZdCddZdDddZiZdEddZedkrdd 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/rVe0dAej/Z1e1s8e"dBne12d<Z(e12d8Z3e3e&j4e(<ej5rle'e&5e.ej6re'e&6e.ej7re'e&j7ej8re'e&j7ej8kdS)FN)RawConfigParser) FormatError PkgNotFound LibraryInfo VariableSet read_config parse_flagsz\$\{([a-zA-Z0-9_-]+)\}c@s eZdZdZddZddZdS)rzQ Exception thrown when there is a problem parsing a configuration file. cCs ||_dSNmsgselfr rH/usr/local/lib/python3.9/site-packages/numpy/distutils/npy_pkg_config.py__init__szFormatError.__init__cCs|jSr r r rrr__str__szFormatError.__str__N__name__ __module__ __qualname____doc__rrrrrrr src@s eZdZdZddZddZdS)rz3Exception raised when a package can not be located.cCs ||_dSr r r rrrrszPkgNotFound.__init__cCs|jSr r rrrrrszPkgNotFound.__str__NrrrrrrsrcCsgggggd}d|d}|D]}d|}t|dkr"|dr`|d|dd q"|d r|d |dd q"|d r|d |dd q"|dr|d|dd q"|d|q"|S)a Parse a line from a config file containing compile flags. Parameters ---------- line : str A single line containing one or more compile flags. Returns ------- d : dict Dictionary of parsed flags, split into relevant categories. These categories are the keys of `d`: * 'include_dirs' * 'library_dirs' * 'libraries' * 'macros' * 'ignored' ) include_dirs library_dirs librariesmacrosignored z --rz-IrNz-Lrz-lrz-Drr)splitlen startswithappendstrip)linedflagsflagrrrrs"     rcCs |ddS)N\z\\)replace)valrrr_escape_backslashIsr,c@s>eZdZdZdddZddZddd 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)r r-r.r0sectionsr2r/rrrrgszLibraryInfo.__init__cCst|jS)z Return the section headers of the config file. Parameters ---------- None Returns ------- keys : list of str The list of section headers. )listr1keysrrrrr3rszLibraryInfo.sectionsdefaultcCs|j|j|d}t|S)Ncflagsr2 interpolater1r,r sectionr+rrrr7szLibraryInfo.cflagscCs|j|j|d}t|S)Nlibsr8r:rrrr<szLibraryInfo.libscCsVd|jd|jg}|jr&|dn|dd|j|d|jd|S)NzName: %szDescription: %sz Requires:z Requires: %s,z Version: %s )r-r.r/r#joinr0)r mrrrrs  zLibraryInfo.__str__)N)r6)r6) rrrrrr3r7r<rrrrrrLs    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)r r&rrrrszVariableSet.__init__cCs$|jD]\}}|||q dSr )rHrG_init_parse_var)r rBrCrrrrKszVariableSet._init_parsecCs"td||j|<||j|<dS)Nz\$\{%s\})recompilerIrJr r-valuerrrrLszVariableSet._init_parse_varcs2fdd}t|r.||}||kr(q.|}q |S)Ncs,jD]}j|j||}q |Sr )rIr5subrJ)rPrBrrr _interpolatesz-VariableSet.interpolate.._interpolate)_VARsearch)r rPrRZnvaluerrrr9s  zVariableSet.interpolatecCst|jS)z Return the list of variable names. Parameters ---------- None Returns ------- names : list of str The names of all variables in the `VariableSet` instance. )r4rHr5rrrr variablesszVariableSet.variablescCs |j|Sr )rH)r r-rrr __getitem__szVariableSet.__getitem__cCs||j|<|||dSr )rHrLrOrrr __setitem__s zVariableSet.__setitem__N) rrrrrrKrLr9rUrVrWrrrrrs rcCsR|dstdt|d}dD]}||vr$td|q$d|vrNg|d<|S)NmetazNo meta section found !)r-r.r0z6Option %s (section [meta]) is mandatory, but not foundr/) has_sectionrrFrG)configr&rBrrr parse_metas r[cCs:|dstdi}|dD]\}}|||<q t|S)NrUzNo variables section found !)rYrrGr)rZr&r-rPrrrparse_variabless   r\cCsttfSr )Zmeta_dr)rZrrrparse_sectionssr^cCsd|S)Nz%s.inir)pkg_namerrrpkg_to_filenamesr`cs|rfdd|D}ng}t}||}t|dksJtdt|t|}i}|dr|dD]\}}t|||<qjdd| D} i} i} | D]H} i} | | dr| | d| | <|| D]\}}|| |<q| | | <q||| | fS)Ncsg|]}tj|qSr)ospathr?)rAr&filenamerrrDrEz parse_config..zCould not find file(s) %srUcSsg|]}|dvr|qS))rXrUr)rAsrrrrDrEr/) rreadr!rstrr[rYrGr,r3 has_optionget)rddirs filenamesrZnrXr2r-rPZsecsr3r/rfr&rrcr parse_configs.      rncsfdd|\}}}}d|vrtd|vrt|d}|tjvrTtd||dftj|}ttj|j|d<t|d|d|d|t |d S) Ncst|\}}}}|D]p\}}t|\}}} } |D]\} } | |vr>| || <q>| |D]$\} }|rd||| d|7<qdq||||fS)Nz %s)rnrGr`)frXr2r3reqsrnameZrvalueZnmetaZnvarsZ nsectionsZnreqsrBrCZonameZovalue _read_configrkrrrss z&_read_config_imp.._read_configZpkgdirpkgnamez-You should import %s to get information on %sr-r.r0)r-r.r0r3r2) sysmodules ValueErrorr,rarbdirname__file__rr)rlrkrXr2r3rprtmodrrrr_read_config_imps   r{cCs<z t|WSty6tt||}|t|<|YS0dS)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 N)_CACHEKeyErrorr{r`)rtrkrCrrrrFs '  r__main__) OptionParserz--cflagsr7 store_truez*output all preprocessor and compiler flags)destactionhelpz--libsr<zoutput all linker flagsz --use-sectionr;z/use this section instead of default for options)rrz --versionr0zoutput versionz--atleast-version min_versionzMinimal versionz --list-alllist_allz--define-variabledefine_variablez%Replace variable with the given valuerz(Expect package name on the command line:z*.iniz %s %s - %sreZNPY_PKG_CONFIG_PATHznumpy/_core/lib/npy-pkg-config.r6z([\S]+)=([\S]+)zH--define-variable option should be of the form --define-variable=foo=bar)N)N)N)9rurMra configparserr__all__rNrSOSErrorrrrr,rrr[r\r^r`rnr{r|rroptparserglobparser add_option parse_argsargvoptionsargsr!rwrfilesroinfoprintr-r.r_environrjr&r;rrTr@grouprPr2r7r<r0rrrrrs   *HD  $ ( 3