U
    Hah                     @   s  d Z ddlZddlZddlZddlZddlmZmZ zddlZW n e	k
r\   ddl
ZY nX dddddd	d
ddddgZdd ZejrejeejZnee Zejdkrdedd  kreejeeZejdkrdedd  kreejeeeZejdkrBdedd  krBeejeeeZdd Ze Zdadd Ze ZedZdd Zd ejdd!  Zd"ejdd#  Z d$ejdd#  Z!ej"ej#Z$ej"ej%Z&da'dZ(d%d& Z)d'd( Z*d)d* Z+d+d, Z,d-d. Z-d/d0 Z.dHd1d2Z/d3d Z0d4d5 Z1d6d7 Z2dId8dZ3d9d Z4d:d Z5d;d	 Z6e- dd<fd=d
Z7e- dd<fd>dZ8d?d Z9d@d Z:dAd Z;dBd Z<dCdD Z=dEdF Z>e?dGkre>  dS )Jz-Access to Python's configuration information.    N)pardirrealpathget_config_h_filenameget_config_varget_config_varsget_makefile_filenameget_pathget_path_names	get_pathsget_platformget_python_versionget_scheme_namesparse_config_hc                 C   s(   z
t | W S  tk
r"   |  Y S X d S N)r   OSError)path r   ?/tmp/pip-unpacked-wheel-0woaezjq/distlib/_backport/sysconfig.py_safe_realpath"   s    
r   ntZpcbuildiz\pc\viz\pcbuild\amd64ic                  C   s,   dD ]"} t jt jtd| r dS qdS )N)z
Setup.distzSetup.localModulesTF)osr   isfilejoin_PROJECT_BASE)fnr   r   r   is_python_build:   s    r   Fc               	   C   s   t sddlm}  tddd }| |}|d}|s>td| }t	| W 5 Q R X t
rdD ] }t|d	d
 t|dd qdda d S )N   )finder.   r   zsysconfig.cfgzsysconfig.cfg exists)posix_prefix
posix_homeincludez{srcdir}/Includeplatincludez{projectbase}/.T)	_cfg_read	resourcesr   __name__rsplitfindAssertionError	as_stream_SCHEMESreadfp_PYTHON_BUILDset)r   Zbackport_packageZ_finderZ_cfgfilesschemer   r   r   _ensure_cfg_readD   s    

r2   z\{([^{]*?)\}c              
      s   t   | dr| d}nt }|  }|D ]8}|dkr<q.|D ]$\}}| ||rVq@| ||| q@q.| d |  D ]H}t| |  fdd}| |D ]\}}| ||t	
|| qqzd S )Nglobalsc                    s$   |  d}| kr | S |  dS Nr    r   groupZmatchobjname	variablesr   r   	_replacero   s    
z"_expand_globals.<locals>._replacer)r2   has_sectionitemstuplesections
has_optionr/   remove_sectiondict	_VAR_REPLsub)configr3   r?   sectionoptionvaluer;   r   r9   r   _expand_globalsY   s$    

rI   z%s.%s.%s   z%s.%sr   z%s%sc                    s    fdd}t || S )zIn the string `path`, replace tokens like {some.thing} with the
    corresponding value from the map `local_vars`.

    If there is no corresponding value, leave the token unchanged.
    c                    s8   |  d}| kr | S |tjkr.tj| S |  dS r4   )r6   r   environr7   
local_varsr   r   r;      s    


z_subst_vars.<locals>._replacerrC   rD   )r   rM   r;   r   rL   r   _subst_vars   s    rO   c                 C   s0   |   }| D ]\}}||kr"q|| |< qd S r   )keysr=   )target_dict
other_dicttarget_keyskeyrH   r   r   r   _extend_dict   s
    rU   c                 C   s`   i }|d kri }t |t  t| D ]4\}}tjdkrDtj|}tjt	||||< q&|S )N)posixr   )
rU   r   r,   r=   r   r8   r   
expandusernormpathrO   )r1   varsresrT   rH   r   r   r   _expand_vars   s    
r[   c                    s    fdd}t || S )Nc                    s$   |  d}| kr | S |  dS r4   r5   r7   rY   r   r   r;      s    
zformat_value.<locals>._replacerrN   )rH   rY   r;   r   r\   r   format_value   s    r]   c                   C   s   t jdkrdS t jS )NrV   r!   )r   r8   r   r   r   r   _get_default_scheme   s    
r^   c                  C   s   t jdd } dd }t jdkrBt jdp.d}| r8| S ||dS tjdkr|td	}|r|| r`| S |dd
|dtjd d  S | r| S |ddS d S )NPYTHONUSERBASEc                  W   s   t jt jj|  S r   )r   r   rW   r   )argsr   r   r   joinuser   s    z_getuserbase.<locals>.joinuserr   APPDATA~PythondarwinPYTHONFRAMEWORKLibraryz%d.%dr   z.local)r   rK   getr8   sysplatformr   version_info)env_basera   baseZ	frameworkr   r   r   _getuserbase   s$    



rn   c              	   C   s  t d}t d}t d}|dkr*i }i }i }tj| ddd}| }W 5 Q R X |D ]}	|	dsZ|	 d	krvqZ||	}
|
rZ|
d
d\}}| }|	dd	}d|kr|||< qZzt
|}W n$ tk
r   |	dd||< Y qZX |||< qZt| }d}t|dkrt|D ]}|| }||p>||}
|
dk	r|
d
}d}||krpt|| }n||krd}nx|tjkrtj| }n`||kr|dr|dd |krd	}n$d| |krd}nt|d|  }nd	 ||< }|r||
 d }|d|
  | | }d|kr:|||< n~zt
|}W n" tk
rh   | ||< Y n
X |||< || |dr|dd |kr|dd }||kr|||< n|||< || qq| D ]"\}}t|tr| ||< q|| |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.
    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_]*)}Nzutf-8surrogateescape)encodingerrors# r    r   z$$$)CFLAGSLDFLAGSCPPFLAGSr   TFPY_rJ   )recompilecodecsopen	readlines
startswithstripmatchr6   replaceint
ValueErrorlistrP   lenr>   searchstrr   rK   endstartremover=   
isinstanceupdate)filenamerY   _variable_rx_findvar1_rx_findvar2_rxdonenotdoneflineslinemnvtmpvr:   renamed_variablesr8   rH   founditemafterkr   r   r   _parse_makefile   s    	
















r   c                  C   sD   t rtjtdS ttdr,dttjf } nd} tjt	d| dS )z Return the path of the Makefile.Makefileabiflagszconfig-%s%srE   stdlib)
r.   r   r   r   r   hasattrri   _PY_VERSION_SHORTr   r   )config_dir_namer   r   r   r   K  s    
c              
   C   s   t  }zt||  W nJ tk
r^ } z,d| }t|drF|d|j  }t|W 5 d}~X Y nX t }z"t|}t||  W 5 Q R X W nJ tk
r } z,d| }t|dr|d|j  }t|W 5 d}~X Y nX tr| d | d< dS )z7Initialize the module as appropriate for POSIX systems.z.invalid Python installation: unable to open %sstrerrorz (%s)N	BLDSHAREDLDSHARED)	r   r   IOErrorr   r   r   r|   r   r.   )rY   makefileemsgconfig_hr   r   r   r   _init_posixV  s&    


r   c                 C   sV   t d| d< t d| d< t d| d< d| d< d	| d
< t| d< tjttj| d< dS )z+Initialize the module as appropriate for NTr   LIBDEST
platstdlib
BINLIBDESTr#   	INCLUDEPYz.pydSOz.exeEXEVERSIONBINDIRN)r   _PY_VERSION_SHORT_NO_DOTr   r   dirnamer   ri   
executabler\   r   r   r   _init_non_posixr  s    r   c                 C   s   |dkri }t d}t d}|  }|s.q||}|rx|dd\}}zt|}W n tk
rl   Y nX |||< q ||}|r d||d< q |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   )ry   rz   readliner   r6   r   r   )fprY   	define_rxundef_rxr   r   r   r   r   r   r   r     s&    




c                  C   s:   t r$tjdkrtjtd} q,t} ntd} tj| dS )zReturn the path of pyconfig.h.r   PCr$   z
pyconfig.h)r.   r   r8   r   r   r   r   )inc_dirr   r   r   r     s    
c                   C   s   t tt S )z,Return a tuple containing the schemes names.)r>   sortedr,   r?   r   r   r   r   r     s    c                   C   s
   t dS )z*Return a tuple containing the paths names.r!   )r,   optionsr   r   r   r   r	     s    Tc                 C   s&   t   |rt| |S tt| S dS )zReturn a mapping containing an install scheme.

    ``scheme`` is the install scheme name. If not provided, it will
    return the default scheme for the current platform.
    N)r2   r[   rB   r,   r=   )r1   rY   expandr   r   r   r
     s    
c                 C   s   t ||||  S )z[Return a path corresponding to the scheme.

    ``scheme`` is the install scheme name.
    )r
   )r8   r1   rY   r   r   r   r   r     s    c                  G   s  t dkrzi a tt d< tt d< tt d< tt d< td td  t d< tt d	< tt d
< tt d< ztjt d< W n tk
r   dt d< Y nX t	j
dkrtt  t	j
dkrtt  tjdkrt t d< dt krtt d< ntt d t d< tr\t	j
dkr\t}zt	 }W n tk
r   d}Y nX t	jt d s\||kr\t	j|t d }t	j|t d< tjdkrzt	 d }t|dd }|dk rdD ]2}t | }tdd|}tdd|}|t |< qndt	jkrt	jd }dD ]0}t | }tdd|}|d | }|t |< qt dd}	td|	}
|
dk	rz|
 d}t	j!|szdD ]$}t | }tdd|}|t |< qT| rg }| D ]}|"t | q|S t S dS )ay  With no arguments, return a dictionary of all configuration
    variables relevant for the current platform.

    On Unix, this means every variable defined in Python's installed Makefile;
    On Windows and Mac OS 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prefixexec_prefix
py_versionpy_version_shortr   r   py_version_nodotrm   platbaseprojectbaser   rs   )r   Zos2rV   z2.6userbasesrcdirre   r      )rv   
BASECFLAGSru   	PY_CFLAGSr   z-arch\s+\w+\s z-isysroot [^ 	]*Z	ARCHFLAGSru   z-isysroot\s+(\S+)r    z-isysroot\s+\S+(\s|$))#_CONFIG_VARS_PREFIX_EXEC_PREFIX_PY_VERSIONr   r   ri   r   AttributeErrorr   r8   r   r   versionrn   r   r.   getcwdr   r   isabsr   rX   rj   unamer   splitry   rD   rK   rh   r   r6   existsappend)r`   rm   cwdr   Zkernel_versionmajor_versionrT   flagsarchru   r   Zsdkvalsr8   r   r   r   r     s    










c                 C   s   t  | S )zReturn the value of a single variable using the dictionary returned by
    'get_config_vars()'.

    Equivalent to get_config_vars().get(name)
    )r   rh   )r8   r   r   r   r   P  s    c                  C   s^  t jdkrnd} tj| }|dkr(tjS tjd|}tj|t|  |  }|dkr\dS |dkrhdS tjS t jd	kstt d
stjS t 	 \}}}}}| 
dd}|
dd}|
dd}|dd dkrd||f S |dd dkr&|d dkrPd}dt|d d |dd f }n*|dd dkrDd||f S |dd dkrdd|||f S |dd d krd }td!}	|	|}
|
rP|
 }n|dd d"krPt }|d#}|}ztd$}W n tk
r   Y nJX ztd%| }
W 5 |  X |
dk	r2d&|
d'd&dd }|s<|}|rP|}d(}|d& d)krd*t d+d krd,}t d+}td-|}ttt|}t|d'kr|d }n^|d.krd,}nN|d/krd0}n>|d1krd2}n.|d3krd4}n|d5krd6}ntd7|f n<|d8kr0tjd9krPd:}n |d;krPtjd9krLd<}nd=}d>|||f S )?a  Return a string that identifies the current platform.

    This is used mainly to distinguish platform-specific build directories and
    platform-specific built distributions.  Typically includes the OS name
    and version and the architecture (as supplied by 'os.uname()'),
    although the exact information included depends on the OS; eg. for IRIX
    the architecture isn't particularly important (IRIX only runs on SGI
    hardware), but for Linux the kernel version isn't particularly
    important.

    Examples of returned values:
       linux-i586
       linux-alpha (?)
       solaris-2.6-sun4u
       irix-5.3
       irix64-6.2

    Windows will return one of:
       win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
       win-ia64 (64bit Windows on Itanium)
       win32 (all others - specifically, sys.platform is returned)

    For other non-POSIX platforms, currently just returns 'sys.platform'.
    r   z bit ()amd64z	win-amd64Zitaniumzwin-ia64rV   r   /rs   r   _-N   linuxz%s-%ssunosr   5solarisz%d.%srJ   r      Zirixaixz%s-%s.%s   cygwinz[\d.]+re   MACOSX_DEPLOYMENT_TARGETz0/System/Library/CoreServices/SystemVersion.plistz=<key>ProductUserVisibleVersion</key>\s*<string>(.*?)</string>r   r    macosxz10.4.z-archru   fatz-arch\s+(\S+))i386ppc)r   x86_64intel)r   r   r   Zfat3)ppc64r   fat64)r   r   r   r   	universalz%Don't know machine value for archs=%rr   l        r   )PowerPCPower_Macintoshr   r   z%s-%s-%s) r   r8   ri   r   r)   rj   r   lowerr   r   r   r   ry   rz   r   r6   r   rh   r|   r   closer   readr   r   r   findallr>   r   r/   r   maxsize)r   ijZlookosnamehostreleaser   machinerel_rer   ZcfgvarsZmacverZ
macreleaser   cflagsZarchsr   r   r   r   Y  s    
$












c                   C   s   t S r   )r   r   r   r   r   r     s    c                 C   sF   t t| D ]0\}\}}|dkr0td|   td||f  qd S )Nr   z%s: z
	%s = "%s")	enumerater   r=   print)titledataindexrT   rH   r   r   r   _print_dict  s    r  c                   C   sR   t dt   t dt   t dt   t   tdt  t   tdt  dS )z*Display all information sysconfig detains.zPlatform: "%s"zPython version: "%s"z!Current installation scheme: "%s"Paths	VariablesN)r  r   r   r^   r  r
   r   r   r   r   r   _main  s    r  __main__)N)N)@__doc__r{   r   ry   ri   os.pathr   r   configparserImportErrorConfigParser__all__r   r   r   r   r   r   r8   r   r   r   r.   r%   r2   RawConfigParserr,   rz   rC   rI   rk   r   r   r   rX   r   r   r   r   r   
_USER_BASErO   rU   r[   r]   r^   rn   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r  r  r'   r   r   r   r   <module>   s   ""
!	
v
 	 #
