3
;p_eS                 @   s  d Z ddlZddlZddlZddlZddlmZ dejkZej	j
ejZej	j
ejZej	j
ejZej	j
ejZdejkrej	jejd Zn&ejrej	jej	jejZnej Zdd Zeed	dZejd
krdd ZeeZeeZdd Ze ZdZ yesej!Z W n e"k
r$   Y nX dd Z#d-ddZ$d.ddZ%dd Z&dd Z'dd Z(d/ddZ)ej*dZ+ej*dZ,ej*d Z-d0d!d"Z.d#d$ Z/da0d%d& Z1d'd( Z2d)d* Z3d+d, Z4dS )1a  Provide access to Python's configuration information.  The specific
configuration variables available depend heavily on the platform and
configuration.  The values may be retrieved using
get_config_var(name), and the list of variables is available via
get_config_vars().keys().  Additional convenience functions are also
available.

Written by:   Fred L. Drake, Jr.
Email:        <fdrake@acm.org>
    N   )DistutilsPlatformErrorZ__pypy__Z_PYTHON_PROJECT_BASEc             C   s.   x(dD ] }t jjt jj| d|rdS qW dS )NSetupSetup.localModulesTF)r   r   )ospathisfilejoin)dfn r   G/tmp/pip-install-ofl94hr3/setuptools/setuptools/_distutils/sysconfig.py_is_python_source_dir,   s    
r   Z_homentc             C   s0   | r,t jj| jt jjt jjtdr,tS | S )NZPCbuild)r   r   normcase
startswithr
   PREFIX)r   r   r   r   _fix_pcbuild5   s    r   c               C   s   t rtt S ttS )N)	_sys_homer   project_baser   r   r   r   _python_build=   s    r    c               C   s   dt jdd  S )zReturn a string containing the major and minor Python version,
    leaving off the patchlevel.  Sample return values could be '1.5'
    or '2.2'.
    z%d.%dN   )sysversion_infor   r   r   r   get_python_versionQ   s    r   c             C   s   |dkr| rt pt}tr&tjj|dS tjdkr|tr^| r@tp>t	S tjjt
dd}tjj|S dt  t }tjj|d|S tjdkrtrtjj|dtjj tjj|d S tjj|dS td	tj dS )
a  Return the directory containing installed Python header files.

    If 'plat_specific' is false (the default), this is the path to the
    non-platform-specific header files, i.e. Python.h and so on;
    otherwise, this is the path to platform-specific header files
    (namely pyconfig.h).

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    NincludeposixsrcdirIncludepythonr   PCzFI don't know where Python installs its C header files on platform '%s')BASE_EXEC_PREFIXBASE_PREFIXIS_PYPYr   r   r
   namepython_buildr   r   get_config_varnormpathr   build_flagspathsepr   )plat_specificprefixincdir
python_dirr   r   r   get_python_incY   s(    

r0   c             C   s   t r8|dkrt}|r*tjj|dtjd S tjj|dS |dkr^|rR| rLtpNt}n| rZt	p\t}tj
dkr| sp|r~ttdd}nd}tjj||dt  }|r|S tjj|dS n<tj
d	kr|rtjj|d
S tjj|d
dS ntdtj
 dS )aS  Return the directory containing the Python library (standard or
    site additions).

    If 'plat_specific' is true, return the directory containing
    platform-specific modules, i.e. any module from a non-pure-Python
    module distribution; otherwise, return the platform-shared library
    directory.  If 'standard_lib' is true, return the directory
    containing standard Python library modules; otherwise, return the
    directory for site-specific modules.

    If 'prefix' is supplied, use it instead of sys.base_prefix or
    sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
    Nz
lib-pythonr   zsite-packagesr   Z
platlibdirlibr!   r   Libz?I don't know where Python installs its library on platform '%s')r%   r   r   r   r
   r   versionr#   r$   EXEC_PREFIXr&   getattrr   r   )r,   standard_libr-   Zlibdir	libpythonr   r   r   get_python_lib   s4    


r8   c          	   C   s  | j dkrtjdkr8tds8ddl}|jt dtd< tddd	d
dddd\}}}}}}}}	dtj	krtj	d }
tjdkrdtj	kr|j
|r|
|t|d  }|
}dtj	krtj	d }dtj	krtj	d }dtj	krtj	d }n|d }dtj	kr|d tj	d  }d	tj	kr<|d tj	d	  }|d tj	d	  }dtj	kr~|d tj	d  }|d tj	d  }|d tj	d  }dtj	krtj	d }dtj	kr|d tj	d  }n|d |	 }|d | }| j|||d | ||||d || _dS )zDo any platform-specific customization of a CCompiler instance.

    Mainly needed on Unix, so we can plug in the information that
    varies across Unices and is stored in Python's Makefile.
    unixdarwinCUSTOMIZED_OSX_COMPILERr   NTrueCCCXXCFLAGSCCSHAREDLDSHAREDSHLIB_SUFFIXARARFLAGSCPPz -ELDFLAGS CPPFLAGS)preprocessorcompilercompiler_socompiler_cxx	linker_so
linker_exearchiver)compiler_typer   platformr(   _osx_supportcustomize_compiler_config_varsget_config_varsr   environr   lenset_executablesshared_lib_extension)rJ   rR   cccxxcflagsccsharedldsharedshlib_suffixarar_flagsnewcccpprO   cc_cmdr   r   r   rS      s\    













rS   c              C   sD   t r,tjdkr"tjjtptd} q6tp(t} n
tdd} tjj| dS )z2Return full pathname of installed pyconfig.h file.r   r"   r   )r,   z
pyconfig.h)r'   r   r&   r   r
   r   r   r0   )inc_dirr   r   r   get_config_h_filename  s    


rf   c              C   s\   t rtjjtptdS tddd} djt t	}t
tjdrL|dtjj 7 }tjj| |dS )zAReturn full pathname of installed Makefile from the Python build.Makefiler   r   )r,   r6   zconfig-{}{}
_multiarchz-%s)r'   r   r   r
   r   r   r8   formatr   r*   hasattrr   implementationrh   )lib_dirconfig_filer   r   r   get_makefile_filename  s    rn   c             C   s   |dkri }t jd}t jd}xx| j }|s0P |j|}|rz|jdd\}}yt|}W n tk
rn   Y nX |||< q"|j|}|r"d||jd< q"W |S )zParse a config.h-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    Nz"#define ([A-Z][A-Za-z0-9_]+) (.*)
z&/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/
r   r   r   )recompilereadlinematchgroupint
ValueError)fpg	define_rxundef_rxlinemnvr   r   r   parse_config_h  s(    


  

r~   z"([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)z\$\(([A-Za-z][A-Za-z0-9_]*)\)z\${([A-Za-z][A-Za-z0-9_]*)}c             C   s  ddl m} || ddddd}|dkr*i }i }i }x|j }|dkrFP tj|}|r4|jdd\}}	|	j }	|	jdd	}
d
|
kr|	||< q4yt|	}	W n$ t	k
r   |	jdd
||< Y q4X |	||< q4W d}x|rxt
|D ]}|| }tj|ptj|}|rx|jd}d}||kr2t|| }n||krBd}nx|tjkrZtj| }n`||kr|jdr|dd |krd	}n$d| |krd}nt|d|  }nd	 ||< }|r~||j d }|d|j  | | }d
|kr|||< nzyt|}W n" t	k
r*   |j ||< Y n
X |||< ||= |jdr~|dd |kr~|dd }||kr~|||< q||= qW qW |j  x.|j D ]"\}}	t|	tr|	j ||< qW |j| |S )zParse a Makefile-style file.

    A dictionary containing name/value pairs is returned.  If an
    optional dictionary is passed in as the second argument, it is
    used instead of a new dictionary.
    r   )TextFiler   surrogateescape)strip_commentsskip_blanks
join_lineserrorsNr   z$$r   $r?   rF   rH   TFPY_   )r?   rF   rH   )distutils.text_filer   rq   _variable_rxrr   rs   stripreplacert   ru   list_findvar1_rxsearch_findvar2_rxstrr   rV   r   endstartcloseitems
isinstanceupdate)r   rw   r   rv   donenotdonerz   r{   r|   r}   tmpvrenamed_variablesr&   valuefounditemafterkr   r   r   parse_makefile=  s    








 


r   c             C   sZ   xTt j| ptj| }|rP|j \}}| d| |j|jd | |d  } qP qW | S )a  Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
    'string' according to 'vars' (a dictionary mapping variable names to
    values).  Variables not present in 'vars' are silently expanded to the
    empty string.  The variable values in 'vars' should not contain further
    variable expansions; if 'vars' is the output of 'parse_makefile()',
    you're fine.  Returns a variable-expanded version of 's'.
    r   r   N)r   r   r   spangetrs   )svarsr{   begr   r   r   r   expand_makefile_vars  s    *r   c              C   s   t jjddjtjtjttjddd} yt	| t
 t dgd}W n* tk
rl   t	dt
 t dgd}Y nX |j}i atj| d	S )
z7Initialize the module as appropriate for POSIX systems._PYTHON_SYSCONFIGDATA_NAMEz+_sysconfigdata_{abi}_{platform}_{multiarch}rh   r   )abirQ   	multiarchbuild_time_varsr   Z_sysconfigdataN)r   rV   r   ri   r   abiflagsrQ   r5   rk   
__import__globalslocalsImportErrorr   rT   r   )r&   _tempr   r   r   r   _init_posix  s    r   c              C   s~   i } t ddd| d< t ddd| d< tdd| d< tj d | d< d	| d
< t jdd| d< tjjtjj	t
j| d< | adS )z+Initialize the module as appropriate for NTr   r   )r,   r6   LIBDEST
BINLIBDEST)r,   	INCLUDEPY
EXT_SUFFIXz.exeEXE.r   VERSIONBINDIRN)r8   r0   _impextension_suffixesr   r   r   r   dirnameabspathr   
executablerT   )rw   r   r   r   _init_nt  s    r   c              G   sd  t dkr.t jdtj }|r(|  ni a tt d< tt d< tst jd}|dk	r\|t d< t jdt}tjdkrt	rtj
jt }tj
j||}ntj
jt }tj
jtj
j|t d< t	otjdkrt}tj
jt d  o|tj krtj
j|t d }tj
j|t d< tjd	kr.d
dl}|jt  | r\g }x| D ]}|jt j| q>W |S t S dS )a  With no arguments, return a dictionary of all configuration
    variables relevant for the current platform.  Generally this includes
    everything needed to build extensions and install both pure modules and
    extensions.  On Unix, this means every variable defined in Python's
    installed Makefile; on Windows it's a much smaller set.

    With arguments, return a list of values that result from looking up
    each argument in the configuration variable dictionary.
    N_init_r-   exec_prefixr   SOr   r   r:   r   )rT   r   r   r   r&   r   r4   r%   r   r'   r   r   rn   r
   r   r)   isabsgetcwdr   rQ   rR   customize_config_varsappend)argsfuncr   r   baserR   valsr&   r   r   r   rU     sB    




rU   c             C   s*   | dkrddl }|jdtd t j| S )zReturn the value of a single variable using the dictionary
    returned by 'get_config_vars()'.  Equivalent to
    get_config_vars().get(name)
    r   r   Nz SO is deprecated, use EXT_SUFFIXr   )warningswarnDeprecationWarningrU   r   )r&   r   r   r   r   r(   5  s    r(   )r   N)r   r   N)N)N)5__doc__r   r   ro   r   r   r   builtin_module_namesr%   r   r)   r-   r   r   r4   base_prefixr$   base_exec_prefixr#   rV   r   r   r   r   r   r   r5   r   r&   r   r   r'   r*   r   AttributeErrorr   r0   r8   rS   rf   rn   r~   rp   r   r   r   r   r   rT   r   r   rU   r(   r   r   r   r   <module>
   s\   




*
6I




jK