o
    !QdRn                     @   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 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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< qjqfeD ]=Z#ee# $ D ]4\ZZ%e&dde%Z%e%'ddZ%e%'ddZ%edkre%d7 Z%ej(dkredkre%'ddZ%e%ee# e< qqerdddd d!ded"< ddd#d$d!ded%< G d&d' d'eZ)dS )(zFdistutils.command.install

Implements the Distutils 'install' command.    N)log)Command)DEBUG)get_config_vars)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nt))r   posix_prefix)r   
posix_home)r   r   r   includez	\{(.+?)\}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)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| _tr/t| _t| _d| _d| _d| _d| _d| _d| _d| _d| _d| _d| _dS )zInitializes options.Nr      )prefixexec_prefixhomer&   install_baseinstall_platbaserootinstall_purelibinstall_platlibinstall_headersinstall_libinstall_scriptsinstall_dataHAS_USER_SITEr   install_userbaser   install_usersiter   optimize
extra_pathinstall_path_filer#   
skip_buildwarn_dir
build_base	build_librecordself rA   4/RAG/Python-3.10.13/Lib/distutils/command/install.pyinitialize_options   s4   
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rtd| jd< |    | 
d | j| jd< | j| jd< t!rd	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)Z	dist_nameZdist_versionZdist_fullname
py_versionpy_version_shortpy_version_nodotZ
sys_prefixr(   Zsys_exec_prefixr)   abiflags
platlibdiruserbaseZusersiteTsrcdirzpost-expand_basedirs()baseplatbase)pprintzconfig vars:zpost-expand_dirs()libr   r   r   r   r   Zlibbasezafter prepending rootbuild)r<   r<   )r=   r=   )3r(   r)   r*   r+   r,   r   r&   osnamewarn	dump_dirsfinalize_unixfinalize_othersysversionsplitr   rJ   AttributeErrordistributionget_nameget_versionget_fullnameversion_inforK   config_varsr4   r5   r6   	sysconfigis_python_buildget_config_varexpand_basedirsr   rP   printexpand_dirscreate_home_pathr1   ext_modulesr/   r.   convert_pathshandle_extra_pathinstall_libbasepathjoin
extra_dirsr-   change_rootsset_undefined_options)r@   rG   r(   r)   rJ   rP   rA   rA   rB   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_getoptrt   r   debuguser_optionsnegative_opt	translategetattr)r@   msgrt   optZopt_namevalrA   rA   rB   rV     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du rz| jdurit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 prefixr   )r+   r,   r1   r.   r/   r0   r2   r3   r   r&   r5   r   select_schemer*   r(   r)   rS   rn   normpathrY   r?   rA   rA   rB   rW     sB   










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   Z_userr   z)I don't know how to install stuff on '%s')r&   r5   r   r+   r,   r   rS   rT   r*   r(   rn   r   rY   KeyErrorr?   rA   rA   rB   rX     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)r@   rT   schemekeyattrnamerA   rA   rB   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 )NrD   r   )r}   rS   rT   rn   
expanduserr	   rb   r   )r@   attrsattrr   rA   rA   rB   _expand_attrs  s   
zinstall._expand_attrsc                 C      |  g d dS )zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.)r+   r,   r-   Nr   r?   rA   rA   rB   rf     s   zinstall.expand_basedirsc                 C   r   )z+Calls `os.path.expanduser` on install dirs.)r.   r/   r1   r0   r2   r3   Nr   r?   rA   rA   rB   rh     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}   r@   namesrT   r   rA   rA   rB   rk     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   rF   zY'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elementsrE   )r8   r]   r   rU   
isinstancestrr[   lenr   r   	path_filerp   )r@   r   rp   rA   rA   rB   rl      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
   r-   r}   r   rA   rA   rB   rq   "  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   rS   rn   r   rb   items
startswithisdirdebug_printmakedirs)r@   r*   rT   rn   rA   rA   rB   ri   (  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rtd| j dS dS dS dS )zRuns the command.rR   z"Can't install when cross-compilingNz'writing list of installed files to '%s'zmodules installed to '%s', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself)r:   run_commandr]   get_command_obj	plat_namer;   r   r   get_sub_commandsr   create_path_filer>   get_outputsr-   r   rangeexecuter   maprS   rn   r   rY   normcaser1   r9   r   ry   )r@   Z
build_platcmd_nameoutputsZroot_lenZcounterZsys_pathr1   rA   rA   rB   run4  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)
rS   rn   ro   rm   r   r9   r   r   rp   rU   )r@   filenamerA   rA   rB   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   r9   rS   rn   ro   rm   )r@   r   r   cmdr   rA   rA   rB   r   n  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@   Zinputsr   r   rA   rA   rB   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_moduleshas_ext_modulesr?   rA   rA   rB   has_lib  s   
zinstall.has_libc                 C   
   | j  S )zLReturns true if the current distribution has any headers to
        install.)r]   has_headersr?   rA   rA   rB   r        
zinstall.has_headersc                 C   r   )zMReturns true if the current distribution has any scripts to.
        install.)r]   has_scriptsr?   rA   rA   rB   r     r   zinstall.has_scriptsc                 C   r   )zJReturns true if the current distribution has any data to.
        install.)r]   has_data_filesr?   rA   rA   rB   has_data  r   zinstall.has_datar1   r0   r2   r3   Zinstall_egg_infoc                 C   s   dS )NTrA   r?   rA   rA   rB   <lambda>  s    zinstall.<lambda>) __name__
__module____qualname__descriptionrz   boolean_optionsr4   r   r   r{   rC   rs   rV   rW   rX   r   r   rf   rh   rk   rl   rq   ri   r   r   r   r   r   r   r   r   sub_commandsrA   rA   rA   rB   r   Z   sL    ;
O (		",
r   )*__doc__rY   rc   rS   re	distutilsr   distutils.corer   distutils.debugr   distutils.sysconfigr   distutils.errorsr   distutils.file_utilr   distutils.utilr   r	   r
   r   r   Zsiter   r   r4   r   r   r   Zdistutils_scheme_nameZsys_scheme_nameZsys_key_INSTALL_SCHEMESZ
sys_schemeZmain_keyr   valuesubreplacera   r   rA   rA   rA   rB   <module>   sh    

	

