U
    ^N  ã                   @   sè  d Z ddlm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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 ddlmZ erÌddlmZmZmZmZ ddlm Z! e "d¡Z#dd„ Z$dd„ Z%e &d¡Z'e (¡  )¡ dkr
e
 *¡ Z'ze +¡ Z,W n e-k
r2   ej.Z,Y nX er†ej/ 0ej1d¡Z2ej/ 0e,d¡Z3ej/ 4e2¡sÐej/ 0ej1d¡Z2ej/ 0e,d¡Z3nJej/ 0ej1d¡Z2ej/ 0e,d¡Z3ejdd… dkrÐej1dd… dkrÐdZ2d!dd„Z5d"dd „Z6dS )#z7Locations where we look for configs, install stuff, etcé    )Úabsolute_importN)Ú	sysconfig)ÚSCHEME_KEYS)Úinstall)ÚScheme)Úappdirs)ÚWINDOWS)ÚMYPY_CHECK_RUNNINGÚcast)Úrunning_under_virtualenv)ÚDictÚListÚOptionalÚUnion)ÚCommandZpipc                   C   s   dj tjŽ S )ze
    Return the major-minor version of the current Python as a string, e.g.
    "3.7" or "3.10".
    z{}.{})ÚformatÚsysÚversion_info© r   r   ú6lib/python3.8/site-packages/pip/_internal/locations.pyÚget_major_minor_version"   s    r   c                  C   sZ   t ƒ rtj tjd¡} n6ztj t ¡ d¡} W n tk
rL   t d¡ Y nX tj 	| ¡S )NÚsrcz=The folder you are executing pip from can no longer be found.)
r   ÚosÚpathÚjoinr   ÚprefixÚgetcwdÚOSErrorÚexitÚabspath)Z
src_prefixr   r   r   Úget_src_prefix+   s    ÿ
r    ÚpurelibZpypyZScriptsÚbiné   Údarwiné   z/System/Library/z/usr/local/binFc                 C   s„  ddl m} d| i}|r"dg|d< ||ƒ}| ¡  d}	|jddd	}	|	dk	sPt‚tt|	ƒ}
|rr|rrtd
 ||¡ƒ‚|rŠ|rŠtd ||¡ƒ‚|p’|
j|
_|sž|r¤d|
_	|p¬|
j	|
_	|p¸|
j
|
_
|pÄ|
j|
_|
 ¡  i }tD ]}t|
d| ƒ||< qØd| d¡kr| t|
j|
jd¡ tƒ r€tj tj	ddd tƒ ¡| ¡|d< |dk	r€tj tj |d ¡¡d }tj ||dd… ¡|d< |S )z+
    Return a distutils install scheme
    r   )ÚDistributionÚnamez--no-user-cfgZscript_argsNr   T)Zcreatezuser={} prefix={}zhome={} prefix={}Ú Zinstall_Úinstall_lib)r!   ÚplatlibZincludeÚsitezpython{}Úheadersé   )Zdistutils.distr&   Zparse_config_filesZget_command_objÚAssertionErrorr
   Údistutils_install_commandr   Úuserr   ÚhomeÚrootZfinalize_optionsr   ÚgetattrZget_option_dictÚupdateÚdictr)   r   r   r   r   r   r   Ú
splitdriver   )Ú	dist_namer0   r1   r2   Úisolatedr   r&   Z	dist_argsÚdÚobjÚiÚschemeÚkeyZpath_no_driver   r   r   Údistutils_scheme_   sV    


û
ÿÿ
þr>   c                 C   s8   t | |||||ƒ}t|d |d |d |d |d dS )a;  
    Get the "scheme" corresponding to the input parameters. The distutils
    documentation provides the context for the available schemes:
    https://docs.python.org/3/install/index.html#alternate-installation

    :param dist_name: the name of the package to retrieve the scheme for, used
        in the headers scheme path
    :param user: indicates to use the "user" scheme
    :param home: indicates to use the "home" scheme and provides the base
        directory for the same
    :param root: root under which other directories are re-based
    :param isolated: equivalent to --no-user-cfg, i.e. do not consider
        ~/.pydistutils.cfg (posix) or ~/pydistutils.cfg (non-posix) for
        scheme paths
    :param prefix: indicates to use the "prefix" scheme and provides the
        base directory for the same
    r*   r!   r,   ÚscriptsÚdata)r*   r!   r,   r?   r@   )r>   r   )r7   r0   r1   r2   r8   r   r<   r   r   r   Ú
get_schemeŸ   s         ÿûrA   )FNNFN)FNNFN)7Ú__doc__Z
__future__r   r   Úos.pathÚplatformr+   r   r   Z	distutilsZdistutils_sysconfigZdistutils.command.installr   r   r/   Zpip._internal.models.schemer   Zpip._internal.utilsr   Zpip._internal.utils.compatr   Zpip._internal.utils.typingr	   r
   Zpip._internal.utils.virtualenvr   Útypingr   r   r   r   Zdistutils.cmdr   ZDistutilsCommandZuser_cache_dirZUSER_CACHE_DIRr   r    Zget_pathZsite_packagesZpython_implementationÚlowerZget_python_libÚgetusersitepackagesÚ	user_siteÚAttributeErrorÚ	USER_SITEr   r   r   Zbin_pyZbin_userÚexistsr>   rA   r   r   r   r   Ú<module>   sd   
	
(         ÿ
B     ú