U
    ÉZj¬2  ã                   @   s¸  d dl Z d dlZd dlZd dlmZ ddddddgZe d	¡ZG d
d„ deƒZ	G dd„ deƒZ
dd„ Zdd„ ZG dd„ dƒZG dd„ dƒZdd„ Zdd„ Zdd„ Zdd„ ZdBdd„ZdCdd„Zi ZdDdd„Zedk�r´d dlmZ d dlZeƒ Zejd d!d"d#d$� ejd%d&d"d'd$� ejd(d)d*d+� ejd,d-d"d.d$� ejd/d0d1d+� ejd2d3d"d1d$� ejd4d5d6d+� e e j¡\ZZ e!e ƒd7k �rŽe"d8ƒ‚ej#�rÌe d9¡Z$e$D ]&Z%ee%ƒZ&e'd:e&j(e&j(e&j)f ƒ �q¤e d; Z*ej+ ,d<¡Z-e-�røee*d=d>e-gƒZ&nee*d=d>gƒZ&ej.�rej.Z.nd?Z.ej/�r^e 0d@ej/¡Z1e1�s@e"dAƒ‚ne1 2d;¡Z(e1 2d7¡Z3e3e&j4e(< ej5�rte'e& 5e.¡ƒ ej6�rŠe'e& 6e.¡ƒ ej7�rœe'e&j7ƒ ej8�r´e'e&j7ej8kƒ dS )Eé    N)ÚRawConfigParserÚFormatErrorÚPkgNotFoundÚLibraryInfoÚVariableSetÚread_configÚparse_flagsz\$\{([a-zA-Z0-9_-]+)\}c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   zQ
    Exception thrown when there is a problem parsing a configuration file.

    c                 C   s
   || _ d S ©N©Úmsg©Úselfr   © r   úa/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/numpy/distutils/npy_pkg_config.pyÚ__init__   s    zFormatError.__init__c                 C   s   | j S r	   r
   ©r   r   r   r   Ú__str__   s    zFormatError.__str__N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z3Exception raised when a package can not be located.c                 C   s
   || _ d S r	   r
   r   r   r   r   r      s    zPkgNotFound.__init__c                 C   s   | j S r	   r
   r   r   r   r   r      s    zPkgNotFound.__str__Nr   r   r   r   r   r      s   c                 C   sæ   g g g g g dœ}d|    d¡}|D ]¾}d| }t|ƒdkr"| d¡r`|d  |dd	…  ¡ ¡ q"| d
¡r†|d  |dd	…  ¡ ¡ q"| d¡r¬|d  |dd	…  ¡ ¡ q"| d¡rÒ|d  |dd	…  ¡ ¡ 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Ú	librariesÚmacrosÚignoredú z -ú-r   z-Ir   é   Nz-Lr   z-lr   z-Dr   r   )ÚsplitÚlenÚ
startswithÚappendÚstrip)ÚlineÚdÚflagsÚflagr   r   r   r      s$     ÿ



c                 C   s   |   dd¡S )Nú\z\\)Úreplace)Úvalr   r   r   Ú_escape_backslashI   s    r,   c                   @   s>   e Zd ZdZddd„Zdd„ Zddd	„Zdd
d„Zdd„ ZdS )r   a$  
    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.

    Nc                 C   s4   || _ || _|r|| _ng | _|| _|| _|| _d S r	   )ÚnameÚdescriptionÚrequiresÚversionÚ	_sectionsÚvars)r   r-   r.   r0   Úsectionsr2   r/   r   r   r   r   g   s    zLibraryInfo.__init__c                 C   s   t | j ¡ ƒS )zÚ
        Return the section headers of the config file.

        Parameters
        ----------
        None

        Returns
        -------
        keys : list of str
            The list of section headers.

        )Úlistr1   Úkeysr   r   r   r   r3   r   s    zLibraryInfo.sectionsÚdefaultc                 C   s   | j  | j| d ¡}t|ƒS )NÚcflags©r2   Úinterpolater1   r,   ©r   Úsectionr+   r   r   r   r7   ‚   s    zLibraryInfo.cflagsc                 C   s   | j  | j| d ¡}t|ƒS )NÚlibsr8   r:   r   r   r   r<   †   s    zLibraryInfo.libsc                 C   sV   d| j  d| j g}| jr&| d¡ n| dd | j¡ ¡ | d| j ¡ d |¡S )NzName: %szDescription: %sz	Requires:zRequires: %sú,zVersion: %sÚ
)r-   r.   r/   r#   Újoinr0   )r   Úmr   r   r   r   Š   s    zLibraryInfo.__str__)N)r6   )r6   )	r   r   r   r   r   r3   r7   r<   r   r   r   r   r   r   L   s   


c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )r   a  
    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.

    c                 C   s0   t dd„ | ¡ D ƒƒ| _i | _i | _|  ¡  d S )Nc                 S   s   g | ]\}}||f‘qS r   r   )Ú.0ÚkÚvr   r   r   Ú
<listcomp>¢   s     z(VariableSet.__init__.<locals>.<listcomp>)ÚdictÚitemsÚ	_raw_dataÚ_reÚ_re_subÚ_init_parse)r   r&   r   r   r   r   ¡   s    zVariableSet.__init__c                 C   s$   | j  ¡ D ]\}}|  ||¡ q
d S r	   )rG   rF   Ú_init_parse_var)r   rB   rC   r   r   r   rJ   ©   s    zVariableSet._init_parsec                 C   s"   t  d| ¡| j|< || j|< d S )Nz\$\{%s\})ÚreÚcompilerH   rI   ©r   r-   Úvaluer   r   r   rK   ­   s    zVariableSet._init_parse_varc                    s2   ‡ fdd„}t  |¡r.||ƒ}||kr(q.|}q|S )Nc                    s,   ˆ j  ¡ D ]}ˆ j |  ˆ j| | ¡} q
| S r	   )rH   r5   ÚsubrI   )rO   rB   r   r   r   Ú_interpolate´   s    z-VariableSet.interpolate.<locals>._interpolate)Ú_VARÚsearch)r   rO   rQ   Znvaluer   r   r   r9   ±   s    
zVariableSet.interpolatec                 C   s   t | j ¡ ƒS )zì
        Return the list of variable names.

        Parameters
        ----------
        None

        Returns
        -------
        names : list of str
            The names of all variables in the `VariableSet` instance.

        )r4   rG   r5   r   r   r   r   Ú	variablesÀ   s    zVariableSet.variablesc                 C   s
   | j | S r	   )rG   )r   r-   r   r   r   Ú__getitem__Ñ   s    zVariableSet.__getitem__c                 C   s   || j |< |  ||¡ d S r	   )rG   rK   rN   r   r   r   Ú__setitem__Ô   s    
zVariableSet.__setitem__N)r   r   r   r   r   rJ   rK   r9   rT   rU   rV   r   r   r   r   r   ”   s   c                 C   sR   |   d¡stdƒ‚t|  d¡ƒ}dD ]}||kr$td| ƒ‚q$d|krNg |d< |S )NÚmetazNo meta section found !)r-   r.   r0   z6Option %s (section [meta]) is mandatory, but not foundr/   )Úhas_sectionr   rE   rF   )Úconfigr&   rB   r   r   r   Ú
parse_metaØ   s    
ÿrZ   c                 C   s:   |   d¡stdƒ‚i }|  d¡D ]\}}|||< q t|ƒS )NrT   zNo variables section found !)rX   r   rF   r   )rY   r&   r-   rO   r   r   r   Úparse_variablesè   s    

r[   c                 C   s   t tfS r	   )Zmeta_dÚr)rY   r   r   r   Úparse_sectionsó   s    r]   c                 C   s   d|  S )Nz%s.inir   )Úpkg_namer   r   r   Úpkg_to_filenameö   s    r_   c                    sô   |r‡ fdd„|D ƒ}nˆ g}t ƒ }| |¡}t|ƒdksJtdt|ƒ ƒ‚t|ƒ}i }| d¡r€| d¡D ]\}}t|ƒ||< qjdd„ | 	¡ D ƒ}	i }
i }|	D ]H}i }| 
|d¡rÂ| |d¡||< | |¡D ]\}}|||< qÌ||
|< qž|||
|fS )Nc                    s   g | ]}t j |ˆ ¡‘qS r   )ÚosÚpathr?   )rA   r&   ©Úfilenamer   r   rD   û   s     z parse_config.<locals>.<listcomp>é   zCould not find file(s) %srT   c                 S   s   g | ]}|d kr|‘qS ))rW   rT   r   )rA   Úsr   r   r   rD     s      r/   )r   Úreadr!   r   ÚstrrZ   rX   rF   r,   r3   Ú
has_optionÚget)rc   ÚdirsÚ	filenamesrY   ÚnrW   r2   r-   rO   Zsecsr3   r/   re   r&   r   rb   r   Úparse_configù   s.    



rm   c                    s–   ‡ ‡fdd„‰ ˆ | ƒ\}}}}d|krtd|krt|d }|t jkrTtd||d f ƒ‚t j| }ttj |j¡ƒ|d< t|d |d |d |t	|ƒd	�S )
Nc                    s˜   t | ˆƒ\}}}}| ¡ D ]p\}}ˆ t|ƒƒ\}}}	}
| ¡ D ]\}}||kr>|||< q>|	|  ¡ D ]$\}}|rd|| |  d| 7  < qdq||||fS )Nz %s)rm   rF   r_   )ÚfrW   r2   r3   ÚreqsÚrnameZrvalueZnmetaZnvarsZ	nsectionsZnreqsrB   rC   ZonameZovalue©Ú_read_configrj   r   r   rr     s    
z&_read_config_imp.<locals>._read_configZpkgdirÚpkgnamez-You should import %s to get information on %sr-   r.   r0   )r-   r.   r0   r3   r2   )
ÚsysÚmodulesÚ
ValueErrorr,   r`   ra   ÚdirnameÚ__file__r   r   )rk   rj   rW   r2   r3   ro   rs   Úmodr   rq   r   Ú_read_config_imp  s    

ÿ
  ÿrz   c                 C   s>   z
t |  W S  tk
r8   tt| ƒ|ƒ}|t | < | Y S X dS )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)
    <class 'numpy.distutils.npy_pkg_config.LibraryInfo'>
    >>> print(npymath_info)
    Name: npymath
    Description: Portable, core math library implementing C99 standard
    Requires:
    Version: 0.1  #random

    N)Ú_CACHEÚKeyErrorrz   r_   )rs   rj   rC   r   r   r   r   F  s    '
Ú__main__)ÚOptionParserz--cflagsr7   Ú
store_truez*output all preprocessor and compiler flags)ÚdestÚactionÚhelpz--libsr<   zoutput all linker flagsz--use-sectionr;   z/use this section instead of default for options)r€   r‚   z	--versionr0   zoutput versionz--atleast-versionÚmin_versionzMinimal versionz
--list-allÚlist_allz--define-variableÚdefine_variablez%Replace variable with the given valuer   z(Expect package name on the command line:z*.iniz
%s	%s - %srd   ZNPY_PKG_CONFIG_PATHznumpy/core/lib/npy-pkg-configÚ.r6   z([\S]+)=([\S]+)zH--define-variable option should be of the form --define-variable=foo=bar)N)N)N)9rt   rL   r`   Úconfigparserr   Ú__all__rM   rR   ÚOSErrorr   r   r   r,   r   r   rZ   r[   r]   r_   rm   rz   r{   r   r   Úoptparser~   ÚglobÚparserÚ
add_optionÚ
parse_argsÚargvÚoptionsÚargsr!   rv   r„   Úfilesrn   ÚinfoÚprintr-   r.   r^   Úenvironri   r&   r;   r…   rS   r@   ÚgrouprO   r2   r7   r<   r0   rƒ   r   r   r   r   Ú<module>   sœ    ÿ
*HD
$
(
3

ÿ
ÿÿ
ÿÿ
ÿÿ





