o
    Š�bcRx  ã                
   @   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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 dd
lmZ ddlmZ ddlmZ ddlmZ eduZdZi i i dœZddddddddddœ	ed< ddddddddddœ	ed< eD ]"Zd D ]\ZZ eZ!ej"e  Z#ed!kr�ee#vr�d"Z!e#e! ee e< qˆq„eD ]=Z$ee$  %¡ D ]4\ZZ&e 'd#d$e&¡Z&e& (d%d&¡Z&e& (d'd(¡Z&ed!krÐe&d)7 Z&ej)d*krßed+krße& (d,d-¡Z&e&ee$ e< q±q©erýd.d.d/d0d1dœed2< d.d.d3d4d1dœed5< G d6d7„ d7eƒZ*dS )8zFdistutils.command.install

Implements the Distutils 'install' command.é    N)Úlog)ÚCommand)ÚDEBUG)Úget_config_varsÚis_virtual_environment)ÚDistutilsPlatformError)Ú
write_file)Úconvert_pathÚ
subst_varsÚchange_root)Úget_platform)ÚDistutilsOptionError)Ú	USER_BASE)Ú	USER_SITE)ÚpurelibÚplatlibÚheadersÚscriptsÚdata)Úunix_prefixÚ	unix_homeÚntz6{installed_base}/{platlibdir}/python{py_version_short}z0{platbase}/{platlibdir}/python{py_version_short}z7{base}/local/lib/python{py_version_short}/dist-packageszD{platbase}/local/{platlibdir}/python{py_version_short}/dist-packagesz;{installed_base}/include/python{py_version_short}{abiflags}z7{base}/local/include/python{py_version_short}{abiflags}z?{installed_platbase}/include/python{py_version_short}{abiflags}z{base}/local/binz{base}/local)	ÚstdlibÚ
platstdlibr   r   Úincluder   Úplatincluder   r   Ú
unix_localz {base}/lib/python3/dist-packagesz-{platbase}/{platlibdir}/python3/dist-packagesz
{base}/binz{base}Ú
deb_system))r   Úposix_prefix)r   Ú
posix_home)r   r   r   r   z	\{(.+?)\}z$\g<1>z$installed_basez$basez$py_version_nodot_platz$py_version_nodotz/$dist_name)é   é	   r   z/lib/z/$platlibdir/z	$usersitez4$userbase/Python$py_version_nodot/Include/$dist_namez)$userbase/Python$py_version_nodot/Scriptsz	$userbaseÚnt_userz=$userbase/include/python$py_version_short$abiflags/$dist_namez$userbase/binÚ	unix_userc                   @   s  e Zd ZdZg d¢Zg d¢Zere ddde f¡ e d¡ ddiZ	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3efd4efd5efd6efd7d8d9„ fgZdS ):Ú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)zinstall-layout=Nz7installation layout to choose (known values: deb, unix))r%   r)   r+   ÚuserNz!install in user site-package '%s'r'   r%   c                 C   s°   d| _ d| _d| _d| _d| _d| _d| _d| _d| _d| _	d| _
d| _d| _d| _tr2t| _t| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _dS )zInitializes options.Nr   é   )ÚprefixÚexec_prefixÚhomer,   Úprefix_optionÚinstall_baseÚinstall_platbaseÚrootÚinstall_purelibÚinstall_platlibÚinstall_headersÚinstall_libÚinstall_scriptsÚinstall_dataÚHAS_USER_SITEr   Úinstall_userbaser   Úinstall_usersiteÚinstall_layoutÚ	multiarchr%   ÚoptimizeÚ
extra_pathÚinstall_path_filer)   Ú
skip_buildÚwarn_dirÚ
build_baseÚ	build_libÚrecord©Úself© rJ   ú0/usr/lib/python3.10/distutils/command/install.pyÚinitialize_options¾   s:   
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 ¡ |dtjdd…  dtjdd…  |||||tjdœ| _tr³| j| jd< | j| jd< t d¡rÀt d¡| jd< |   ¡  |  
d¡ | j| jd< | j| jd< t!ræd	dl"m"} t#dƒ || jƒ |  $¡  |  
d¡ | jrö|  %¡  | j&du �r
| jj'�r| j(| _&n| j)| _&|  *dddddd ¡ t�r|  *dd¡ |  +¡  | j&| _,tj- .| j&| j/¡| _&| j0du�r@|  1d!dddddd ¡ |  
d"¡ |  2d#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   r.   r/   Ú z%d.%dé   z%d%d)Ú	dist_nameÚdist_versionÚdist_fullnameÚ
py_versionÚpy_version_shortÚpy_version_nodotÚ
sys_prefixr.   Úsys_exec_prefixr/   ÚabiflagsÚ
platlibdirÚuserbaseÚusersiteTÚsrcdirzpost-expand_basedirs()ÚbaseÚplatbase)Úpprintzconfig vars:zpost-expand_dirs()Úlibr   r   r   r   r   Úlibbasezafter prepending rootÚbuild)rE   rE   )rF   rF   )3r.   r/   r0   r2   r3   r   r,   ÚosÚnameÚwarnÚ	dump_dirsÚfinalize_unixÚfinalize_otherÚsysÚversionÚsplitr   rX   ÚAttributeErrorÚdistributionÚget_nameÚget_versionÚget_fullnameÚversion_inforY   Úconfig_varsr;   r<   r=   Ú	sysconfigÚis_python_buildÚget_config_varÚexpand_basedirsr   r_   ÚprintÚexpand_dirsÚcreate_home_pathr8   Úext_modulesr6   r5   Úconvert_pathsÚhandle_extra_pathÚinstall_libbaseÚpathÚjoinÚ
extra_dirsr4   Úchange_rootsÚset_undefined_options)rI   rS   r.   r/   rX   r_   rJ   rJ   rK   Úfinalize_options  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ú:éÿÿÿÿú=z  %s: %s)	r   Údistutils.fancy_getoptr„   r   ÚdebugÚuser_optionsÚnegative_optÚ	translateÚgetattr)rI   Úmsgr„   ÚoptÚopt_nameÚvalrJ   rJ   rK   rf   ¬  s    





õzinstall.dump_dirsc                 C   sÜ  | j dus
| jdur.| jdu r| jdu r| jdu s(| jdu s(| jdu s(| jdu r,tdƒ‚dS | j	rH| j
du r:tdƒ‚| j
 | _ | _|  d¡ dS | jdur[| j | _ | _|  d¡ dS | j| _| jdu r~| jdurmtdƒ‚tj tj¡| _tj tj¡| _n	| jdu r‡| j| _| j| _ | j| _| jr¼| j ¡ dv rªddl}| d	¡| _|  d
¡ dS | j ¡ dv r¸|  d¡ dS tdƒ‚| jrÈtj | j¡dksËtƒ rÒ|  d¡ dS tj | j¡dkrçd | _| _d | _ | _|  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)Údebr   Ú	MULTIARCHr   )Úunixr   z"unknown value for --install-layoutz
/usr/localz/usrr   )r2   r3   r8   r5   r6   r7   r9   r:   r   r,   r<   r   Úselect_schemer0   r.   r1   r/   rc   r~   Únormpathri   r>   Úlowerrs   ru   r?   r   )rI   rs   rJ   rJ   rK   rg   ¿  sh   





ÿ
ÿ


ÿ
ÿÿ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 ƒ‚w )z)Finalizes options for non-posix platformsNr’   Ú_userr   z)I don't know how to install stuff on '%s')r,   r<   r   r2   r3   r–   rc   rd   r0   r.   r~   r—   ri   ÚKeyErrorrH   rJ   rJ   rK   rh   ú  s(   
ÿ

ÿÿzinstall.finalize_otherc                 C   s<   t | }tD ]}d| }t| |ƒdu rt| ||| ƒ qdS )z=Sets the install directories by applying the install schemes.Úinstall_N)ÚINSTALL_SCHEMESÚSCHEME_KEYSr�   Úsetattr)rI   rd   ÚschemeÚkeyÚattrnamerJ   rJ   rK   r–     s   €ýzinstall.select_schemec                 C   sX   |D ]'}t | |ƒ}|d ur)tjdkstjdkrtj |¡}t|| jƒ}t| ||ƒ qd S )NrM   r   )r�   rc   rd   r~   Ú
expanduserr
   rr   rž   )rI   ÚattrsÚattrr‘   rJ   rJ   rK   Ú_expand_attrs  s   
€úzinstall._expand_attrsc                 C   ó   |   g d¢¡ dS )zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.)r2   r3   r4   N©r¥   rH   rJ   rJ   rK   rv   "  s   zinstall.expand_basedirsc                 C   r¦   )z+Calls `os.path.expanduser` on install dirs.)r5   r6   r8   r7   r9   r:   Nr§   rH   rJ   rJ   rK   rx   '  s   zinstall.expand_dirsc                 G   s,   |D ]}d| }t | |tt| |ƒƒƒ qdS )z!Call `convert_path` over `names`.r›   N)rž   r	   r�   ©rI   Únamesrd   r¤   rJ   rJ   rK   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   rO   zY'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elementsrN   )rA   rm   r   re   Ú
isinstanceÚstrrk   Úlenr   r	   Ú	path_filer€   )rI   r®   r€   rJ   rJ   rK   r|   3  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.r›   N)rž   r   r4   r�   r¨   rJ   rJ   rK   r�   U  s   þzinstall.change_rootsc                 C   sb   | j sdS ttj d¡ƒ}| j ¡ D ]\}}| |¡r.tj |¡s.|  	d| ¡ t 
|d¡ qdS )zCreate directories under ~.Nú~zos.makedirs('%s', 0o700)iÀ  )r,   r	   rc   r~   r¢   rr   ÚitemsÚ
startswithÚisdirÚdebug_printÚmakedirs)rI   r0   rd   r~   rJ   rJ   rK   ry   [  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 ¡ 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.rb   z"Can't install when cross-compilingNz'writing list of installed files to '%s'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)rC   Úrun_commandrm   Úget_command_objÚ	plat_namerD   r   r   Úget_sub_commandsr®   Úcreate_path_filerG   Úget_outputsr4   r­   ÚrangeÚexecuter   Úmaprc   r~   r—   ri   Únormcaser8   rB   r   r‰   )rI   Ú
build_platÚcmd_nameÚoutputsÚroot_lenÚcounterÚsys_pathr8   rJ   rJ   rK   Úrung  sH   

ÿþÿÿýýþzinstall.runc                 C   sL   t j | j| jd ¡}| jr|  t|| jgfd| ¡ dS |  	d| ¡ dS )zCreates the .pth fileú.pthzcreating %szpath file '%s' not createdN)
rc   r~   r   r}   r®   rB   r¼   r   r€   re   )rI   ÚfilenamerJ   rJ   rK   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®   rB   rc   r~   r   r}   )rI   rÁ   rÀ   ÚcmdrÇ   rJ   rJ   rK   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)rI   ÚinputsrÀ   rÊ   rJ   rJ   rK   rÌ   ²  s
   
zinstall.get_inputsc                 C   s   | j  ¡ p	| j  ¡ S )zSReturns true if the current distribution has any Python
        modules to install.)rm   Úhas_pure_modulesÚhas_ext_modulesrH   rJ   rJ   rK   Úhas_lib¾  s   
ÿzinstall.has_libc                 C   ó
   | j  ¡ S )zLReturns true if the current distribution has any headers to
        install.)rm   Úhas_headersrH   rJ   rJ   rK   rÒ   Ä  ó   
zinstall.has_headersc                 C   rÑ   )zMReturns true if the current distribution has any scripts to.
        install.)rm   Úhas_scriptsrH   rJ   rJ   rK   rÔ   É  rÓ   zinstall.has_scriptsc                 C   rÑ   )zJReturns true if the current distribution has any data to.
        install.)rm   Úhas_data_filesrH   rJ   rJ   rK   Úhas_dataÎ  rÓ   zinstall.has_datar8   r7   r9   r:   Úinstall_egg_infoc                 C   s   dS )NTrJ   rH   rJ   rJ   rK   Ú<lambda>Ù  s    zinstall.<lambda>) Ú__name__Ú
__module__Ú__qualname__ÚdescriptionrŠ   Úboolean_optionsr;   rÉ   r   r‹   rL   rƒ   rf   rg   rh   r–   r¥   rv   rx   r{   r|   r�   ry   rÅ   r¹   rº   rÌ   rÐ   rÒ   rÔ   rÖ   Úsub_commandsrJ   rJ   rJ   rK   r$   r   sL    >ÿ
T ;		",
ür$   )+Ú__doc__ri   rs   rc   ÚreÚ	distutilsr   Údistutils.corer   Údistutils.debugr   Údistutils.sysconfigr   r   Údistutils.errorsr   Údistutils.file_utilr   Údistutils.utilr	   r
   r   r   r   Úsiter   r   r;   r�   rœ   r    Údistutils_scheme_nameÚsys_scheme_nameÚsys_keyÚ_INSTALL_SCHEMESÚ
sys_schemeÚmain_keyr°   ÚvalueÚsubÚreplacerq   r$   rJ   rJ   rJ   rK   Ú<module>   s�    
÷
÷
ôö
û	
ú
