o
    5‘ðixu  ã                
   @  s¸  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlm Z! dZ"ddddddœZ#ddddddœddddddœe#ddddddœddddddœdœZ$e"r¦d d d!d"d#dœe$d$< d d d%d&d#dœe$d'< e$ %e!j&¡ dZ'd(d)„ Z(d*d+„ Z)d,d-„ Z*d.d/„ Z+d0d1„ Z,d2d3„ Z-d4d5„ Z.d6d7„ Z/d8d9„ Z0G d:d;„ d;eƒZ1dS )<zFdistutils.command.install

Implements the Distutils 'install' command.é    )ÚannotationsN)Úlog)Ú	USER_BASEÚ	USER_SITE)ÚClassVaré   )ÚCommand)ÚDEBUG)ÚDistutilsOptionErrorÚDistutilsPlatformError)Ú
write_file)Úget_config_vars)Úchange_rootÚconvert_pathÚget_platformÚ
subst_varsé   )Ú_framework_compatTz{base}/Lib/site-packagesz{base}/Include/{dist_name}z{base}/Scriptsz{base})ÚpurelibÚplatlibÚheadersÚscriptsÚdatazA{base}/lib/{implementation_lower}{py_version_short}/site-packageszN{platbase}/{platlibdir}/{implementation_lower}{py_version_short}/site-packageszM{base}/include/{implementation_lower}{py_version_short}{abiflags}/{dist_name}z
{base}/binz!{base}/lib/{implementation_lower}z*{base}/{platlibdir}/{implementation_lower}z1{base}/include/{implementation_lower}/{dist_name}z{base}/site-packagesz{base}/include/{dist_name})Úposix_prefixÚ
posix_homeÚntÚpypyÚpypy_ntz
{usersite}zF{userbase}/{implementation}{py_version_nodot_plat}/Include/{dist_name}z:{userbase}/{implementation}{py_version_nodot_plat}/Scriptsz
{userbase}Únt_userzQ{userbase}/include/{implementation_lower}{py_version_short}{abiflags}/{dist_name}z{userbase}/binÚ
posix_userc                   C  s@   t  t¡� dd„ t ¡ D ƒW  d   ƒ S 1 sw   Y  d S )Nc                 S  s   i | ]
}|t j|d d�“qS )F)Úexpand)Ú	sysconfigÚ	get_paths©Ú.0Úscheme© r&   úd/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/command/install.pyÚ
<dictcomp>e   s    ÿÿz+_load_sysconfig_schemes.<locals>.<dictcomp>)Ú
contextlibÚsuppressÚAttributeErrorr!   Úget_scheme_namesr&   r&   r&   r'   Ú_load_sysconfig_schemesc   s
   þ$ÿr-   c                     s(   t ƒ pi ‰ ‡ fdd„tt tˆ ¡ƒD ƒS )z=
    Extend default schemes with schemes from sysconfig.
    c                   s*   i | ]}|i t  |i ¡¥ˆ  |i ¡¥“qS r&   )ÚINSTALL_SCHEMESÚgetr#   ©Úsysconfig_schemesr&   r'   r(   r   s    ü
ÿ
þÿz!_load_schemes.<locals>.<dictcomp>)r-   ÚsetÚ	itertoolsÚchainr.   r&   r&   r0   r'   Ú_load_schemesk   s   

ûr5   c                   C  s   t tdƒrdS dS )NÚpypy_version_infoÚPyPyÚPython)ÚhasattrÚsysr&   r&   r&   r'   Ú_get_implementation{   s   
r;   c                 C  s.   t |tt|ƒƒƒ}t| ƒ t| t|ƒƒ¡ d S ©N)Ú_inject_headersÚ_load_schemeÚ_resolve_schemeÚvarsÚupdateÚ_remove_setÚ_scheme_attrs)ÚobÚnamer%   r&   r&   r'   Ú_select_scheme‚   s   rF   c                   s   ‡ fdd„|  ¡ D ƒS )z1
    Include only attrs that are None in ob.
    c                   s$   i | ]\}}t ˆ |ƒd u r||“qS r<   )Úgetattr)r$   ÚkeyÚvalue©rD   r&   r'   r(   ‹   s   $ z_remove_set.<locals>.<dictcomp>)Úitems)rD   Úattrsr&   rJ   r'   rB   ‡   s   rB   c                 C  s@   |   d¡\}}}zt |¡}W |S  ty   t | ¡}Y |S w )NÚ_)Ú	partitionr!   Úget_preferred_schemeÚ	ExceptionÚfwr%   )rE   Úos_nameÚseprH   Úresolvedr&   r&   r'   r?   Ž   s   þþr?   c                 C  s
   t ƒ |  S r<   )r5   )rE   r&   r&   r'   r>   —   s   
r>   c                 C  s   t | ƒ}| d|d ¡ |S )z¾
    Given a scheme name and the resolved scheme,
    if the scheme does not include headers, resolve
    the fallback scheme for the name and use headers
    from it. pypa/distutils#88
    r   )r>   Ú
setdefault)rE   r%   Úfallbackr&   r&   r'   r=   ›   s   	r=   c                   s   ‡ fdd„t D ƒS )z<Resolve install directories by applying the install schemes.c                   s   i | ]
}d |› �ˆ | “qS )Úinstall_r&   )r$   rH   ©r%   r&   r'   r(   «   s    z!_scheme_attrs.<locals>.<dictcomp>)ÚSCHEME_KEYSrX   r&   rX   r'   rC   ©   ó   rC   c                   @  sF  e Zd ZU dZg d¢Zg d¢Zded< er&e ddde	› d	�f¡ e d¡ d
diZ
ded< dAdd„ZdAdd„ZdAdd„ZdAdd„ZdAdd„ZdAdd„Zdd„ ZdAdd„ZdAd d!„ZdAd"d#„ZdAd$d%„ZdAd&d'„ZdAd(d)„Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:efd;efd<efd=efd>d?d@„ fgZ dS )BÚinstallz'install everything from build directory))zprefix=Nzinstallation prefix)zexec-prefix=Nz.(Unix only) prefix for platform-specific files)zhome=Nz+(Unix only) home directory to install under)zinstall-base=Nz;base installation directory (instead of --prefix or --home))zinstall-platbase=Nz\base installation directory for platform-specific files (instead of --exec-prefix or --home))zroot=Nz<install everything relative to this alternate root directory)zinstall-purelib=Nz;installation directory for pure Python module distributions)zinstall-platlib=Nz8installation directory for non-pure module distributions)zinstall-lib=Nzginstallation directory for all module distributions (overrides --install-purelib and --install-platlib))zinstall-headers=Nz(installation directory for C/C++ headers)zinstall-scripts=Nz)installation directory for Python scripts)zinstall-data=Nz%installation directory for data files)ÚcompileÚczcompile .py to .pyc [default])ú
no-compileNzdon't compile .py files)z	optimize=ÚOzlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0])ÚforceÚfz1force installation (overwrite any existing files))ú
skip-buildNz2skip rebuilding everything (for testing/debugging))zrecord=Nz3filename in which to record list of installed files)r\   r`   rb   zClassVar[list[str]]Úboolean_optionsÚuserNzinstall in user site-package 'ú'r^   r\   zClassVar[dict[str, str]]Únegative_optÚreturnÚNonec                 C  sš   d| _ d| _d| _d| _d| _d| _d| _d| _d| _d| _	d| _
d| _d| _t| _t| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _dS )zInitializes options.NFT)ÚprefixÚexec_prefixÚhomerd   Úinstall_baseÚinstall_platbaseÚrootÚinstall_purelibÚinstall_platlibÚinstall_headersÚinstall_libÚinstall_scriptsÚinstall_datar   Úinstall_userbaser   Úinstall_usersiter\   ÚoptimizeÚ
extra_pathÚinstall_path_filer`   Ú
skip_buildÚwarn_dirÚ
build_baseÚ	build_libÚrecord©Úselfr&   r&   r'   Úinitialize_options÷   s2   
zinstall.initialize_optionsc                 C  s¾  | j s	| js	| jr| js| jrtdƒ‚| jr | j s| jr tdƒ‚| jr6| j s2| js2| js2| js2| jr6tdƒ‚tjdkrF| jrF|  	d¡ d| _|  
d¡ tjdkrU|  ¡  n|  ¡  |  
d¡ tj ¡ d	 }td
dƒ\}}ztj}W n ty|   d}Y nw | j ¡ | j ¡ | j ¡ |tjj› dtjj› �tjj› tjj› �|||||ttddƒtƒ  ¡ tƒ dœ}tttddƒ dd¡d�}trÉ| j |d< | j!|d< t" #|t$ ¡ |t% &¡ ¡| _'|  (¡  |  
d¡ | j|d< | j|d< t)rüd	dl*m*} t+dƒ |t| j'ƒƒ |  ,¡  |  
d¡ | j�r|  -¡  | j.du �r"| j /¡ �r| j0| _.n| j1| _.|  2dddddddd¡ |  3¡  | j.| _4tj5 6| j.| j7¡| _.| j8du�rQ|  9d dddddd¡ |  
d!¡ |  :d"d#d$¡ dS )%zFinalizes options.zWmust supply either prefix/exec-prefix/home or install-base/install-platbase -- not bothz9must supply either home or prefix/exec-prefix -- not bothzGcan't combine user with prefix, exec_prefix/home, or install_(plat)baseÚposixz+exec-prefix option ignored on this platformNzpre-finalize_{unix,other}zpost-finalize_{unix,other}()r   ri   rj   Ú Ú.Ú
platlibdirÚlib)Ú	dist_nameÚdist_versionÚdist_fullnameÚ
py_versionÚpy_version_shortÚpy_version_nodotÚ
sys_prefixri   Úsys_exec_prefixrj   Úabiflagsr…   Úimplementation_lowerÚimplementationÚwinver)Úpy_version_nodot_platÚuserbaseÚusersitezpost-expand_basedirs()ÚbaseÚplatbase)Úpprintzconfig vars:zpost-expand_dirs()r   r   r   r   r   Úlibbasezafter prepending rootÚbuild)r|   r|   )r}   r}   );ri   rj   rk   rl   rm   r
   rd   ÚosrE   ÚwarnÚ	dump_dirsÚfinalize_unixÚfinalize_otherr:   ÚversionÚsplitr   r�   r+   ÚdistributionÚget_nameÚget_versionÚget_fullnameÚversion_infoÚmajorÚminorrG   r;   ÚlowerÚdictÚreplaceÚHAS_USER_SITEru   rv   ÚcollectionsÚChainMapr!   rQ   r@   Úconfig_varsÚexpand_basedirsr	   r˜   ÚprintÚexpand_dirsÚcreate_home_pathrr   Úhas_ext_modulesrp   ro   Úconvert_pathsÚhandle_extra_pathÚinstall_libbaseÚpathÚjoinÚ
extra_dirsrn   Úchange_rootsÚset_undefined_options)r€   rŠ   ri   rj   r�   Ú
local_varsÚcompat_varsr˜   r&   r&   r'   Úfinalize_optionsD  sÔ   ÿÿÿÿÿþýüûÿ







þ
òþ

ü




øÿ
ÿzinstall.finalize_optionsc                 C  s    t sdS ddlm} t |d ¡ | jD ]9}|d }|d dkr&|dd… }|| jv r<| j| }| |¡}t| |ƒ }n
| |¡}t| |ƒ}t d||¡ qdS )	zDumps the list of user options.Nr   )Úlongopt_xlateú:r   éÿÿÿÿú=z  %s: %s)	r	   Úfancy_getoptrÀ   r   ÚdebugÚuser_optionsrf   Ú	translaterG   )r€   ÚmsgrÀ   ÚoptÚopt_nameÚvalr&   r&   r'   r�   û  s    





õzinstall.dump_dirsc                 C  s<  | j dus
| jdur0| jdu o| jdu o| jdu p'| jdu p'| jdu p'| jdu }|r.tdƒ‚dS | j	rJ| j
du r<tdƒ‚| j
 | _ | _|  d¡ dS | jdur]| j | _ | _|  d¡ dS | jdu r†| jdurktdƒ‚ttddƒ}tj tj¡| | _tj tj¡| | _n	| jdu r�| j| _| j| _ | j| _|  d	¡ dS )
z&Finalizes options for posix platforms.NzPinstall-base or install-platbase supplied, but installation scheme is incompleteú$User base directory is not specifiedr   r   z*must not supply exec-prefix without prefixÚ_prefix_additionrƒ   r   )rl   rm   rr   ro   rp   rq   rs   rt   r
   rd   ru   r   Úselect_schemerk   ri   rj   rG   r!   r›   r¸   Únormpathr:   )r€   Úincomplete_schemerÍ   r&   r&   r'   rž     sL   
ÿýûúø
ÿ



ÿ
zinstall.finalize_unixc                 C  s¼   | j r| jdu rtdƒ‚| j | _| _|  tjd ¡ dS | jdur0| j | _| _|  d¡ dS | j	du r=tj
 tj	¡| _	| j	 | _| _z	|  tj¡ W dS  ty]   tdtj› d�ƒ‚w )z)Finalizes options for non-posix platformsNrÌ   Ú_userr   z&I don't know how to install stuff on 're   )rd   ru   r   rl   rm   rÎ   r›   rE   rk   ri   r¸   rÏ   r:   ÚKeyErrorr   r&   r&   r'   rŸ   @  s$   


ÿÿzinstall.finalize_otherc                 C  s   t | |ƒ d S r<   )rF   )r€   rE   r&   r&   r'   rÎ   V  s   zinstall.select_schemec                 C  sN   |D ]"}t | |ƒ}|d ur$tjdv rtj |¡}t|| jƒ}t| ||ƒ qd S )N)r‚   r   )rG   r›   rE   r¸   Ú
expanduserr   r¯   Úsetattr)r€   rL   ÚattrrË   r&   r&   r'   Ú_expand_attrsY  s   

€úzinstall._expand_attrsc                 C  ó   |   g d¢¡ dS )zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.)rl   rm   rn   N©rÖ   r   r&   r&   r'   r°   b  s   zinstall.expand_basedirsc                 C  r×   )z+Calls `os.path.expanduser` on install dirs.)ro   rp   rr   rq   rs   rt   NrØ   r   r&   r&   r'   r²   g  rZ   zinstall.expand_dirsc                 G  s,   |D ]}d| }t | |tt| |ƒƒƒ qdS )z!Call `convert_path` over `names`.rW   N)rÔ   r   rG   ©r€   ÚnamesrE   rÕ   r&   r&   r'   rµ   r  s   þzinstall.convert_pathsc                 C  s¤   | j du r
| jj | _ | j durFt d¡ t| j tƒr!| j  d¡| _ t| j ƒdkr0| j d  }}nt| j ƒdkr=| j \}}ntdƒ‚t	|ƒ}nd}d}|| _
|| _dS )	z4Set `path_file` and `extra_dirs` using `extra_path`.NzIDistribution option extra_path is deprecated. See issue27919 for details.ú,r   r   r   zY'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elementsrƒ   )rx   r¢   r   ÚwarningÚ
isinstanceÚstrr¡   Úlenr
   r   Ú	path_filerº   )r€   rà   rº   r&   r&   r'   r¶   x  s(   


ÿÿ

zinstall.handle_extra_pathc              	   G  s0   |D ]}d| }t | |t| jt| |ƒƒƒ qdS )z:Change the install directories pointed by name using root.rW   N)rÔ   r   rn   rG   rÙ   r&   r&   r'   r»   ›  s   þzinstall.change_rootsc                 C  sf   | j sdS ttj d¡ƒ}| j ¡ D ]}t|ƒ |¡r0tj 	|¡s0|  
d|› d�¡ t |d¡ qdS )zCreate directories under ~.Nú~zos.makedirs('z	', 0o700)iÀ  )rd   r   r›   r¸   rÓ   r¯   ÚvaluesrÞ   Ú
startswithÚisdirÚdebug_printÚmakedirs)r€   rk   r¸   r&   r&   r'   r³   ¡  s   €ýzinstall.create_home_pathc                 C  s*  | j s|  d¡ | j d¡j}| jr|tƒ krtdƒ‚|  ¡ D ]}|  |¡ q| j	r.|  
¡  | jr_|  ¡ }| jrPt| jƒ}tt|ƒƒD ]}|| |d… ||< qC|  t| j|fd| j› d�¡ ttjjtjƒ}ttjj|ƒ}tj tj | j¡¡}| jr�| j	r‚| js“||vr‘t d| j¡ dS dS dS dS )zRuns the command.rš   z"Can't install when cross-compilingNz$writing list of installed files to 're   zƒmodules installed to '%s', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself)rz   Úrun_commandr¢   Úget_command_objÚ	plat_namer{   r   r   Úget_sub_commandsrà   Úcreate_path_filer~   Úget_outputsrn   rß   ÚrangeÚexecuter   Úmapr›   r¸   rÏ   r:   Únormcaserr   ry   r   rÅ   )r€   Ú
build_platÚcmd_nameÚoutputsÚroot_lenÚcounterÚsys_pathrr   r&   r&   r'   Úrun­  sJ   

ýÿþþúûýzinstall.runc                 C  sR   t j | j| jd ¡}| jr|  t|| jgfd|› �¡ dS |  	d|› d�¡ dS )zCreates the .pth fileú.pthz	creating zpath file 'z' not createdN)
r›   r¸   r¹   r·   rà   ry   rî   r   rº   rœ   )r€   Úfilenamer&   r&   r'   rë   ß  s   ÿzinstall.create_path_filec                 C  sh   g }|   ¡ D ]}|  |¡}| ¡ D ]}||vr| |¡ qq| jr2| jr2| tj | j	| jd ¡¡ |S )z.Assembles the outputs of all the sub-commands.rø   )
rê   Úget_finalized_commandrì   Úappendrà   ry   r›   r¸   r¹   r·   )r€   ró   rò   Úcmdrù   r&   r&   r'   rì   ë  s   

€þzinstall.get_outputsc                 C  s.   g }|   ¡ D ]}|  |¡}| | ¡ ¡ q|S )z*Returns the inputs of all the sub-commands)rê   rú   ÚextendÚ
get_inputs)r€   Úinputsrò   rü   r&   r&   r'   rþ   û  s
   
zinstall.get_inputsc                 C  s   | j  ¡ p	| j  ¡ S )zSReturns true if the current distribution has any Python
        modules to install.)r¢   Úhas_pure_modulesr´   r   r&   r&   r'   Úhas_lib  s   ÿzinstall.has_libc                 C  ó
   | j  ¡ S )zLReturns true if the current distribution has any headers to
        install.)r¢   Úhas_headersr   r&   r&   r'   r    ó   
zinstall.has_headersc                 C  r  )zMReturns true if the current distribution has any scripts to.
        install.)r¢   Úhas_scriptsr   r&   r&   r'   r    r  zinstall.has_scriptsc                 C  r  )zJReturns true if the current distribution has any data to.
        install.)r¢   Úhas_data_filesr   r&   r&   r'   Úhas_data  r  zinstall.has_datarr   rq   rs   rt   Úinstall_egg_infoc                 C  s   dS )NTr&   r   r&   r&   r'   Ú<lambda>$  s    zinstall.<lambda>)rg   rh   )!Ú__name__Ú
__module__Ú__qualname__ÚdescriptionrÆ   rc   Ú__annotations__r¬   rû   r   rf   r�   r¿   r�   rž   rŸ   rÎ   rÖ   r°   r²   rµ   r¶   r»   r³   r÷   rë   rì   rþ   r  r  r  r  Úsub_commandsr&   r&   r&   r'   r[   ®   sP   
 :
ý


M 
8

1

	



#
2
ûr[   )2Ú__doc__Ú
__future__r   r­   r)   r3   r›   r:   r!   Údistutils._logr   Úsiter   r   Útypingr   Úcorer   rÅ   r	   Úerrorsr
   r   Ú	file_utilr   r   Úutilr   r   r   r   rƒ   r   rQ   r¬   ÚWINDOWS_SCHEMEr.   rA   ÚschemesrY   r-   r5   r;   rF   rB   r?   r>   r=   rC   r[   r&   r&   r&   r'   Ú<module>   s˜    û
ù
ûûûç#
ú

ú
	