o
    5hxu                  
   @  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"rd 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ntZpypyZpypy_ntz
{usersite}zF{userbase}/{implementation}{py_version_nodot_plat}/Include/{dist_name}z:{userbase}/{implementation}{py_version_nodot_plat}/Scriptsz
{userbase}Z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)	sysconfigZ	get_paths.0scheme r"   Elib/python3.10/site-packages/setuptools/_distutils/command/install.py
<dictcomp>e   s    z+_load_sysconfig_schemes.<locals>.<dictcomp>)
contextlibsuppressAttributeErrorr   Z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   Zsysconfig_schemesr"   r#   r$   r   s    

z!_load_schemes.<locals>.<dictcomp>)r(   set	itertoolschainr)   r"   r"   r+   r#   _load_schemesk   s   

r/   c                   C  s   t tdrdS dS )NZpypy_version_infoZPyPyPython)hasattrsysr"   r"   r"   r#   _get_implementation{   s   
r3   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   r>   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 r4   )getattr)r    keyvaluer<   r"   r#   r$      s   $ z_remove_set.<locals>.<dictcomp>)items)r<   attrsr"   rB   r#   r:      s   r:   c                 C  s@   |  d\}}}zt|}W |S  ty   t| }Y |S w )N_)	partitionr   Zget_preferred_scheme	Exceptionfwr!   )r=   Zos_namesepr@   Zresolvedr"   r"   r#   r7      s   r7   c                 C  s
   t  |  S r4   )r/   )r=   r"   r"   r#   r6      s   
r6   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   )r6   
setdefault)r=   r!   fallbackr"   r"   r#   r5      s   	r5   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    r@   r!   r"   r#   r$      s    z!_scheme_attrs.<locals>.<dictcomp>)SCHEME_KEYSrM   r"   rM   r#   r;         r;   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)rQ   rU   rW   zClassVar[list[str]]boolean_optionsuserNzinstall in user site-package ''rS   rQ   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homerY   install_baseinstall_platbaserootinstall_purelibinstall_platlibinstall_headersinstall_libinstall_scriptsinstall_datar   install_userbaser   install_usersiterQ   optimize
extra_pathinstall_path_filerU   
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)rd	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j56| 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   r^   r_    .
platlibdirlib)Z	dist_nameZdist_versionZdist_fullname
py_versionZpy_version_shortZpy_version_nodotZ
sys_prefixr^   Zsys_exec_prefixr_   abiflagsrz   Zimplementation_lowerimplementationwinver)Zpy_version_nodot_platuserbaseZusersitezpost-expand_basedirs()baseZplatbase)pprintzconfig vars:zpost-expand_dirs()r   r   r   r   r   Zlibbasezafter prepending rootbuild)rq   rq   )rr   rr   );r^   r_   r`   ra   rb   r
   rY   osr=   warn	dump_dirsfinalize_unixfinalize_otherr2   versionsplitr   r}   r'   distributionZget_nameZget_versionZget_fullnameversion_infomajorminorr?   r3   lowerdictreplaceHAS_USER_SITErj   rk   collectionsChainMapr   rH   r8   config_varsexpand_basedirsr	   r   printexpand_dirscreate_home_pathrg   has_ext_modulesre   rd   convert_pathshandle_extra_pathinstall_libbasepathjoin
extra_dirsrc   change_rootsZset_undefined_options)ru   r|   r^   r_   r}   Z
local_varsZ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	   Zfancy_getoptr   r   debuguser_optionsr[   	translater?   )ru   msgr   optZ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_additionrx   r   )ra   rb   rg   rd   re   rf   rh   ri   r
   rY   rj   r   select_schemer`   r^   r_   r?   r   r   r   normpathr2   )ru   Z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 'rZ   )rY   rj   r   ra   rb   r   r   r=   r`   r^   r   r   r2   KeyErrorrt   r"   r"   r#   r   @  s$   


zinstall.finalize_otherc                 C  s   t | | d S r4   )r>   )ru   r=   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)rw   r   )r?   r   r=   r   
expanduserr   r   setattr)ru   rD   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.)ra   rb   rc   Nr   rt   r"   r"   r#   r   b  s   zinstall.expand_basedirsc                 C  r   )z+Calls `os.path.expanduser` on install dirs.)rd   re   rg   rf   rh   ri   Nr   rt   r"   r"   r#   r   g  rO   zinstall.expand_dirsc                 G  s,   |D ]}d| }t | |tt| | qdS )z!Call `convert_path` over `names`.rL   N)r   r   r?   ru   namesr=   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 elementsrx   )rm   r   r   Zwarning
isinstancestrr   lenr
   r   	path_filer   )ru   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.rL   N)r   r   rc   r?   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  )rY   r   r   r   r   r   valuesr   
startswithisdirZdebug_printmakedirs)ru   r`   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rt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 'rZ   zmodules installed to '%s', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself)ro   Zrun_commandr   Zget_command_objZ	plat_namerp   r   r   get_sub_commandsr   create_path_filers   get_outputsrc   r   rangeexecuter   mapr   r   r   r2   normcaserg   rn   r   r   )ru   Z
build_platcmd_nameoutputsZroot_lenZcounterZsys_pathrg   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   rn   r   r   r   r   )ru   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   rn   r   r   r   r   )ru   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)ru   Z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   Zhas_pure_modulesr   rt   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_headersrt   r"   r"   r#   r        
zinstall.has_headersc                 C  r   )zMReturns true if the current distribution has any scripts to.
        install.)r   has_scriptsrt   r"   r"   r#   r     r   zinstall.has_scriptsc                 C  r   )zJReturns true if the current distribution has any data to.
        install.)r   Zhas_data_filesrt   r"   r"   r#   has_data  r   zinstall.has_datarg   rf   rh   ri   Zinstall_egg_infoc                 C  s   dS )NTr"   rt   r"   r"   r#   <lambda>$  s    zinstall.<lambda>)r\   r]   )!__name__
__module____qualname__descriptionr   rX   __annotations__r   r   r   r[   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zsub_commandsr"   r"   r"   r#   rP      sP   
 :



M 
8

1

	



#
2
rP   )2__doc__Z
__future__r   r   r%   r-   r   r2   r   Zdistutils._logr   Zsiter   r   typingr   corer   r   r	   errorsr
   r   Z	file_utilr   r   utilr   r   r   r   rx   r   rH   r   ZWINDOWS_SCHEMEr)   r9   ZschemesrN   r(   r/   r3   r>   r:   r7   r6   r5   r;   rP   r"   r"   r"   r#   <module>   s    

#



	