a
    0`p                  	   @   s:  d 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 dZddddddZddddddddddddddddddd d!d"ddded#Zer"d$d$d%d&d'ded(< d$d$d)d*d'ded+< dZ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_SITETz$base/Lib/site-packagesz$base/Include/$dist_namez$base/Scriptsz$base)purelibplatlibheadersscriptsdataz/$base/lib/python$py_version_short/site-packagesz;$platbase/$platlibdir/python$py_version_short/site-packagesz9$base/include/python$py_version_short$abiflags/$dist_namez	$base/binz5$base/local/lib/python$py_version_short/dist-packagesz9$platbase/local/lib/python$py_version_short/dist-packagesz6$base/local/include/python$py_version_short/$dist_namez$base/local/binz$base/localz$base/lib/python3/dist-packagesz#$platbase/lib/python3/dist-packagesz0$base/include/python$py_version_short/$dist_namez$base/lib/pythonz$base/$platlibdir/pythonz$base/include/python/$dist_name)unix_prefix
unix_local
deb_system	unix_homentz	$usersitez4$userbase/Python$py_version_nodot/Include/$dist_namez)$userbase/Python$py_version_nodot/Scriptsz	$userbaseZ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| _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_datar   install_userbaser   install_usersiteinstall_layout	multiarchr   optimize
extra_pathinstall_path_filer   
skip_buildwarn_dir
build_base	build_librecordself r?   //usr/lib/python3.9/distutils/command/install.pyinitialize_options   s8    zinstall.initialize_optionsc                 C   sz  | j s| js| jr&| js| jr&td| jr@| j s8| jr@td| jrl| j sd| jsd| jsd| jsd| jrltdtjdkr| jr| 	d d| _| 
d tjdkr|   n|   | 
d tj d	 }td
d\}}z
tj}W n ty   d}Y n0 | j | j | j |dtjdd  dtjdd  |||||tjd| _trh| j| jd< | j| 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dd | (  | j#| _)tj*+| j#| j,| _#| j-dur^| .d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%    z%d.%d   z%d%d)Z	dist_nameZdist_versionZdist_fullname
py_versionZpy_version_shortZpy_version_nodotZ
sys_prefixr$   Zsys_exec_prefixr%   abiflags
platlibdirZuserbaseZusersitezpost-expand_basedirs()baseZplatbase)pprintzconfig vars:zpost-expand_dirs()Zlibr   r   r   r   r   Zlibbasezafter prepending rootbuild)r:   r:   )r;   r;   )0r$   r%   r&   r(   r)   r   r"   osnamewarn	dump_dirsfinalize_unixfinalize_othersysversionsplitr   rF   AttributeErrordistributionZget_nameZget_versionZget_fullnameversion_inforG   config_varsHAS_USER_SITEr1   r2   expand_basedirsr   rI   printexpand_dirscreate_home_pathr.   Zext_modulesr,   r+   convert_pathshandle_extra_pathinstall_libbasepathjoin
extra_dirsr*   change_rootsZset_undefined_options)r>   rE   r$   r%   rF   rI   r?   r?   r@   finalize_options   s    














	
zinstall.finalize_optionsc                 C   s   t sdS ddlm} t|d  | jD ]r}|d }|d dkrL|dd }|| jv rx| j| }||}t| | }n||}t| |}td|| q(dS )zDumps the list of user options.Nr   )longopt_xlate:=z  %s: %s)	r   Zdistutils.fancy_getoptre   r   debuguser_optionsnegative_opt	translategetattr)r>   msgre   ZoptZopt_namevalr?   r?   r@   rN     s    





zinstall.dump_dirsc                 C   s  | j dus| jdur\| jdu r2| jdu r2| jdu sP| jdu sP| jdu sP| jdu rXtddS | j	r| j
du rttd| j
 | _ | _| d n~| jdur| j | _ | _| d nX| j| _| jdu r| jdurtdtjtj| _tjtj| _n| jdu r| j| _| j| _ | j| _| jr~| j dv rXddl}|d	| _| d
 n$| j dv rt| d ntdn| jrtj| jdkstjtjksdtjv sdtjv sdtjv r| d n6t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)Zdebr   Z	MULTIARCHr   )Zunixr   z"unknown value for --install-layoutz
/usr/localZPYTHONUSERBASEZVIRTUAL_ENVZreal_prefixz/usrr   )r(   r)   r.   r+   r,   r-   r/   r0   r   r"   r1   r   select_schemer&   r$   r'   r%   rK   r`   normpathrQ   r3   lower	sysconfigZget_config_varr4   base_prefixenviron__dict__)r>   rt   r?   r?   r@   rO     s    





zinstall.finalize_unixc                 C   s   | j r8| jdu rtd| j | _| _| tjd  n~| jdur\| j | _| _| d nZ| j	du rvtj
tj	| _	| j	 | _| _z| tj W n  ty   tdtj Y n0 dS )z)Finalizes options for non-posix platformsNrp   Z_userr   z)I don't know how to install stuff on '%s')r"   r1   r   r(   r)   rq   rK   rL   r&   r$   r`   rr   rQ   KeyErrorr=   r?   r?   r@   rP     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_KEYSrm   setattr)r>   rL   Zschemekeyattrnamer?   r?   r@   rq     s
    zinstall.select_schemec                 C   sX   |D ]N}t | |}|d urtjdks.tjdkr:tj|}t|| j}t| || qd S )NrB   r   )rm   rK   rL   r`   
expanduserr	   rW   r|   )r>   attrsattrro   r?   r?   r@   _expand_attrs  s    
zinstall._expand_attrsc                 C   s   |  g d dS )zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.)r(   r)   r*   Nr   r=   r?   r?   r@   rY     s    zinstall.expand_basedirsc                 C   s   |  g d dS )z+Calls `os.path.expanduser` on install dirs.)r+   r,   r.   r-   r/   r0   Nr   r=   r?   r?   r@   r[   
  s    zinstall.expand_dirsc                 G   s,   |D ]"}d| }t | |tt| | qdS )z!Call `convert_path` over `names`.ry   N)r|   r   rm   r>   namesrL   r   r?   r?   r@   r]     s    zinstall.convert_pathsc                 C   s   | j du r| jj | _ | j durtd t| j trB| j d| _ t| j dkr`| j d  }}n"t| j dkrz| 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   rD   zY'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elementsrC   )r6   rU   r   rM   
isinstancestrrS   lenr   r   	path_filerb   )r>   r   rb   r?   r?   r@   r^     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.ry   N)r|   r
   r*   rm   r   r?   r?   r@   rc   8  s    zinstall.change_rootsc                 C   sb   | j s
dS ttjd}| j D ]8\}}||r$tj|s$| 	d|  t
|d q$dS )zCreate directories under ~.N~zos.makedirs('%s', 0o700)i  )r"   r   rK   r`   r   rW   items
startswithisdirZdebug_printmakedirs)r>   r&   rL   r`   r?   r?   r@   r\   >  s    zinstall.create_home_pathc                 C   s"  | j s6| d | jdj}| jr6|t kr6td|  D ]}| | q>| j	r\| 
  | jr|  }| jrt| j}tt|D ]}|| |d ||< q| 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 )zRuns the command.rJ   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)r8   Zrun_commandrU   Zget_command_objZ	plat_namer9   r   r   get_sub_commandsr   create_path_filer<   get_outputsr*   r   rangeexecuter   maprK   r`   rr   rQ   normcaser.   r7   r   ri   )r>   Z
build_platcmd_nameoutputsZroot_lenZcounterZsys_pathr.   r?   r?   r@   runJ  sD    

zinstall.runc                 C   sJ   t j| j| jd }| jr8| t|| jgfd|  n| 	d|  dS )zCreates the .pth file.pthzcreating %szpath file '%s' not createdN)
rK   r`   ra   r_   r   r7   r   r   rb   rM   )r>   filenamer?   r?   r@   r   v  s    

zinstall.create_path_filec                 C   sh   g }|   D ].}| |}| D ]}||vr"|| q"q| jrd| jrd|tj| j	| jd  |S )z.Assembles the outputs of all the sub-commands.r   )
r   get_finalized_commandr   appendr   r7   rK   r`   ra   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>   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.)rU   Zhas_pure_modulesZhas_ext_modulesr=   r?   r?   r@   has_lib  s    
zinstall.has_libc                 C   s
   | j  S )zLReturns true if the current distribution has any headers to
        install.)rU   has_headersr=   r?   r?   r@   r     s    zinstall.has_headersc                 C   s
   | j  S )zMReturns true if the current distribution has any scripts to.
        install.)rU   has_scriptsr=   r?   r?   r@   r     s    zinstall.has_scriptsc                 C   s
   | j  S )zJReturns true if the current distribution has any data to.
        install.)rU   Zhas_data_filesr=   r?   r?   r@   has_data  s    zinstall.has_datar.   r-   r/   r0   Zinstall_egg_infoc                 C   s   dS )NTr?   r=   r?   r?   r@   <lambda>      zinstall.<lambda>) __name__
__module____qualname__Zdescriptionrj   Zboolean_optionsrX   r   r   rk   rA   rd   rN   rO   rP   rq   r   rY   r[   r]   r^   rc   r\   r   r   r   r   r   r   r   r   Zsub_commandsr?   r?   r?   r@   r   W   sJ   >
S >		",
r   )__doc__rQ   rK   Z	distutilsr   Zdistutils.corer   Zdistutils.debugr   Zdistutils.sysconfigr   Zdistutils.errorsr   Zdistutils.file_utilr   Zdistutils.utilr   r	   r
   r   r   Zsiter   r   rX   ZWINDOWS_SCHEMErz   r{   r   r?   r?   r?   r@   <module>   sz   
!
	
