U
    X7h~u                  
   @   s  d 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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r6d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(d.d/ Z)d0d1 Z*d2d3 Z+d4d5 Z,d6d7 Z-d8d9 Z.G d:d; d;eZ/dS )<zFdistutils.command.install

Implements the Distutils 'install' command.    N)log)	USER_BASE	USER_SITE   )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pypyZ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   s4   t t  dd t D W  5 Q R  S Q R X d S )Nc                 S   s   i | ]}|t j|d dqS )F)expand)	sysconfig	get_paths.0scheme r#   _/var/www/formularioweb/env/lib/python3.8/site-packages/setuptools/_distutils/command/install.py
<dictcomp>c   s    z+_load_sysconfig_schemes.<locals>.<dictcomp>)
contextlibsuppressAttributeErrorr   get_scheme_namesr#   r#   r#   r$   _load_sysconfig_schemesa   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 | ]}|t |i  |i qS r#   )INSTALL_SCHEMESgetr    Zsysconfig_schemesr#   r$   r%   p   s
   

z!_load_schemes.<locals>.<dictcomp>)r*   set	itertoolschainr+   r#   r#   r-   r$   _load_schemesi   s    

r1   c                   C   s   t tdrdS dS d S )Npypy_version_infoPyPyPython)hasattrsysr#   r#   r#   r$   _get_implementationy   s    
r7   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    rB   c                    s    fdd|  D S )z1
    Include only attrs that are None in ob.
    c                    s$   i | ]\}}t  |d kr||qS r8   )getattr)r!   keyvaluer@   r#   r$   r%      s       z_remove_set.<locals>.<dictcomp>)items)r@   attrsr#   rF   r$   r>      s    r>   c                 C   sF   |  d\}}}zt|}W n" tk
r@   tt| }Y nX |S )N_)	partitionr   Zget_preferred_scheme	Exceptionfwr"   
_pypy_hack)rA   os_nameseprD   resolvedr#   r#   r$   r;      s    r;   c                 C   s
   t  |  S r8   )r1   )rA   r#   r#   r$   r:      s    r:   c                 C   s    t 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:   rM   
setdefault)rA   r"   fallbackr#   r#   r$   r9      s    	r9   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!   rD   r"   r#   r$   r%      s      z!_scheme_attrs.<locals>.<dictcomp>)SCHEME_KEYSrT   r#   rT   r$   r?      s    r?   c                 C   sF   t jdk }tt do|}| d }ddtjdk  }|rB|rB|S | S )N)      r2   )_user_homer   Z_ntr   )r6   version_infor5   endswithosrA   )rA   ZPY37Zold_pypyprefixZ	pypy_namer#   r#   r$   rM      s
    
rM   c                   @   s>  e Zd ZdZdddddddd	d
dddddddddgZdddgZerdeddde d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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFefdGefdHefdIefdJdKdL fgZdS )M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 filesr_   rc   re   userNzinstall in user site-package ''ra   c                 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)r]   exec_prefixhomerf   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_filerc   
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 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k
r   d}Y nX | j | j | j |dtjdd  dtjdd  |||||ttddt  t d}tttddddd}tr| j|d< | j|d< t j!"t#$ |t% |g| _&| '  | 
d | j|d< | j|d< t(rd	dl)m)} t*d |t| j& | +  | 
d | jr| ,  | j-dkrH| j. r@| j/| _-n| j0| _-| 1dddd d!d"dd | 2  | j-| _3tj45| j-| j6| _-| j7dk	r| 8d#dddd d!d" | 
d$ | 9d%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]   rh    z%d.%dr   z%d%d
platlibdirlib)Z	dist_nameZdist_versionZdist_fullname
py_versionpy_version_shortpy_version_nodotZ
sys_prefixr]   Zsys_exec_prefixrh   abiflagsr   Zimplementation_lowerimplementationwinver.)Zpy_version_nodot_platuserbaseZusersitezpost-expand_basedirs()baseplatbase)pprintzconfig vars:zpost-expand_dirs()r   r   r   r   r   Zlibbasezafter prepending rootbuild)rz   rz   )r{   r{   ):r]   rh   ri   rj   rk   r   rf   r\   rA   warn	dump_dirsfinalize_unixfinalize_otherr6   versionsplitr   r   r(   distributionget_nameget_versionget_fullnamerZ   rC   r7   lowerdictreplaceHAS_USER_SITErs   rt   jaracocollectionsZ	DictStackrL   r<   r   config_varsexpand_basedirsr   r   printexpand_dirscreate_home_pathrp   has_ext_modulesrn   rm   convert_pathshandle_extra_pathinstall_libbasepathjoin
extra_dirsrl   change_rootsset_undefined_options)r~   r   r]   rh   r   
local_varsZcompat_varsr   r#   r#   r$   finalize_optionsJ  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krx| 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_optionsnegative_opt	translaterC   )r~   msgr   optZopt_namevalr#   r#   r$   r     s    





zinstall.dump_dirsc                 C   s<  | j dk	s| jdk	r`| jdkr2| jdkr2| jdkpN| jdkpN| jdkpN| jdk}|r\tddS | j	r| j
dkrxtd| j
 | _ | _| d n| jdk	r| j | _ | _| d n| jdkr
| jdk	rtdttdd}tjtj| | _tjtj| | _n| jdk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   )rj   rk   rp   rm   rn   ro   rq   rr   r   rf   rs   r	   select_schemeri   r]   rh   rC   r   r\   r   normpathr6   )r~   Zincomplete_schemer   r#   r#   r$   r     sL    




zinstall.finalize_unixc                 C   s   | j r8| jdkrtd| j | _| _| tjd  n| jdk	r\| j | _| _| d n`| j	dkrvtj
tj	| _	| j	 | _| _z| tj W n& tk
r   tdtj dY nX dS )z)Finalizes options for non-posix platformsNr   rX   r   z&I don't know how to install stuff on 'rg   )rf   rs   r	   rj   rk   r   r\   rA   ri   r]   r   r   r6   KeyErrorr}   r#   r#   r$   r   F  s"    


zinstall.finalize_otherc                 C   s   t | | d S r8   )rB   )r~   rA   r#   r#   r$   r   \  s    zinstall.select_schemec                 C   sN   |D ]D}t | |}|d k	rtjdkr0tj|}t|| j}t| || qd S )N)r   r   )rC   r\   rA   r   
expanduserr   r   setattr)r~   rH   attrr   r#   r#   r$   _expand_attrs_  s    

zinstall._expand_attrsc                 C   s   |  dddg dS )zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.rj   rk   rl   Nr   r}   r#   r#   r$   r   h  s    zinstall.expand_basedirsc                 C   s   |  ddddddg dS )z+Calls `os.path.expanduser` on install dirs.rm   rn   rp   ro   rq   rr   Nr   r}   r#   r#   r$   r   m  s    zinstall.expand_dirsc                 G   s,   |D ]"}d| }t | |tt| | qdS )z!Call `convert_path` over `names`.rS   N)r   r   rC   r~   namesrA   r   r#   r#   r$   r   x  s    zinstall.convert_pathsc                 C   s   | j dkr| jj | _ | j dk	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   r   zY'extra_path' option must be a list, tuple, or comma-separated string with 1 or 2 elementsr   )rv   r   r   warning
isinstancestrr   lenr   r   	path_filer   )r~   r   r   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.rS   N)r   r   rl   rC   r   r#   r#   r$   r     s    zinstall.change_rootsc                 C   sf   | j s
dS ttjd}| j D ]<}t||r$tj	|s$| 
d| d t|d q$dS )zCreate directories under ~.N~zos.makedirs('z	', 0o700)i  )rf   r   r\   r   r   r   valuesr   
startswithisdirdebug_printmakedirs)r~   ri   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 d ttjjtj}ttjj|}tjtj| j}| jr"| j	r
| js"||kr"td| j dS )zRuns the command.r   z"Can't install when cross-compilingNz$writing list of installed files to 'rg   zmodules installed to '%s', which is not in Python's module search path (sys.path) -- you'll have to change the search path yourself)rx   run_commandr   get_command_obj	plat_namery   r   r	   get_sub_commandsr   create_path_filer|   get_outputsrl   r   rangeexecuter
   mapr\   r   r   r6   normcaserp   rw   r   r   )r~   Z
build_platcmd_nameoutputsZroot_lencounterZsys_pathrp   r#   r#   r$   run  sF    

zinstall.runc                 C   sP   t j| j| jd }| jr:| t|| jgfd|  n| 	d| d dS )zCreates the .pth file.pthz	creating zpath file 'z' not createdN)
r\   r   r   r   r   rw   r   r
   r   r   )r~   filenamer#   r#   r$   r     s     
 zinstall.create_path_filec                 C   sh   g }|   D ].}| |}| D ]}||k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   rw   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~   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   has_pure_modulesr   r}   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.)r   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.)r   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.)r   has_data_filesr}   r#   r#   r$   has_data  s    zinstall.has_datarp   ro   rq   rr   install_egg_infoc                 C   s   dS )NTr#   r}   r#   r#   r$   <lambda>*      zinstall.<lambda>) __name__
__module____qualname__descriptionr   boolean_optionsr   r   r   r   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^      sr   :


M 81	#2
r^   )0__doc__r&   r/   r\   r6   r   Zdistutils._logr   Zsiter   r   Zjaraco.collectionsr   corer   r   r   errorsr   r	   	file_utilr
   r   utilr   r   r   r   r   r   rL   r   ZWINDOWS_SCHEMEr+   r=   ZschemesrU   r*   r1   r7   rB   r>   r;   r:   r9   r?   rM   r^   r#   r#   r#   r$   <module>   s   

#



	