Current File : //lib/python3.9/site-packages/pip/_internal/operations/install/__pycache__/wheel.cpython-39.pyc
a

[��fk�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'm(Z(ddl)m*Z*dd	l+m,Z,dd
l-m.Z.ddl/m0Z0ddl1m2Z2dd
l3m4Z4m5Z5m6Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<ddl=m>Z>m?Z?ddl@mAZAmBZBmCZCmDZDddlEmFZFmGZGmHZHmIZIddlJmKZKe�r�ddlmLZLGdd�deL�ZMe�NeO�ZPedeQ�ZRe#eReQe$eSeQffZTdPeQeSe#eQeQfd�dd�ZUeQeeQefd�dd�ZVeQeWd�d d!�ZXeeWd"�d#d$�ZYe4e#eeQeQfeeQeQffd%�d&d'�ZZe!eQe eQd(�d)d*�Z[eeTee#eQeQeQfd+�d,d-�Z\eReQd.�d/d0�Z]dQeQe eQeRd1�d2d3�Z^eeeQeeReRfe"eReeQeQeeTd4�d5d6�Z_eeQeQfeeQd7�d8d9�Z`Gd:d;�d;�ZaGd<d=�d=�ZbGd>d?�d?e0�ZceQdd@�dAdB�ZdGdCdD�dDe*�ZedReQe'eQe<eWeWe e9eWddG�	dHdI�ZfejgeQeddJ�dKdL��ZhdSeQeQe<eQeWeWe e9eWddM�	dNdO�ZidS)TzGSupport for installing and building the "wheel" binary package format.
�N)�urlsafe_b64encode)�Message)�chain�filterfalse�starmap)�IO�
TYPE_CHECKING�Any�BinaryIO�Callable�Dict�Iterable�Iterator�List�NewType�Optional�Sequence�Set�Tuple�Union�cast)�ZipFile�ZipInfo)�ScriptMaker)�get_export_entry)�canonicalize_name)�InstallationError)�get_major_minor_version)�BaseDistribution�FilesystemWheel�get_wheel_distribution)�DIRECT_URL_METADATA_NAME�	DirectUrl)�SCHEME_KEYS�Scheme)�adjacent_tmp_file�replace)�captured_stdout�
ensure_dir�	hash_file�	partition)�
current_umask�is_within_directory�2set_extracted_file_to_default_mode_plus_executable�zip_item_is_executable)�parse_wheel)�Protocolc@s4eZdZUded<eed<eed<dd�dd�ZdS)	�File�
RecordPath�src_record_path�	dest_path�changedN��returncCsdS�N���selfr9r9�J/usr/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py�saveEsz	File.save)�__name__�
__module__�__qualname__�__annotations__�str�boolr=r9r9r9r<r1@s
r1r2�)�path�	blocksizer7cCs6t||�\}}dt|����d��d�}|t|�fS)z?Return (encoded_digest, length) for path using hashlib.sha256()zsha256=�latin1�=)r)r�digest�decode�rstriprB)rErF�h�lengthrIr9r9r<�rehashOsrN)�moder7cCs|ddd�S)zPReturn keyword arguments to properly open a CSV file
    in the given mode.
    ��utf-8)rO�newline�encodingr9)rOr9r9r<�
csv_io_kwargsVsrT�rEr7cCs�tj�|�sJ�t|d��^}|��}|�d�s>Wd�dStj�t�	��}d|tj
�d�}|��}Wd�n1s~0Yt|d��$}|�|�|�|�Wd�n1s�0YdS)	zQReplace #!python with #!/path/to/python
    Return True if file was changed.
    �rbs#!pythonNFs#!�ascii�wbT)
�osrE�isfile�open�readline�
startswith�sys�
executable�encode�getfilesystemencoding�linesep�read�write)rEZscript�	firstlineZexename�restr9r9r<�
fix_script]s
&
(rg)�metadatar7cCs|�dd���dkS)NzRoot-Is-PurelibrP�true)�get�lower)rhr9r9r<�wheel_root_is_purelibqsrl)�distr7cCsLi}i}|��D]2}|jdkr,|j||j<q|jdkr|j||j<q||fS)N�console_scripts�gui_scripts)Ziter_entry_points�group�value�name)rmrnro�entry_pointr9r9r<�get_entrypointsus

rt)�scriptsr7c
s�|sdSt�t�}|D]*}tj�|�}tj�|�}||�|�qdd�tj�	dd��
tj�D����tj�
tj�tj����fdd�|��D�}|s�dSg}|��D]b\}}t|�}t|�dkr�d	�|d
�}	n$d�d�|dd
��d|d
�}	|�d�|	|��q�d}
t|�dk�r0|�|
�d��n|�|
�d��tdd�tj�	dd��
tj�D��}|�rxd}|�|�d�|�S)z�Determine if any scripts are not on PATH and format a warning.
    Returns a warning message if one or more scripts are not on PATH,
    otherwise None.
    NcSs g|]}tj�|��tj��qSr9)rYrE�normcaserK�sep��.0�ir9r9r<�
<listcomp>�s�z5message_about_scripts_not_on_PATH.<locals>.<listcomp>�PATHrPcs&i|]\}}tj�|��vr||�qSr9)rYrErv)ry�
parent_dirru�Z
not_warn_dirsr9r<�
<dictcomp>�s�z5message_about_scripts_not_on_PATH.<locals>.<dictcomp>�zscript {} isrzscripts {} are�, ���z and z.The {} installed in '{}' which is not on PATH.zeConsider adding {} to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.zthis directoryzthese directoriescss|]}|r|ddkVqdS)r�~Nr9rxr9r9r<�	<genexpr>�sz4message_about_scripts_not_on_PATH.<locals>.<genexpr>ziNOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.�
)�collections�defaultdict�setrYrE�dirname�basename�add�environrj�split�pathsep�appendrvr^r_�items�sorted�len�format�join�any)
ruZgrouped_by_dir�destfiler}�script_nameZwarn_for�	msg_linesZdir_scriptsZsorted_scriptsZ
start_textZ
last_line_fmtZwarn_for_tildeZtilde_warning_msgr9r~r<�!message_about_scripts_not_on_PATH�sT
�
�������
r�)�outrowsr7cCstdd�|D��S)a�Normalize the given rows of a RECORD file.

    Items in each row are converted into str. Rows are then sorted to make
    the value more predictable for tests.

    Each row is a 3-tuple (path, hash, size) and corresponds to a record of
    a RECORD file (see PEP 376 and PEP 427 for details).  For the rows
    passed to this function, the size can be an integer as an int or string,
    or the empty string.
    css"|]\}}}||t|�fVqdSr8)rB)ry�record_pathZhash_�sizer9r9r<r��sz&_normalized_outrows.<locals>.<genexpr>)r�)r�r9r9r<�_normalized_outrows�s�r��r�r7cCs|Sr8r9)r�r9r9r<�_record_to_fs_path�sr�)rE�relative_tor7cCsX|dur>tj�|�d��tj�|�d��kr>tj�||�}|�tjjd�}td|�S)Nr�/r2)rYrE�
splitdriverk�relpathr&rwr)rEr�r9r9r<�_fs_to_record_path�s��r�)�old_csv_rows�	installedr5�	generated�lib_dirr7cCs�g}|D]�}t|�dkr$t�d|�td|d�}|�||�}||vrXtt|��\}	}
n0t|�dkrl|dnd}	t|�dkr�|dnd}
|�||	|
f�q|D]*}t||�}t|�\}	}
|�||	|
f�q�|�	�D]}
|�|
ddf�q�|S)z_
    :param installed: A map from archive RECORD path to installation RECORD
        path.
    �z,RECORD line has more than three elements: %sr2rr�rP�)
r��logger�warningr�poprNr�r�r��values)r�r�r5r�r�Zinstalled_rows�rowZold_record_pathZnew_record_pathrIrM�frEZinstalled_record_pathr9r9r<�get_csv_rows_for_installed�s$
r�)�consoler7cCs|��}g}|�dd�}|r�dtjvr4|�d|�tj�dd�dkr^|�d�tjd|��|�dt	��d	|���d
d�|D�}|D]
}||=q�|�dd�}|r�dtjvr�|�d
|�|�d�t	�|��dd�|D�}|D]
}||=q�|�
tdj|����|S)zk
    Given the mapping from entrypoint name to callable, return the relevant
    console script specs.
    ZpipNZENSUREPIP_OPTIONSzpip = rPZ
altinstallz
pip{} = {}rz = cSsg|]}t�d|�r|�qS)zpip(\d(\.\d)?)?$��re�match�ry�kr9r9r<r{J�z,get_console_script_specs.<locals>.<listcomp>Zeasy_installzeasy_install = zeasy_install-{} = {}cSsg|]}t�d|�r|�qS)zeasy_install(-\d\.\d)?$r�r�r9r9r<r{Xs�{} = {})
�copyr�rYr�r�rjr�r^�version_infor�extendrr�)r��scripts_to_generateZ
pip_scriptZpip_epr�Zeasy_install_scriptZeasy_install_epr9r9r<�get_console_script_specss<#
�
���r�c@s<eZdZeeedd�dd�Zed�dd�Zdd�dd	�Z	dS)
�
ZipBackedFileN)r3r4�zip_filer7cCs||_||_||_d|_dS�NF)r3r4�	_zip_filer5)r;r3r4r�r9r9r<�__init__eszZipBackedFile.__init__r6cCs|j�|j�Sr8)r�Zgetinfor3r:r9r9r<�_getinfomszZipBackedFile._getinfoc	Cs�tj�|j�}t|�tj�|j�r0t�|j�|��}|j�	|��H}t	|jd��}t
�||�Wd�n1st0YWd�n1s�0Yt|�r�t
|j�dS)NrX)rYrEr�r4r(�exists�unlinkr�r�r[�shutil�copyfileobjr.r-)r;r}Zzipinfor��destr9r9r<r=ps
HzZipBackedFile.save)
r>r?r@r2rBrr�rr�r=r9r9r9r<r�ds
�r�c@s*eZdZddd�dd�Zdd�dd�ZdS)	�
ScriptFiler1N��filer7cCs$||_|jj|_|jj|_d|_dSr�)�_filer3r4r5)r;r�r9r9r<r��s

zScriptFile.__init__r6cCs|j��t|j�|_dSr8)r�r=rgr4r5r:r9r9r<r=�s
zScriptFile.save)r>r?r@r�r=r9r9r9r<r��sr�cs$eZdZedd��fdd�Z�ZS)�MissingCallableSuffixN)rsr7cst��d�|��dS)Nz�Invalid script entry point: {} - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.)�superr�r�)r;rs��	__class__r9r<r��s
��zMissingCallableSuffix.__init__)r>r?r@rBr��
__classcell__r9r9r�r<r��sr�)�
specificationr7cCs*t|�}|dur&|jdur&tt|���dSr8)r�suffixr�rB)r��entryr9r9r<�_raise_for_invalid_entrypoint�sr�cs4eZdZdeeeefeed��fdd�
Z�ZS)�PipScriptMakerN)r��optionsr7cst|�t��||�Sr8)r�r��make)r;r�r�r�r9r<r��szPipScriptMaker.make)N)	r>r?r@rBrr	rr�r�r9r9r�r<r��sr�TF)	rr�	wheel_zip�
wheel_path�scheme�	pycompile�warn_script_location�
direct_url�	requestedr7c8	st||�\}}	t|	�r|j�n|j�i�t��g}
d4tttdd����fdd�
}ttd�dd�}ttdd	��fd
d��ttt	tgdfd
��fdd�}
tt
t	tgdfd���fdd�}ttd�dd�}ttt|�
��}t||�}t||�\}}|
|��}t||�}ttd�dd�}t||�\}}|||�}t||�}t||�}tt��t|��}t|�\��dtd���fdd�}t||�}t||�}tt|�}t||�}|D] }|��||j|j|j��q�ttd���fdd�}ttd�dd�} |�r�t���}!t���xt�d�|�D]V}"t j!|"d d d!�}#|#�r| |"�}$t"j#�$|$��sHJ�td"|$�%t"j#j&d#��}%||%|$��qWd�n1�s�0YWd�n1�s�0Yt'�(|!�)��t*d|j+�}&d |&_,d$h|&_-d |&_.t/��}'t0t1d%j2��3���}(|&�4|'�})|
�5|)�|
�5|&�4|(d&d i��|�rBt6|)�}*|*du�rBt'�7|*�d't8�@�t9j:tt;tt<d(��fd)d*��}+t"j#�=�|�},t"j#�=|,d+�}-|+|-��}.|.�>d,�Wd�n1�s�0Y|
�?|-�|du�r(t"j#�=|,t@�}/|+|/��$}0|0�>|�A��Bd-��Wd�n1�s0Y|
�?|/�|�rrt"j#�=|,d.�}1tC|1d/��Wd�n1�s^0Y|
�?|1�|�Dd0�}2t0tE�F|2�G���}3tH|3��|
�d1�}4t"j#�=|,d0�}5|+|5fitId2����.}6tE�Jtd3|6��}7|7�KtL|4��Wd�n1�s�0YdS)5a�Install a wheel.

    :param name: Name of the project to install
    :param wheel_zip: open ZipFile for wheel being installed
    :param scheme: Distutils scheme dictating the install directories
    :param req_description: String used in place of the requirement, for
        logging
    :param pycompile: Whether to byte-compile installed Python files
    :param warn_script_location: Whether to check that scripts are installed
        into a directory on PATH
    :raises UnsupportedWheel:
        * when the directory holds an unpacked wheel with incompatible
          Wheel-Version
        * when the .dist-info dir does not match the wheel
    FN)�srcfiler��modifiedr7cs(t|��}|�|<|r$��t|��dS)z6Map archive RECORD paths to installation RECORD paths.N)r�r�)r�r�r��newpath)r5r�r�r9r<�record_installed�s
z(_install_wheel.<locals>.record_installedrUcSs
|�d�S)Nr�)�endswith�rEr9r9r<�is_dir_path�sz#_install_wheel.<locals>.is_dir_path)�
dest_dir_path�target_pathr7cs$t||�s d}t|��||���dS)NzRThe wheel {!r} has a file {!r} trying to install outside the target directory {!r})r,rr�)r�r��message)r�r9r<�assert_no_path_traversal�s
��z0_install_wheel.<locals>.assert_no_path_traversalr1)r�r�r7cstdd����fdd�}|S)Nr1r�cs0tj�|�}tj��|�}��|�t||��Sr8)rYrE�normpathr�r�)r��normed_pathr4)r�r�r�r9r<�make_root_scheme_file�s
zM_install_wheel.<locals>.root_scheme_file_maker.<locals>.make_root_scheme_file)r2)r�r�r�)r�)r�r�r<�root_scheme_file_maker�sz._install_wheel.<locals>.root_scheme_file_maker)r�r�r7cs0�fdd�tD��tdd�����fdd�}|S)Ncsi|]}|t�|��qSr9)�getattr)ry�key)r�r9r<r�r�zB_install_wheel.<locals>.data_scheme_file_maker.<locals>.<dictcomp>r1r�c		s�tj�|�}z|�tjjd�\}}}Wn&tyLd��|�}t|��Yn0z�|}Wn8ty�d�	t
���}d��|||�}t|��Yn0tj�	||�}�||�t||��S)Nr�zbUnexpected file in {}: {!r}. .data directory contents should be named like: '<scheme key>/<path>'.r�z�Unknown scheme key used in {}: {} (for file {!r}). .data directory contents should be in subdirectories named with a valid scheme key ({}))rYrEr�r�rw�
ValueErrorr�r�KeyErrorr�r�r�)	r�r��_Z
scheme_keyZdest_subpathr�Zscheme_pathZvalid_scheme_keysr4)r��scheme_pathsr�r�r9r<�make_data_scheme_file�s*����
zM_install_wheel.<locals>.data_scheme_file_maker.<locals>.make_data_scheme_file)r#r2)r�r�r�)r�r�)r�r�r�r<�data_scheme_file_maker�sz._install_wheel.<locals>.data_scheme_file_makercSs|�dd�d�d�S)Nr�r�r�.data)r�r�r�r9r9r<�is_data_scheme_pathsz+_install_wheel.<locals>.is_data_scheme_pathcSs2|�dd�}t|�dko0|d�d�o0|ddkS)Nr�r�rr�r�ru)r�r�r�)rE�partsr9r9r<�is_script_scheme_path"sz-_install_wheel.<locals>.is_script_scheme_pathr�csz|j}tj�|�}|���d�r.|dd�}n<|���d�rJ|dd�}n |���d�rf|dd�}n|}|�vpx|�vS)Nz.exe���z
-script.pyi����z.pya)r4rYrEr�rkr�)r�rErrZ	matchname)r��guir9r<�is_entrypoint_wrapper5sz-_install_wheel.<locals>.is_entrypoint_wrapperr6c3sHtt�����D]2}tj��|�}tj�|�s0q|�d�s<q|VqdS)Nz.py)r�r�r�rYrEr�rZr�)Zinstalled_pathZfull_installed_path)r�r�r9r<�pyc_source_file_pathsPs
z-_install_wheel.<locals>.pyc_source_file_pathscSstj�|�S)z8Return the path the pyc file would have been written to.)�	importlib�util�cache_from_sourcer�r9r9r<�pyc_output_path]sz'_install_wheel.<locals>.pyc_output_path�ignoreT)�force�quietr2r�rPr�r�i�)rE�kwargsr7c;sTt|fi|���}|VWd�n1s,0Yt�|j��t|j|�dSr8)r%rY�chmodrrr&)rErr�)�generated_file_moder9r<�_generate_file�s$z&_install_wheel.<locals>._generate_fileZ	INSTALLERspip
rQZ	REQUESTEDrXZRECORD)r�r5r�r��wzIO[str])F)Mr/rlZpurelibZplatlibr�r2rBrCrrr$rrZnamelistrr*�maprr rrrtr�r=r3r4r5rr'�warnings�catch_warnings�filterwarnings�
compileall�compile_filerYrEr�r&rwr��debug�getvaluer�ruZclobberZvariantsZset_moder��listrr�r�Z
make_multipler�r�r�r+�
contextlib�contextmanagerr	r
r�rdr�r!Zto_jsonr`r[�	read_text�csv�reader�
splitlinesr�rT�writerZ	writerowsr�)8rrr�r�r�r�r�r�r�Zinfo_dirrhr�r�r�r�r�r��pathsZ
file_pathsZroot_scheme_pathsZdata_scheme_pathsr��filesr�Zother_scheme_pathsZscript_scheme_pathsr�Zother_scheme_filesZdistributionr�Zscript_scheme_filesr�r�r�stdoutrE�successZpyc_pathZpyc_record_pathZmakerr�Zgui_scripts_to_generateZgenerated_console_scripts�msgr
Z
dest_info_dirZinstaller_pathZinstaller_fileZdirect_url_pathZdirect_url_fileZrequested_pathZrecord_textZrecord_rowsZrowsr�Zrecord_filerr9)r�r5r�r	r�r�r�r�r<�_install_wheel�s���	��!


�


��






�N




*


4
 

�	r!)�req_descriptionr7c
csPz
dVWn@tyJ}z(d�||jd�}t|�|�WYd}~n
d}~00dS)NzFor req: {}. {}r)rr��args)r"�er�r9r9r<�req_error_context�s

r%)	rrr�r�r"r�r�r�r�r7c	Cspt|dd��P}t|��(t||||||||d�Wd�n1sD0YWd�n1sb0YdS)NT)Z
allowZip64)rrr�r�r�r�r�r�r�)rr%r!)	rrr�r�r"r�r�r�r��zr9r9r<�
install_wheel�s

�r')rD)N)TTNF)TTNF)j�__doc__r�rrrrZloggingZos.pathrYr�r�r^r
�base64rZ
email.messager�	itertoolsrrr�typingrrr	r
rrr
rrrrrrrrr�zipfilerrZpip._vendor.distlib.scriptsrZpip._vendor.distlib.utilrZpip._vendor.packaging.utilsrZpip._internal.exceptionsrZpip._internal.locationsrZpip._internal.metadatarrr Zpip._internal.models.direct_urlr!r"Zpip._internal.models.schemer#r$Zpip._internal.utils.filesystemr%r&Zpip._internal.utils.miscr'r(r)r*Zpip._internal.utils.unpackingr+r,r-r.Zpip._internal.utils.wheelr/r0r1Z	getLoggerr>r�rBr2�intZInstalledCSVRowrNrTrCrgrlrtr�r�r�r�r�r�r�r�r�r�r�r!rr%r'r9r9r9r<�<module>s�H	

(I�

� Q(
��
��