o
    éT•jp*  ã                   @   s  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Zd dlmZ dd„ Z	ddgZ
dZdZd	Zd
edfdedfgZe  dd¡Ze d¡add„ Zdd„ Zdad#dd„Zdd„ Zdd„ Zdddddd dœdd„Zdddddd dœdd„Zd dœdd „Zd#d!d"„ZdS )$é    N)Ú	resourcesc                   C   s<   t tdƒrd S tjttdtjƒkrd S tdƒ t d¡ d S )NÚreal_prefixÚbase_prefixa£  ensurepip is disabled in Debian/Ubuntu for the system python.

Python modules for the system python are usually handled by dpkg and apt-get.

    apt install python3-<module name>

Install the python3-pip package to use pip itself.  Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.
é   )ÚhasattrÚsysÚprefixÚgetattrÚprintÚexit© r   r   ú)/usr/lib/python3.10/ensurepip/__init__.pyÚ+_ensurepip_is_disabled_in_debian_for_system   s   
r   ÚversionÚ	bootstrap)Ú
setuptoolsÚpipz65.5.0z23.0.1r   Úpy3r   ÚPackage)r   Ú
wheel_nameÚ
wheel_pathÚWHEEL_PKG_DIRc                 C   s    i }zt  | ¡}W n ty   d}Y nw t|ƒ}|D ]2}| d¡s#qtD ]}|d }| |¡r2 nq%q| |¡ d¡d }t j	 
| |¡}t|d |ƒ||< q|S )Nr   z.whlú-r   )ÚosÚlistdirÚOSErrorÚsortedÚendswithÚ_PACKAGE_NAMESÚ
startswithÚremoveprefixÚ	partitionÚpathÚjoinÚ_Package)r"   ÚpackagesÚ	filenamesÚfilenameÚnamer   r   r   r   r   r   Ú_find_packages=   s(   þ

ÿr)   c                     st   t d urt S i } tD ]\}}}|› d|› d|› d�}t||d ƒ| |< q
tr6ttƒ‰ t‡ fdd„tD ƒƒr6ˆ } | a | S )Nr   z-none-any.whlc                 3   s   � | ]}|ˆ v V  qd S ©Nr   )Ú.0r(   ©Údir_packagesr   r   Ú	<genexpr>f   s   € z _get_packages.<locals>.<genexpr>)Ú	_PACKAGESÚ	_PROJECTSr$   Ú_WHEEL_PKG_DIRr)   Úallr   )r%   r(   r   Úpy_tagr   r   r,   r   Ú_get_packagesZ   s   r4   c                 C   sJ   d|pg › d| › d�}t jddd|g}t jjr| dd¡ tj|d	d
�jS )Nz$
import runpy
import sys
sys.path = z + sys.path
sys.argv[1:] = z>
runpy.run_module("pip", run_name="__main__", alter_sys=True)
z-Wzignore::DeprecationWarningz-cr   z-IT)Úcheck)r   Ú
executableÚflagsÚisolatedÚinsertÚ
subprocessÚrunÚ
returncode)ÚargsÚadditional_pathsÚcodeÚcmdr   r   r   Ú_run_pipm   s   ýü	ûrA   c                   C   s   t ƒ d jS )zA
    Returns a string specifying the bundled version of pip.
    r   )r4   r   r   r   r   r   r   ‡   s   c                  C   s2   dd„ t jD ƒ} | D ]}t j|= q
t jt jd< d S )Nc                 S   s   g | ]	}|  d ¡r|‘qS )ÚPIP_)r   )r+   Úkr   r   r   Ú
<listcomp>’   s    z7_disable_pip_configuration_settings.<locals>.<listcomp>ÚPIP_CONFIG_FILE)r   ÚenvironÚdevnull)Úkeys_to_removerC   r   r   r   Ú#_disable_pip_configuration_settingsŽ   s   
rI   F©ÚrootÚupgradeÚuserÚ
altinstallÚdefault_pipÚ	verbosityc                 C   s   t | |||||d� dS )z­
    Bootstrap pip into the current Python installation (or the given root
    directory).

    Note that calling this function will alter both sys.path and os.environ.
    rJ   N)Ú
_bootstraprJ   r   r   r   r   š   s   

þc              
   C   s   t ƒ  |r|rtdƒ‚t d| ¡ tƒ  |rdtjd< n|s#dtjd< t ¡ �Ÿ}g }t	ƒ  
¡ D ]^\}}	|	jrFddlm}
 |	j}t |
|¡}n!t|	jdƒ�}| ¡ }W d	  ƒ n1 s[w   Y  tj |	j¡}tj ||¡}t|d
ƒ�}| |¡ W d	  ƒ n1 sƒw   Y  | |¡ q/dddd|g}| r�|d| g7 }|r¤|dg7 }|r«|dg7 }|r¶|dd|  g7 }tg |¢t¢|ƒW  d	  ƒ S 1 sÉw   Y  d	S )zÎ
    Bootstrap pip into the current Python installation (or the given root
    directory). Returns pip command status code.

    Note that calling this function will alter both sys.path and os.environ.
    z.Cannot use altinstall and default_pip togetherzensurepip.bootstraprN   ÚENSUREPIP_OPTIONSÚinstallr   )Ú_bundledÚrbNÚwbz--no-cache-dirz
--no-indexz--find-linksú--rootú	--upgradeú--userr   Úv)r   Ú
ValueErrorr   ÚauditrI   r   rF   ÚtempfileÚTemporaryDirectoryr4   Úitemsr   Ú	ensurepiprT   r   Úread_binaryÚopenr   Úreadr"   Úbasenamer#   ÚwriteÚappendrA   r   )rK   rL   rM   rN   rO   rP   Útmpdirr>   r(   ÚpackagerT   r   ÚwhlÚfpr'   r=   r   r   r   rQ   ©   sH   


ÿÿ

$ßrQ   )rP   c                 C   sŒ   zddl }W n
 ty   Y dS w tƒ }|j|kr*td|j›d|›d�tjd� dS tƒ  g d¢}| r<|dd	|   g7 }tg |¢t	t
ƒ¢ƒS )
z~Helper to support a clean default uninstall process on Windows

    Note that calling this function may alter os.environ.
    r   Nz2ensurepip will only uninstall a matching version (z installed, z available))Úfile)Ú	uninstallz-yz--disable-pip-version-checkr   rZ   )r   ÚImportErrorr   Ú__version__r
   r   ÚstderrrI   rA   Úreversedr   )rP   r   Úavailable_versionr=   r   r   r   Ú_uninstall_helperî   s(   ÿ
ÿþýrr   c                 C   sÈ   dd l }|jdd�}|jddd tƒ ¡dd� |jd	d
ddddd� |jdddddd� |jddddd� |jdd dd� |jddddd� |jddddd� | | ¡}t|j|j|j	|j
|j|jd�S )Nr   zpython -m ensurepip)Úprogz	--versionr   zpip {}z9Show the version of pip that is bundled with this Python.)Úactionr   Úhelpz-vz	--verboseÚcountrP   zDGive more output. Option is additive, and can be used up to 3 times.)rt   ÚdefaultÚdestru   z-UrX   Ú
store_trueFz8Upgrade pip and dependencies, even if already installed.)rt   rw   ru   rY   zInstall using the user scheme.rW   z=Install everything relative to this alternate root directory.)rw   ru   z--altinstallzoMake an alternate install, installing only the X.Y versioned scripts (Default: pipX, pipX.Y, easy_install-X.Y).z--default-pipzqMake a default pip install, installing the unqualified pip and easy_install in addition to the versioned scripts.)rK   rL   rM   rP   rN   rO   )ÚargparseÚArgumentParserÚadd_argumentÚformatr   Ú
parse_argsrQ   rK   rL   rM   rP   rN   rO   )Úargvrz   Úparserr=   r   r   r   Ú_main  sj   
üûüüýüü
úr�   r*   )Úcollectionsr   Úos.pathr:   r   Ú	sysconfigr]   Ú	importlibr   r   Ú__all__r   Ú_SETUPTOOLS_VERSIONÚ_PIP_VERSIONr0   Ú
namedtupler$   Úget_config_varr1   r)   r4   r/   rA   r   rI   r   rQ   rr   r�   r   r   r   r   Ú<module>   sH    þÿ

þþE