o
    �PÔaC  ã                   @   sÄ   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mZ d dlmZmZ d dlmZ e  e¡Zdee fd	d
„Zdededeeef fdd„Zdedefdd„ZdS )é    N)ÚPath)ÚOptionalÚTuple)Ú	constants)ÚEXIT_CODE_OKÚExitCode)ÚhazardÚstars)Ú	pipx_wrapÚreturnc                  C   s–   d} t tƒ ¡ }t t ¡ ƒ ¡ }z| |¡}W n ty"   d}Y nw d}|rI|d d t t ¡ ƒ ¡ jd d f}|D ]}| 	¡ rH|j}  | S q<| S )zmReturns None if pipx is not installed using `pip --user`
    Otherwise returns parent dir of pipx binary
    NFTÚbinÚpipxÚScriptszpipx.exe)
r   Ú__file__ÚresolveÚsiteÚgetuserbaseÚrelative_toÚ
ValueErrorÚgetusersitepackagesÚparentÚexists)Úpipx_bin_pathÚscript_pathÚuserbase_pathÚ_Úpip_user_installedÚ
test_pathsÚ	test_path© r   ú;/usr/lib/python3/dist-packages/pipx/commands/ensure_path.pyÚget_pipx_user_bin_path   s(   ÿ
þür!   ÚlocationÚforcec                C   s¬   t | ƒ}d}t |¡}t |¡}|s|s3|s3t |d¡ ttd|› d�dd�ƒ d}t |¡}||fS |sG|rGttd|› d	�dd�ƒ ||fS tt|› d
�dd�ƒ ||fS )zhEnsure location is in user's PATH or add it to PATH.
    Returns True if location was added to PATH
    Fr   zSuccess! Added z" to the PATH environment variable.z    )Úsubsequent_indentTú
                z£ has been been added to PATH, but you need to
                open a new terminal or re-login for this PATH change to take
                effect.
                z is already in PATH.)ÚstrÚuserpathÚneed_shell_restartÚin_current_pathÚappendÚprintr
   )r"   r#   Úlocation_strÚ
path_addedr(   r)   r   r   r    Úensure_path6   s:   


þÿ
ðÿúÿüÿr.   c                 C   sÀ   t tjgƒ}tƒ }|dur| |¡ d}d}|D ]}t|| d�\}}||O }||O }qtƒ  |r9ttdƒd ƒ n|sMtj	 
¡  t tdt› d�ƒd ¡ |rWttdƒd ƒ td	t› �ƒ tS )
zReturns pipx exit code.NF)r#   z†
                Consider adding shell completions for pipx. Run 'pipx
                completions' for instructions.
                Ú
r%   z¯  All pipx binary directories have been added to PATH. If you
                are sure you want to proceed, try again with the '--force'
                flag.
                z‡
                You will need to open a new terminal or re-login for the PATH
                changes to take effect.
                zOtherwise pipx is ready to go! )Úsetr   ÚLOCAL_BIN_DIRr!   Úaddr.   r+   r
   ÚsysÚstdoutÚflushÚloggerÚwarningr   r	   r   )r#   Ú	bin_pathsÚpipx_user_bin_pathr-   r(   Úbin_pathÚpath_added_currentÚneed_shell_restart_currentr   r   r    Úensure_pipx_paths\   sT   

ÿ
ÿúÿ	
ÿÿùÿÿúÿ
r=   )Úloggingr   r3   Úpathlibr   Útypingr   r   r'   r   r   Úpipx.constantsr   r   Úpipx.emojisr   r	   Ú	pipx.utilr
   Ú	getLoggerÚ__name__r6   r!   Úboolr.   r=   r   r   r   r    Ú<module>   s    
%&