Your IP : 3.145.43.200


Current Path : /lib/python3.8/site-packages/setuptools/command/__pycache__/
Upload File :
Current File : //lib/python3.8/site-packages/setuptools/command/__pycache__/easy_install.cpython-38.pyc

U

�Qab�U�@s4dZddlmZddlmZddlmZmZddlmZmZm	Z	m
Z
ddlmZm
Z
ddlmZmZddlmZdd	lmZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
lZdd
l Z dd
l!Z!dd
l"Z"dd
l#Z#dd
l$Z$dd
l%Z%ddl&m'Z'm(Z(ddl)m*Z*dd
l+m,Z,ddl-m.Z.m/Z/ddl)m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;m<Z<ddl5m=Z=m>Z>ddl?m@Z@ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPdd
lQZAeRZSejTdeAjUd�ddddddgZVd d!�ZWd"d�ZXe,jY�rBd#d$�ZZd%d&�Z[nd'd$�ZZd(d&�Z[d)d*�Z\Gd+d�de0�Z]d,d-�Z^d.d/�Z_d0d1�Z`d2d�Zad3d�ZbGd4d�deH�ZcGd5d6�d6ec�Zdeje�fd7d8�d9k�r�edZcd:d;�Zgd<d=�Zhd>d?�Zid@dA�ZjdsdBdC�ZkdDdE�ZldFdG�ZmdHejnk�remZondIdJ�ZodtdLdM�ZpdNdO�ZqdPdQ�ZrdRdS�ZszddTlmtZuWnevk
�rndUdV�ZuYnXdWdX�ZtGdYdZ�dZew�Zxex�y�ZzGd[d\�d\ex�Z{Gd]d^�d^�Z|Gd_d`�d`e|�Z}Gdadb�dbe}�Z~e|jZe|j�Z�dcdd�Z�dedf�Z�dgehfdhdi�Z�djdk�Z�dldm�Z�dudnd�Z�e"j�dodp��Z�Gdqdr�dre*�Z�d
S)va%
Easy Install
------------

A tool for doing automatic download/extract/build of distutils-based Python
packages.  For detailed documentation, see the accompanying EasyInstall.txt
file, or visit the `EasyInstall home page`__.

__ https://setuptools.readthedocs.io/en/latest/easy_install.html

�)�glob)�get_platform)�convert_path�
subst_vars)�DistutilsArgError�DistutilsOptionError�DistutilsError�DistutilsPlatformError)�INSTALL_SCHEMES�SCHEME_KEYS)�log�dir_util)�
first_line_re)�find_executableN)�get_config_vars�get_path)�SetuptoolsDeprecationWarning)�six)�configparser�map)�Command)�	run_setup)�rmtree_safe)�setopt)�unpack_archive)�PackageIndex�parse_requirement_arg�
URL_SCHEME)�	bdist_egg�egg_info)�Wheel)�yield_lines�normalize_path�resource_string�ensure_directory�get_distribution�find_distributions�Environment�Requirement�Distribution�PathMetadata�EggMetadata�
WorkingSet�DistributionNotFound�VersionConflict�DEVELOP_DIST�default)�category�samefile�easy_install�PthDistributions�extract_wininst_cfg�main�get_exe_prefixescCst�d�dkS)N�P�)�struct�calcsize�r<r<�C/usr/lib/python3.8/site-packages/setuptools/command/easy_install.py�is_64bitOsr>cCsjtj�|�otj�|�}ttjd�o&|}|r:tj�||�Stj�tj�|��}tj�tj�|��}||kS)z�
    Determine if two paths reference the same file.

    Augments os.path.samefile to work on Windows and
    suppresses errors if the path doesn't exist.
    r2)�os�path�exists�hasattrr2�normpath�normcase)Zp1Zp2Z
both_existZuse_samefileZnorm_p1Znorm_p2r<r<r=r2SscCs|S�Nr<��sr<r<r=�	_to_bytesesrHcCs.zt�|d�WdStk
r(YdSXdS�N�asciiTF)rZ	text_type�UnicodeErrorrFr<r<r=�isasciihs
rLcCs
|�d�S)N�utf8)�encoderFr<r<r=rHpscCs,z|�d�WdStk
r&YdSXdSrI)rNrKrFr<r<r=rLss

cCst�|����dd�S)N�
z; )�textwrap�dedent�strip�replace)�textr<r<r=�<lambda>{�rUc@s�eZdZdZdZdZdddddd	d
ddd
dddddddddddgZdddddddd d!g	Zej	r�d"ej
Ze�d#d$ef�e�d#�d%diZ
eZd&d'�Zd(d)�Zd*d+�Zed,d-��Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Ze�d@�� �Z!e�dA�� �Z"e�dB�� �Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)e*j+dOdP��Z,d�dRdS�Z-d�dTdU�Z.dVdW�Z/d�dXdY�Z0dZd[�Z1d\d]�Z2d^d_�Z3d�d`da�Z4edbdc��Z5d�dfdg�Z6dhdi�Z7djdk�Z8dldm�Z9dndo�Z:dpdq�Z;drds�Z<e�dt�� �Z=e�du�Z>d�dwdx�Z?e�dy�� �Z@dzd{�ZAd|d}�ZBd~d�ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHe�d��� �ZId�d��ZJd�d��ZKd�d��ZLeMeMd�d�d��d��ZNeMd�d�d��ZOd�d��ZPd$S)�r3z'Manage a download/build/install processz Find/get/install Python packagesT)zprefix=Nzinstallation prefix)�zip-ok�zzinstall package as a zipfile)�
multi-version�mz%make apps have to require() a version)�upgrade�Uz1force upgrade (searches PyPI for latest versions))zinstall-dir=�dzinstall package to DIR)zscript-dir=rGzinstall scripts to DIR)�exclude-scripts�xzDon't install scripts)�always-copy�az'Copy all needed packages to install dir)z
index-url=�iz base URL of Python Package Index)zfind-links=�fz(additional URL(s) to search for packages)zbuild-directory=�bz/download/extract/build in DIR; keep the results)z	optimize=�Ozlalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0])zrecord=Nz3filename in which to record list of installed files)�always-unzip�Zz*don't install as a zipfile, no matter what)z
site-dirs=�Sz)list of directories where .pth files work)�editable�ez+Install specified packages in editable form)�no-deps�Nzdon't install dependencies)zallow-hosts=�Hz$pattern(s) that hostnames must match)�local-snapshots-ok�lz(allow building eggs from local checkouts)�versionNz"print version information and exit)z
no-find-linksNz9Don't load find-links defined in packages being installedrWrYr^r[r`rirkrnrpz!install in user site-package '%s'�userNrfcCs,d|_d|_|_d|_|_|_d|_d|_d|_d|_	d|_
|_d|_|_
|_d|_|_|_d|_|_|_d|_d|_d|_d|_d|_d|_d|_d|_d|_tjr�tj |_!tj"|_#nd|_!d|_#d|_$d|_%d|_&|_'d|_(i|_)d|_*d|_+|j,j-|_-|j,�.||j,�/d��dS)NrFr3)0rq�zip_ok�local_snapshots_ok�install_dir�
script_dir�exclude_scripts�	index_url�
find_links�build_directory�args�optimize�recordr[�always_copy�
multi_versionri�no_deps�allow_hosts�root�prefix�	no_reportrp�install_purelib�install_platlib�install_headers�install_lib�install_scripts�install_data�install_base�install_platbase�site�ENABLE_USER_SITE�	USER_BASE�install_userbase�	USER_SITE�install_usersite�
no_find_links�
package_index�pth_file�always_copy_from�	site_dirs�installed_projects�sitepy_installedZ_dry_run�distribution�verboseZ_set_command_options�get_option_dict��selfr<r<r=�initialize_options�sJ


�zeasy_install.initialize_optionscCs"dd�|D�}tt|j|��dS)Ncss*|]"}tj�|�stj�|�r|VqdSrE)r?r@rA�islink)�.0�filenamer<r<r=�	<genexpr>�s�z/easy_install.delete_blockers.<locals>.<genexpr>)�listr�_delete_path)r��blockersZextant_blockersr<r<r=�delete_blockers�s�zeasy_install.delete_blockerscCsJt�d|�|jrdStj�|�o.tj�|�}|r8tntj}||�dS)NzDeleting %s)	r�info�dry_runr?r@�isdirr��rmtree�unlink)r�r@Zis_treeZremoverr<r<r=r��szeasy_install._delete_pathcCs4djtj�}td�}d}t|jft���t��dS)zT
        Render the Setuptools version and installation details, then exit.
        �{}.{}�
setuptoolsz=setuptools {dist.version} from {dist.location} (Python {ver})N)�format�sys�version_infor%�print�locals�
SystemExit)Zver�dist�tmplr<r<r=�_render_version�s
zeasy_install._render_versionc	Csh|jo|��tj��d}tdd�\}}|j��|j��|j��||dd�|d|d||||t	tdd�d�|_
tjr�|j
|j
d	<|j|j
d
<|��|��|��|�ddd
d�|jdkr�|j|_|jdkr�d|_|�dd�|�dd�|j�r|j�r|j|_|j|_|�dd�tttj�}t�|_|jdk	�r�dd�|j�d�D�}|D]N}t j�!|��s|t"�#d|�n,t|�|k�r�t$|d��n|j�%t|���q\|j&�s�|�'�|j(�p�d|_(|jdd�|_)|jt|j�fD] }||j)k�r�|j)�*d|��q�|j+dk	�r0dd�|j+�d�D�}ndg}|j,dk�rX|j-|j(|j)|d�|_,t.|j)tj�|_/|j0dk	�r�t1|j0t2j3��r�|j0��|_0ng|_0|j4�r�|j,�5|j)tj�|j�s�|j,�6|j0�|�dd�t1|j7t8��s6z0t8|j7�|_7d|j7k�rdk�snt9�Wnt9k
�r4t$d ��YnX|j&�rN|j:�sNt;d!��|j<�s^t;d"��g|_=dS)#Nrr��exec_prefix���abiflags�)Z	dist_nameZdist_versionZ
dist_fullname�
py_versionZpy_version_shortZpy_version_nodotZ
sys_prefixr�Zsys_exec_prefixr�r��userbaseZusersitertruryr�Fr�)rtrtr��rtru�install)r|r|cSsg|]}tj�|����qSr<)r?r@�
expanduserrR�r�rGr<r<r=�
<listcomp>8sz1easy_install.finalize_options.<locals>.<listcomp>�,z"%s (in --site-dirs) does not existz$ (in --site-dirs) is not on sys.pathzhttps://pypi.org/simple/cSsg|]}|���qSr<)rRr�r<r<r=r�Ns�*)Zsearch_path�hosts)r{r{z--optimize must be 0, 1, or 2z9Must specify a build directory (-b) when using --editablez:No urls, filenames, or requirements specified (see --help))>rpr�r��splitrr�Zget_nameZget_versionZget_fullname�getattr�config_varsr�r�r�r��_fix_install_dir_for_user_site�expand_basedirs�expand_dirs�_expandrurtr�Zset_undefined_optionsrqr�r�rr"r@�
get_site_dirs�
all_site_dirsr�r?r�r�warnr�appendri�check_site_dirrw�shadow_path�insertr�r��create_indexr'�local_indexrx�
isinstancerZstring_typesrsZscan_egg_links�add_find_linksr{�int�
ValueErrorryrrz�outputs)	r�r�r�r�rCr�r]Z	path_itemr�r<r<r=�finalize_options�s�

��

��
�����zeasy_install.finalize_optionscCs\|jrtjsdS|��|jdkr.d}t|��|j|_|_tj	�
dd�d}|�|�dS)z;
        Fix the install_dir if "--user" was used.
        Nz$User base directory is not specified�posixZunixZ_user)rqr�r��create_home_pathr�r	r�r�r?�namerS�
select_scheme)r��msgZscheme_namer<r<r=r�ss
z+easy_install._fix_install_dir_for_user_sitecCsX|D]N}t||�}|dk	rtjdks.tjdkr:tj�|�}t||j�}t|||�qdS)Nr��nt)r�r?r�r@r�rr��setattr)r��attrs�attr�valr<r<r=�
_expand_attrs�s
zeasy_install._expand_attrscCs|�dddg�dS)zNCalls `os.path.expanduser` on install_base, install_platbase and
        root.r�r�r�N�r�r�r<r<r=r��szeasy_install.expand_basedirscCsddddddg}|�|�dS)z+Calls `os.path.expanduser` on install dirs.r�r�r�r�r�r�Nr�)r��dirsr<r<r=r��s�zeasy_install.expand_dirsc	Cs�|j|jjkrt�|j�z�|jD]}|�||j�q"|jr�|j}|j	rzt
|j	�}tt
|��D]}|||d�||<q`ddlm
}|�|j|j|fd|j�|��W5t�|jj�XdS)Nr)�	file_utilz'writing list of installed files to '%s')r�r�r�
set_verbosityrzr3rr|r�r��len�range�	distutilsr��executeZ
write_file�warn_deprecated_options)r��specr�Zroot_lenZcounterr�r<r<r=�run�s*

��zeasy_install.runcCsDzt��}Wn"tk
r.t�dtj�}YnXtj�|j	d|�S)z�Return a pseudo-tempname base in the install directory.
        This code is intentionally naive; if a malicious party can write to
        the target directory you're already in deep doodoo.
        rztest-easy-install-%s)
r?�getpid�	Exception�randomZrandintr��maxsizer@�joinrt)r��pidr<r<r=�pseudo_tempname�s
zeasy_install.pseudo_tempnamecCsdSrEr<r�r<r<r=r��sz$easy_install.warn_deprecated_optionsc	CsZt|j�}tj�|d�}tj�|�sTzt�|�Wn ttfk
rR|�	�YnX||j
k}|sr|jsr|��}nd|�
�d}tj�|�}z*|r�t�|�t|d���t�|�Wn ttfk
r�|�	�YnX|s�|js�t|����|�r|jdk�rt||j
�|_nd|_|ttt��k�r.d|_n"|j�rPtj�|��sPd|_d|_||_dS)z;Verify that self.install_dir is .pth-capable dir, if needed�easy-install.pthz.write-test�wNT)r"rtr?r@r�rA�makedirs�OSError�IOError�cant_write_to_targetr�r~�check_pth_processingr�r��open�closer�no_default_version_msgr�r4r�_pythonpathr�)r��instdirr�Zis_site_dirZtestfileZtest_existsr<r<r=r��s>





zeasy_install.check_site_diraS
        can't create or remove files in install directory

        The following error occurred while trying to add or remove files in the
        installation directory:

            %s

        The installation directory you specified (via --install-dir, --prefix, or
        the distutils default setting) was:

            %s
        z�
        This directory does not currently exist.  Please create it and try again, or
        choose a different installation directory (using the -d or --install-dir
        option).
        a�
        Perhaps your account does not have write access to this directory?  If the
        installation directory is a system-owned directory, you may need to sign in
        as the administrator or "root" account.  If you do not have administrative
        access to this machine, you may wish to choose a different installation
        directory, preferably one that is listed in your PYTHONPATH environment
        variable.

        For information on other options, you may wish to consult the
        documentation at:

          https://setuptools.readthedocs.io/en/latest/easy_install.html

        Please make the appropriate changes for your system and try again.
        cCsP|jt��d|jf}tj�|j�s6|d|j7}n|d|j7}t	|��dS)N�rO)
�_easy_install__cant_write_msgr��exc_infortr?r@rA�_easy_install__not_exists_id�_easy_install__access_msgr)r�r�r<r<r=r�s
z!easy_install.cant_write_to_targetc
	Cs�|j}t�d|�|��d}|d}tj�|�}td�d}z8|rNt�|�tj�	|�}t
jj|dd�t
|d�}Wn ttfk
r�|��Yn�Xz�|�|jft���|��d	}tj}tjd
k�rtj�|�\}}	tj�|d�}
|	��dk�otj�|
�}|�r|
}d
dlm}||dddgd
�tj�|��rNt�d|�W�dSW5|�r`|��tj�|��rxt�|�tj�|��r�t�|�X|j�s�t�d|�dS)z@Empirically verify whether .pth files are supported in inst. dirz Checking .pth file support in %s�.pthz.okzz
            import os
            f = open({ok_file!r}, 'w')
            f.write('OK')
            f.close()
            rOT)�exist_okr�Nr��pythonw.exe�
python.exer)�spawnz-Ez-c�passz-TEST PASSED: %s appears to support .pth filesz+TEST FAILED: %s does NOT support .pth filesF)rtrr�r�r?r@rA�
_one_linerr��dirname�
pkg_resourcesZ
py31compatr�rr�r�r�r�writer�r�r��
executabler�r�r��lower�distutils.spawnrr~r�)
r�rr�Zok_fileZ	ok_existsr�rrcr�basenameZaltZuse_altrr<r<r=r�s\�

��
z!easy_install.check_pth_processingc	CsV|jsH|�d�rH|�d�D],}|�d|�r.q|�|||�d|��q|�|�dS)z=Write all the scripts for `dist`, unless scripts are excluded�scriptszscripts/N)rvZmetadata_isdirZmetadata_listdir�install_scriptZget_metadata�install_wrapper_scripts)r�r��script_namer<r<r=�install_egg_scriptsYs�z easy_install.install_egg_scriptscCsTtj�|�rDt�|�D]*\}}}|D]}|j�tj�||��q$qn|j�|�dSrE)r?r@r��walkr�r�r�)r�r@�baser��filesr�r<r<r=�
add_outputgs
zeasy_install.add_outputcCs|jrtd|f��dS)NzjInvalid argument %r: you can't use filenames or URLs with --editable (except via the --find-links option).)rir�r�r�r<r<r=�not_editableos��zeasy_install.not_editablecCs<|js
dStj�tj�|j|j��r8td|j|jf��dS)Nz2%r already exists in %s; can't do a checkout there)rir?r@rAr�ry�keyrr!r<r<r=�check_editablews
��zeasy_install.check_editablec	cs:tjdd�}zt|�VW5tj�|�o2tt|��XdS)Nz
easy_install-)r�)�tempfile�mkdtempr?r@rAr�r�str)r��tmpdirr<r<r=�_tmpdir�szeasy_install._tmpdirFc
CsH|js|��|����&}t|t�s�t|�rb|�|�|j�||�}|�	d|||d�W5QR�St
j�|�r�|�|�|�	d|||d�W5QR�St
|�}|�|�|j�|||j|j|j|j�}|dkr�d|}|jr�|d7}t|��nJ|jtk�r|�|||d�|W5QR�S|�	||j||�W5QR�SW5QRXdS)NTz+Could not find suitable distribution for %rz2 (--always-copy skips system and development eggs)�Using)ri�install_site_pyr)r�r(rr"r��download�install_itemr?r@rArr$Zfetch_distributionr[r}r�rZ
precedencer/�process_distribution�location)r�r��depsr(�dlr�r�r<r<r=r3�s<



�
zeasy_install.easy_installcCs
|p|j}|ptj�|�|k}|p,|�d�}|pT|jdk	oTtj�t|��t|j�k}|r�|s�|j|jD]}|j	|krjq�qjd}t
�dtj�|��|r�|�
|||�}|D]}|�|||�q�n |�|�g}|�||d|d�|dk	�r|D]}||kr�|Sq�dS)N�.eggTz
Processing %srr*)r}r?r@r�endswithr�r"r��project_namer/rr�r�install_eggsr.�egg_distribution)r�r�r,r(r0Zinstall_neededr�Zdistsr<r<r=r-�s2

��

zeasy_install.install_itemcCs<t|}tD]*}d|}t||�dkrt||||�qdS)z=Sets the install directories by applying the install schemes.Zinstall_N)r
rr�r�)r�r��schemer#�attrnamer<r<r=r��s
zeasy_install.select_schemec
Gs�|�|�|j�|�||j|jkr2|j�|�|j�|�|�|�||j|j<t�	|j
||f|���|�d�r�|js�|j�
|�d��|s�|js�dS|dk	r�|j|jkr�t�d|�dS|dks�||kr�|��}tt|��}t�	d|�ztg��|g|j|j�}Wn^tk
�r<}ztt|���W5d}~XYn0tk
�rj}zt|����W5d}~XYnX|j�s||j�r�|D]"}|j|jk�r�|�|����q�t�	d|�dS)Nzdependency_links.txtzSkipping dependencies for %szProcessing dependencies for %sz'Finished processing dependencies for %s)�
update_pthr��addr�r#�removerr�rr��installation_report�has_metadatar�r�Zget_metadata_linesr}r��as_requirementr(r'r,Zresolver3r-rr.Zreportr�)r�Zrequirementr�r0r�ZdistreqZdistrosrjr<r<r=r.�sL


��
�z!easy_install.process_distributioncCs2|jdk	r|jS|�d�r dS|�d�s.dSdS)Nznot-zip-safeTzzip-safeF)rrr=�r�r�r<r<r=�should_unzips


zeasy_install.should_unzipcCs�tj�|j|j�}tj�|�r:d}t�||j|j|�|Stj�|�rL|}nRtj�	|�|krft�
|�t�|�}t|�dkr�tj�||d�}tj�|�r�|}t
|�t�||�|S)Nz<%r already exists in %s; build directory %s will not be keptrr)r?r@r�ryr#rArr�r�rr��listdirr�r$�shutil�move)r�r��
dist_filename�
setup_base�dstr��contentsr<r<r=�
maybe_moves$�

zeasy_install.maybe_movecCs,|jr
dSt���|�D]}|j|�qdSrE)rv�ScriptWriter�best�get_args�write_script)r�r�rzr<r<r=r"sz$easy_install.install_wrapper_scriptscCsNt|���}t||�}|r8|�|�t�}t�|�|}|�|t|�d�dS)z/Generate a legacy script wrapper and install itrdN)	r'r>�is_python_script�_load_templater�rI�
get_headerrLrH)r�r�r�script_text�dev_pathr�Z	is_scriptZbodyr<r<r=r(s
zeasy_install.install_scriptcCs(d}|r|�dd�}td|�}|�d�S)z�
        There are a couple of template scripts in the package. This
        function loads one of them and prepares it for use.
        zscript.tmplz.tmplz (dev).tmplr��utf-8)rSr#�decode)rQr�Z	raw_bytesr<r<r=rN2s

zeasy_install._load_template�tr<c	s����fdd�|D��t�d|�j�tj��j|�}��|��jrLdSt	�}t
|�tj�|�rpt�|�t
|d|��}|�|�W5QRXt|d|�dS)z1Write an executable file to the scripts directorycsg|]}tj��j|��qSr<)r?r@r�ru�r�r_r�r<r=r�Dsz-easy_install.write_script.<locals>.<listcomp>zInstalling %s script to %sNr�i�)r�rr�rur?r@r�r r��
current_umaskr$rAr�rr�chmod)r�rrG�moder��target�maskrcr<r�r=rLAs�

zeasy_install.write_scriptcCs^|���d�r|�||�gS|���d�r8|�||�gS|���d�rT|�||�gS|}tj�|�r~|�d�s~t|||j	�ntj�
|�r�tj�|�}|�|�r�|j
r�|dk	r�|�|||�}tj�|d�}tj�|��s0ttj�|dd��}|�stdtj�|���t|�dk�r(td	tj�|���|d
}|j�rNt�|�||��gS|�||�SdS)Nr2�.exez.whl�.pyzsetup.pyr�z"Couldn't find a setup script in %srzMultiple setup scripts in %sr)rr3�install_egg�install_exe�
install_wheelr?r@�isfiler�unpack_progressr��abspath�
startswithryrHr�rArrr�rirr��report_editable�build_and_install)r�r�rDr(rE�setup_scriptZsetupsr<r<r=r5UsJ
��
��
��zeasy_install.install_eggscCs>tj�|�r"t|tj�|d��}ntt�|��}tj	||d�S)N�EGG-INFO)�metadata)
r?r@r�r*r�r+�	zipimport�zipimporterr)Z
from_filename)r��egg_pathrhr<r<r=r6�s�zeasy_install.egg_distributionc	Cs�tj�|jtj�|��}tj�|�}|js2t|�|�|�}t	||��sztj�
|�rrtj�|�srtj
||jd�n"tj�|�r�|�tj|fd|�z�d}tj�
|�r�|�|�r�tjd}}ntjd}}nL|�|�r�|�|�|jd}}n*d}|�|��rtjd}}ntjd}}|�|||f|dtj�|�tj�|�f�t||d	�Wn$tk
�rxt|dd	��YnX|�|�|�|�S)
N�r��	Removing FZMovingZCopyingZ
ExtractingTz	 %s to %s��fix_zipimporter_caches)r?r@r�rtrrbr�r$r6r2r�r�r
�remove_treerAr�r�rcrBrCZcopytreer@Zmkpath�unpack_and_compileZcopy2r�update_dist_cachesr�r )r�rkr(�destinationr�Znew_dist_is_zippedrcrZr<r<r=r]�s^
�
�




���

zeasy_install.install_eggcsPt|�}|dkrtd|��td|�dd�|�dd�t�d�}tj�||��d�}||_	|d}tj�|d�}tj�|d	�}t
|�t||�|_|�
||�tj�|��st|d
�}	|	�d�|�d�D].\}
}|
dkr�|	�d
|
�dd���|f�q�|	��tj�|d��|��fdd�t�|�D��tj|||j|jd�|�||�S)Nz(%s is not a valid distutils Windows .exerhr�rp)r4rp�platformr2z.tmprg�PKG-INFOr�zMetadata-Version: 1.0
�target_versionz%s: %s
�_�-rcsg|]}tj��|d��qS)r)r?r@r�)r�rz�rur<r=r��s�z,easy_install.install_exe.<locals>.<listcomp>)r�r�)r5rr)�getrr?r@r��egg_namer/r$r*Z	_provider�
exe_to_eggrArr�itemsrS�titlerr�rIrKrZmake_zipfiler�r�r])r�rDr(�cfgr�rk�egg_tmpZ	_egg_infoZpkg_infrc�k�vr<ryr=r^�sJ�

�

 ��zeasy_install.install_execs6t|��g�g�i������fdd�}t|�|�g}�D]l}|���d�r<|�d�}|d}t�|d�d|d<tjj	�f|��}��
|�|�
|�t�||�q<|���t�
tj�	�d�t��|��dD]Z}	t�|	r�tj�	�d|	d	�}
tj�|
�s�t|
d
�}|�d�	t�|	�d�|��q�dS)
z;Extract a bdist_wininst to the directories an egg would usecs�|��}�D]�\}}|�|�r||t|�d�}|�d�}tjj�f|��}|��}|�d�sj|�d�r�t�	|d�|d<d�tj�
|d�d<��|�n4|�d�r�|dkr�d�tj�
|d�d<��|�|Sq|�d	�s�t�
d
|�dS)N�/�.pyd�.dll���rrr\�SCRIPTS/r
zWARNING: can't process %s)rrcr�r�r?r@r�r3r�strip_module�splitextr�rr�)�srcrFrG�old�new�partsr1�r��native_libs�prefixes�
to_compile�	top_levelr<r=�process�s$




z(easy_install.exe_to_egg.<locals>.processr�r�r�r\rg)r�r�z.txtr�rON)r7rrr3r�rr�r?r@r�r�Z
write_stub�byte_compileZwrite_safety_flagZanalyze_eggr�rArrr)r�rDr�r�Zstubs�resr��resourceZpyfiler�Ztxtrcr<r�r=r|�s8




�

zeasy_install.exe_to_eggc
Cs�t|�}|��st�tj�|j|���}tj�|�}|j	sBt
|�tj�|�rltj�|�slt
j||j	d�n"tj�|�r�|�tj|fd|�z.|�|j|fdtj�|�tj�|�f�W5t|dd�X|�|�|�|�S)NrlrmFrnzInstalling %s to %s)r Z
is_compatible�AssertionErrorr?r@r�rtr{rbr�r$r�r�r
rprAr�r�rrZinstall_as_eggrrr r6)r�Z
wheel_pathr(Zwheelrsr<r<r=r_!s4�

��	
zeasy_install.install_wheela(
        Because this distribution was installed --multi-version, before you can
        import modules from this package in an application, you will need to
        'import pkg_resources' and then use a 'require()' call similar to one of
        these examples, in order to select the desired version:

            pkg_resources.require("%(name)s")  # latest installed version
            pkg_resources.require("%(name)s==%(version)s")  # this exact version
            pkg_resources.require("%(name)s>=%(version)s")  # this version or higher
        z�
        Note also that the installation directory must be on sys.path at runtime for
        this to work.  (e.g. by being the application's script directory, by being on
        PYTHONPATH, or by being added to sys.path by your code.)
        �	Installedc	Cs^d}|jr>|js>|d|j7}|jtttj�kr>|d|j7}|j	}|j
}|j}d}|t�S)z9Helpful installation message for display to package usersz
%(what)s %(eggloc)s%(extras)srOr�)
r~r��_easy_install__mv_warningrtrr"r�r@�_easy_install__id_warningr/r4rpr�)	r�Zreqr�Zwhatr�Zegglocr�rpZextrasr<r<r=r<Osz easy_install.installation_reportaR
        Extracted editable version of %(spec)s to %(dirname)s

        If it uses setuptools in its setup script, you can activate it in
        "development" mode by going to that directory and running::

            %(python)s setup.py develop

        See the setuptools documentation for the "develop" command for more info.
        cCs"tj�|�}tj}d|jt�S)NrO)r?r@rr�r�_easy_install__editable_msgr�)r�r�rfr�pythonr<r<r=rdhszeasy_install.report_editablec
Cs�tj�dt�tj�dt�t|�}|jdkrNd|jd}|�dd|�n|jdkrd|�dd�|jrv|�dd	�t	�
d
|t|�dd�d�|��zt
||�Wn6tk
r�}ztd|jdf��W5d}~XYnXdS)
Nzdistutils.command.bdist_eggzdistutils.command.egg_infor�r�rrrx�-qz-nz
Running %s %s� zSetup script exited with %s)r��modules�
setdefaultrrr�r�r�r�rr�r�r�rr�rrz)r�rfrErzr�r<r<r=rms&

�zeasy_install.run_setupc		Cs�ddg}tjdtj�|�d�}z�|�	tj�|��|�
|�|�|||�t|g�}g}|D]&}||D]}|�
|�
|j|��qhq\|s�|js�t�d|�|W�St|�t�|j�XdS)Nrz
--dist-dirz
egg-dist-tmp-)r��dirz+No eggs found in %s (setup script problem?))r%r&r?r@rr�rr�r��_set_fetcher_optionsr�rr'r]r/r�r�)	r�rfrErzZdist_dirZall_eggsZeggsr#r�r<r<r=re�s*
�


�zeasy_install.build_and_installc	Csp|j�d���}d}i}|��D]&\}}||kr2q |d||�dd�<q t|d�}tj�|d�}t	�
||�dS)	a
        When easy_install is about to run bdist_egg on a source dist, that
        source dist might have 'setup_requires' directives, requiring
        additional fetching. Ensure the fetcher options given to easy_install
        are available to that command as well.
        r3)rxr�rwr{r�rrwrx)r3z	setup.cfgN)r�r��copyr}rS�dictr?r@r�rZedit_config)	r�rZei_optsZfetch_directivesZ
fetch_optionsr#r�ZsettingsZcfg_filenamer<r<r=r��s	
z!easy_install._set_fetcher_optionscCs*|jdkrdS|j|jD]H}|js0|j|jkrt�d|�|j�|�|j|jkr|j�|j�q|js�|j|jjkr�t�d|�n2t�d|�|j�	|�|j|jkr�|j�
|j�|j�s&|j��|jdk�r&t
j�|jd�}t
j�|�r�t
�|�t|d�}|�|j�|j�d�|��dS)Nz&Removing %s from easy-install.pth filez4%s is already the active version in easy-install.pthz"Adding %s to easy-install.pth filer��setuptools.pth�wtrO)r�r#r~r/rr�r;r��pathsr:r�r��saver?r@r�rtr�r�rr�
make_relativer)r�r�r]r�rcr<r<r=r9�s6
�


zeasy_install.update_pthcCst�d||�|S)NzUnpacking %s to %s)r�debug)r�r�rFr<r<r=ra�szeasy_install.unpack_progresscsdg�g����fdd�}t|||������js`�D]&}t�|�tjdBd@}t||�q8dS)NcsZ|�d�r |�d�s ��|�n|�d�s4|�d�r>��|���||��jrV|pXdS)Nr\�	EGG-INFO/r�z.so)r3rcr�rar�)r�rF�r�Zto_chmodr�r<r=�pf�s
z+easy_install.unpack_and_compile.<locals>.pfimi�)rr�r�r?�stat�ST_MODErW)r�rkrsr�rcrXr<r�r=rq�s
zeasy_install.unpack_and_compilec	Csjtjr
dSddlm}z@t�|jd�||dd|jd�|jrT|||jd|jd�W5t�|j�XdS)Nr)r�r)r{�forcer�)	r��dont_write_bytecode�distutils.utilr�rr�r�r�r{)r�r�r�r<r<r=r��s�
zeasy_install.byte_compilea�
        bad install directory or PYTHONPATH

        You are attempting to install a package to a directory that is not
        on PYTHONPATH and which Python does not read ".pth" files from.  The
        installation directory you specified (via --install-dir, --prefix, or
        the distutils default setting) was:

            %s

        and your PYTHONPATH environment variable currently contains:

            %r

        Here are some of your options for correcting the problem:

        * You can choose a different installation directory, i.e., one that is
          on PYTHONPATH or supports .pth files

        * You can add the installation directory to the PYTHONPATH environment
          variable.  (It must then also be on PYTHONPATH whenever you run
          Python and want to use the package(s) you are installing.)

        * You can set up the installation directory to support ".pth" files by
          using one of the approaches described here:

          https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations


        Please make the appropriate changes for your system and try again.cCs|j}||jtj�dd�fS�NZ
PYTHONPATHr�)�_easy_install__no_default_msgrtr?�environrz)r��templater<r<r=rsz#easy_install.no_default_version_msgc	Cs�|jr
dStj�|jd�}tdd�}|�d�}d}tj�|�r�t�	d|j�t
�|��}|��}W5QRX|�
d�s�td	|��||kr�t�d
|�|js�t|�t
j|ddd��}|�|�W5QRX|�|g�d
|_dS)z8Make sure there's a site.py in the target dir, if neededNzsite.pyr�z
site-patch.pyrRr�zChecking existing site.py in %sz
def __boot():z;%s is not a setuptools-generated site.py; please remove it.zCreating %sr���encodingT)r�r?r@r�rtr#rSrArr��ior�readrcrr�r�r$rr�)r�Zsitepy�sourceZcurrentZstrmr<r<r=r+#s0


��zeasy_install.install_site_pycCsd|js
dSttj�d��}t�|j�D]8\}}|�|�r&tj�	|�s&|�
d|�t�|d�q&dS)zCreate directories under ~.N�~zos.makedirs('%s', 0o700)i�)rqrr?r@r�rZ	iteritemsr�rcr�Zdebug_printr�)r��homer�r@r<r<r=r�Cszeasy_install.create_home_pathz/$base/lib/python$py_version_short/site-packagesz	$base/binr��r�z$base/Lib/site-packagesz
$base/ScriptscGs�|�d�j}|jrd|��}|j|d<|j�tj|j�}|�	�D]$\}}t
||d�dkr>t|||�q>ddlm
}|D]B}t
||�}|dk	rt|||�}tjdkr�tj�|�}t|||�qtdS)Nr�rr)rr�)Zget_finalized_commandr�r�r�r
rzr?r��DEFAULT_SCHEMEr}r�r�r�rr@r�)r�r�r�r7r�r�rr<r<r=r�Ys 



zeasy_install._expand)F)F)T)N)rTr<)r�)Q�__name__�
__module__�__qualname__�__doc__�descriptionZcommand_consumes_argumentsZuser_optionsZboolean_optionsr�r�r�Zhelp_msgr�Znegative_optrr�r�r�r��staticmethodr�r�r�r�r�r�r�r�r�r�rPrQ�lstriprrr	r�r�rr r"r$�
contextlib�contextmanagerr)r3r-r�r.r@rHrrrNrLr5r6r]r^r|r_r�r�r<r�rdrrer�r9rarqr�r�rr+r�r�r
r�r�r<r<r<r=r3~s���

0	

z	0	;


$
$	
'	



,6-5

% 
���cCs tj�dd��tj�}td|�Sr�)r?r�rzr��pathsep�filter)r}r<r<r=rpsrc	Cs~g}|�t��tjg}tjtjkr0|�tj�|D]�}|r4tjdkr^|�tj�	|dd��nVtj
dkr�|�tj�	|ddjtj�d�tj�	|dd�g�n|�|tj�	|dd�g�tjdkr4d	|kr4tj
�d
�}|r4tj�	|ddd
jtj�d�}|�|�q4td�td�f}|D]}||k�r|�|��qtj�rB|�tj�z|�t���Wntk
�rjYnXttt|��}|S)z&
    Return a list of 'site' dirs
    )Zos2emxZriscosZLibz
site-packagesr��libzpython{}.{}zsite-python�darwinzPython.framework�HOME�Library�Pythonr�ZpurelibZplatlib)�extendrr�r�r�r�rtr?r@r��sepr�r�r�rzrr�r�r��getsitepackages�AttributeErrorr�rr")�sitedirsr�r�r�Zhome_spZ	lib_pathsZsite_libr<r<r=r�us^


��
�

�
r�ccs�i}|D]�}t|�}||krqd||<tj�|�s4qt�|�}||fV|D]�}|�d�s\qL|dkrfqLttj�||��}tt	|��}|�
�|D]H}|�d�s�t|���}||kr�d||<tj�|�s�q�|t�|�fVq�qLqdS)zBYield sys.path directories that might contain "old-style" packagesrr
)r�r��importN)
r"r?r@r�rAr3rr�r�r!rrc�rstrip)Zinputs�seenrrr�rc�lines�liner<r<r=�expand_paths�s4



r�cCs@t|d�}�z$t�|�}|dkr*W��dS|d|d|d}|dkrRW��dS|�|d�t�d|�d��\}}}|dkr�W��dS|�|d|�d	d	d
�}t�	|�}z<|�|�}	|	�
dd�d
}
|
�t�
��}
|�t�|
��Wntjk
�rYW�.dSX|�d��r"|�d��s*W�dS|W�S|��XdS)znExtract configuration data from a bdist_wininst .exe

    Returns a configparser.RawConfigParser, or None
    �rbN�	���z<iii)izV4i{V4r�)rprv�rrrhZSetup)rr�zipfileZ_EndRecData�seekr:�unpackr�rZRawConfigParserr�rSr��getfilesystemencodingZreadfpr�StringIO�ErrorZhas_section)rDrcZendrecZ	prepended�tagZcfglenZbmlenZinitr�partZconfigr<r<r=r5�s4





c	Cs@dddddg}t�|�}z�|��D]�}|j}|�d�}t|�dkr�|dd	kr�|d
�d�r�|�dd�	|d
d��df��qt|�dks"|�d�s�q"|�d�r�q"|d�
�dkr"|�|�}tj
r�|��}t|�D]8}|���dd�}|�d�s�|�d|d|fdf�q�q"W5|��Xdd�|D�}|��|��|S)z4Get exe->egg path translations for a given .exe file)zPURELIB/r�)zPLATLIB/pywin32_system32r�)zPLATLIB/r�)r�zEGG-INFO/scripts/)zDATA/lib/site-packagesr�r�r�r�rurz	.egg-inforNr�r
z
-nspkg.pth)ZPURELIBZPLATLIB�\r�z%s/%s/r�cSsg|]\}}|��|f�qSr<)r)r�r_�yr<r<r=r�)sz$get_exe_prefixes.<locals>.<listcomp>)r�ZZipFilerZinfolistr�r�r�r3r�r��upperr�rZPY3rSr!rRrSrcr��sort�reverse)Zexe_filenamer�rXr�r�r�rGZpthr<r<r=r7s@�




"
c@sReZdZdZdZddd�Zdd�Zdd	�Zed
d��Z	dd
�Z
dd�Zdd�ZdS)r4z)A .pth file with Distribution paths in itFr<cCsl||_ttt|��|_ttj�|j��|_|�	�t
�|gdd�t|j
�D]}tt|jt|d���qLdS)NT)r�r�rr"r�r?r@r�basedir�_loadr'�__init__r!r�r:r&)r�r�r�r@r<r<r=r�4szPthDistributions.__init__cCs�g|_d}t�|j�}tj�|j�r�t|jd�}|D]�}|�	d�rHd}q4|�
�}|j�|�|��r4|���	d�rtq4t
tj�|j|��}|jd<tj�|�r�||kr�|j��d|_q4d||<q4|��|jr�|s�d|_|jr�|jd��s�|j��q�dS)NFZrtr�T�#r�r)r�r��fromkeysr�r?r@r`r�rrcr�r�rRr"r�r�rA�pop�dirtyr)r�Z
saw_importr�rcr�r@r<r<r=r�=s4
�


zPthDistributions._loadc	Cs�|js
dStt|j|j��}|r�t�d|j�|�|�}d�	|�d}t
j�|j�r`t
�
|j�t|jd��}|�|�W5QRXn(t
j�|j�r�t�d|j�t
�
|j�d|_dS)z$Write changed .pth file back to diskNz	Saving %srOr�zDeleting empty %sF)r�r�rr�r�rr�r��_wrap_linesr�r?r@r�r�rrrA)r�Z	rel_pathsr��datarcr<r<r=r�\s
zPthDistributions.savecCs|SrEr<)r�r<r<r=r�rszPthDistributions._wrap_linescCsN|j|jko$|j|jkp$|jt��k}|r>|j�|j�d|_t�||�dS)z"Add `dist` to the distribution mapTN)	r/r�r�r?�getcwdr�r�r'r:)r�r��new_pathr<r<r=r:vs�zPthDistributions.addcCs2|j|jkr"|j�|j�d|_qt�||�dS)z'Remove `dist` from the distribution mapTN)r/r�r;r�r'r?r<r<r=r;�szPthDistributions.removecCs�tj�t|��\}}t|j�}|g}tjdkr2dp6tj}t|�|kr�||jkrl|�tj	�|�
�|�|�Stj�|�\}}|�|�q8|S)Nr�)r?r@r�r"r�r��altsepr�r��curdirr�r�)r�r@ZnpathZlastZbaselenr�r�r<r<r=r��s


zPthDistributions.make_relativeN)r<)
r�r�r�r�r�r�r�r�r�r�r:r;r�r<r<r<r=r4/s
	
c@s(eZdZedd��Zed�Zed�ZdS)�RewritePthDistributionsccs$|jV|D]
}|Vq|jVdSrE)�prelude�postlude)�clsr�r�r<r<r=r��sz#RewritePthDistributions._wrap_linesz?
        import sys
        sys.__plen = len(sys.path)
        z�
        import sys
        new = sys.path[sys.__plen:]
        del sys.path[sys.__plen:]
        p = getattr(sys, '__egginsert', 0)
        sys.path[p:p] = new
        sys.__egginsert = p + len(new)
        N)r�r�r��classmethodr�rr�r�r<r<r<r=r��s
r�ZSETUPTOOLS_SYS_PATH_TECHNIQUE�rawZrewritecCs ttjt�rtSt�tj���S)z_
    Return a regular expression based on first_line_re suitable for matching
    strings.
    )r�r�patternr'�re�compilerSr<r<r<r=�_first_line_re�srcCsd|tjtjfkr.tjdkr.t|tj�||�St��\}}}t	�
||d|dd||ff�dS)Nr�rrz %s %s)r?r�r;r�rWr��S_IWRITEr�rrZreraise)�func�arg�excZetZevrwr<r<r=�
auto_chmod�s
r	cCs.t|�}t|tj�|r"t|�nt|�dS)aa

    Fix any globally cached `dist_path` related data

    `dist_path` should be a path of a newly installed egg distribution (zipped
    or unzipped).

    sys.path_importer_cache contains finder objects that have been cached when
    importing data from the original distribution. Any such finders need to be
    cleared since the replacement distribution might be packaged differently,
    e.g. a zipped egg distribution might get replaced with an unzipped egg
    folder or vice versa. Having the old finders cached may then cause Python
    to attempt loading modules from the replacement distribution using an
    incorrect loader.

    zipimport.zipimporter objects are Python loaders charged with importing
    data packaged inside zip archives. If stale loaders referencing the
    original distribution, are left behind, they can fail to load modules from
    the replacement distribution. E.g. if an old zipimport.zipimporter instance
    is used to load data from a new zipped egg archive, it may cause the
    operation to attempt to locate the requested data in the wrong location -
    one indicated by the original distribution's zip archive directory
    information. Such an operation may then fail outright, e.g. report having
    read a 'bad local file header', or even worse, it may fail silently &
    return invalid data.

    zipimport._zip_directory_cache contains cached zip archive directory
    information for all existing zipimport.zipimporter instances and all such
    instances connected to the same archive share the same cached directory
    information.

    If asked, and the underlying Python implementation allows it, we can fix
    all existing zipimport.zipimporter instances instead of having to track
    them down and remove them one by one, by updating their shared cached zip
    archive directory information. This, of course, assumes that the
    replacement distribution is packaged as a zipped egg.

    If not asked to fix existing zipimport.zipimporter instances, we still do
    our best to clear any remaining zipimport.zipimporter related cached data
    that might somehow later get used when attempting to load data from the new
    distribution and thus cause such load operations to fail. Note that when
    tracking down such remaining stale data, we can not catch every conceivable
    usage from here, and we clear only those that we know of and have found to
    cause problems if left alive. Any remaining caches should be updated by
    whomever is in charge of maintaining them, i.e. they should be ready to
    handle us replacing their zip archives with new distributions at runtime.

    N)r"�_uncacher��path_importer_cache�!_replace_zip_directory_cache_data�*_remove_and_clear_zip_directory_cache_data)Z	dist_pathro�normalized_pathr<r<r=rr�s
<
rrcCsPg}t|�}|D]:}t|�}|�|�r|||d�tjdfkr|�|�q|S)ap
    Return zipimporter cache entry keys related to a given normalized path.

    Alternative path spellings (e.g. those using different character case or
    those using alternative path separators) related to the same path are
    included. Any sub-path entries are included as well, i.e. those
    corresponding to zip archives embedded in other zip archives.

    rr�)r�r"rcr?r�r�)r�cache�result�
prefix_len�pZnpr<r<r=�"_collect_zipimporter_cache_entriess

�rcCs@t||�D]0}||}||=|o(|||�}|dk	r
|||<q
dS)a�
    Update zipimporter cache data for a given normalized path.

    Any sub-path entries are processed as well, i.e. those corresponding to zip
    archives embedded in other zip archives.

    Given updater is a callable taking a cache entry key and the original entry
    (after already removing the entry from the cache), and expected to update
    the entry and possibly return a new one to be inserted in its place.
    Returning None indicates that the entry should not be replaced with a new
    one. If no updater is given, the cache entries are simply removed without
    any additional processing, the same as if the updater simply returned None.

    N)r)rr�updaterr�	old_entryZ	new_entryr<r<r=�_update_zipimporter_cache/s
rcCst||�dSrE)r)rrr<r<r=r
Osr
cCsdd�}t|tj|d�dS)NcSs|��dSrE)�clear�r@rr<r<r=�2clear_and_remove_cached_zip_archive_directory_dataTszf_remove_and_clear_zip_directory_cache_data.<locals>.clear_and_remove_cached_zip_archive_directory_data�r�rri�_zip_directory_cache)rrr<r<r=r
Ss�r
Z__pypy__cCsdd�}t|tj|d�dS)NcSs&|��t�|�|�tj|�|SrE)rrirj�updaterrr<r<r=�)replace_cached_zip_archive_directory_datajs
zT_replace_zip_directory_cache_data.<locals>.replace_cached_zip_archive_directory_datarr)rrr<r<r=ris
�r�<string>c	Cs4zt||d�Wnttfk
r*YdSXdSdS)z%Is this string a valid Python script?�execFTN)r�SyntaxError�	TypeError)rTr�r<r<r=�	is_python|s
r#c	CsNz(tj|dd��}|�d�}W5QRXWnttfk
rD|YSX|dkS)zCDetermine if the specified executable is a .sh (contains a #! line)zlatin-1r�r��#!)r�rr�r�r�)r�fp�magicr<r<r=�is_sh�s
r'cCst�|g�S)z@Quote a command line argument according to Windows parsing rules��
subprocess�list2cmdline)rr<r<r=�nt_quote_arg�sr+cCsH|�d�s|�d�rdSt||�r&dS|�d�rDd|��d��kSdS)zMIs this text, as a whole, a Python script? (as opposed to shell/bat/etc.
    r\�.pywTr$r�rF)r3r#rc�
splitlinesr)rPr�r<r<r=rM�s

rM)rWcGsdSrEr<)rzr<r<r=�_chmod�sr.c
CsRt�d||�zt||�Wn0tjk
rL}zt�d|�W5d}~XYnXdS)Nzchanging mode of %s to %ozchmod failed: %s)rr�r.r?�error)r@rXrjr<r<r=rW�s
rWc@s�eZdZdZgZe�Zedd��Zedd��Z	edd��Z
edd	��Zed
d��Zdd
�Z
edd��Zdd�Zedd��Zedd��ZdS)�CommandSpeczm
    A command spec for a #! header, specified as a list of arguments akin to
    those passed to Popen.
    cCs|S)zV
        Choose the best CommandSpec class based on environmental conditions.
        r<�r�r<r<r=rJ�szCommandSpec.bestcCstj�tj�}tj�d|�S)N�__PYVENV_LAUNCHER__)r?r@rCr�rr�rz)r�Z_defaultr<r<r=�_sys_executable�szCommandSpec._sys_executablecCs:t||�r|St|t�r ||�S|dkr0|��S|�|�S)zg
        Construct a CommandSpec from a parameter to build_scripts, which may
        be None.
        N)r�r��from_environment�from_string)r�Zparamr<r<r=�
from_param�s

zCommandSpec.from_paramcCs||��g�SrE)r3r1r<r<r=r4�szCommandSpec.from_environmentcCstj|f|j�}||�S)z}
        Construct a command spec from a simple string representing a command
        line parseable by shlex.split.
        )�shlexr��
split_args)r��stringr}r<r<r=r5�szCommandSpec.from_stringcCs8t�|�|��|_t�|�}t|�s4dg|jdd�<dS)Nz-xr)r7r��_extract_options�optionsr)r*rL)r�rP�cmdliner<r<r=�install_options�s
zCommandSpec.install_optionscCs:|d��d}t��|�}|r.|�d�p0dnd}|��S)zH
        Extract any options from the first line of the script.
        rOrrr�)r-r�match�grouprR)Zorig_script�firstr>r;r<r<r=r:�szCommandSpec._extract_optionscCs|�|t|j��SrE)�_renderr�r;r�r<r<r=�	as_header�szCommandSpec.as_headercCs6d}|D](}|�|�r|�|�r|dd�Sq|S)Nz"'rr�)rcr3)�itemZ_QUOTES�qr<r<r=�
_strip_quotes�s
zCommandSpec._strip_quotescCs t�dd�|D��}d|dS)Ncss|]}t�|���VqdSrE)r0rErR)r�rCr<r<r=r�sz&CommandSpec._render.<locals>.<genexpr>r$rOr()r}r<r<r<r=rA�s
�zCommandSpec._renderN)r�r�r�r�r;r�r8r�rJr3r6r4r5r=r�r:rBrErAr<r<r<r=r0�s*





	
r0c@seZdZedd�ZdS)�WindowsCommandSpecFr�N)r�r�r�r�r8r<r<r<r=rF
srFc@s�eZdZdZe�d���ZeZ	e
ddd��Ze
ddd��Ze
dd	d
��Z
edd��Ze
d
d��Ze
dd��Ze
dd��Ze
ddd��ZdS)rIz`
    Encapsulates behavior around writing entry point scripts for console and
    gui apps.
    a�
        # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r
        __requires__ = %(spec)r
        import re
        import sys
        from pkg_resources import load_entry_point

        if __name__ == '__main__':
            sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
            sys.exit(
                load_entry_point(%(spec)r, %(group)r, %(name)r)()
            )
    NFcCs6t�dt�|rtnt��}|�d||�}|�||�S)NzUse get_argsr�)�warningsr��EasyInstallDeprecationWarning�WindowsScriptWriterrIrJ�get_script_headerrK)r�r�r�wininst�writer�headerr<r<r=�get_script_args$szScriptWriter.get_script_argscCs$tjdtdd�|rd}|�||�S)NzUse get_headerr�)�
stacklevelr
)rGr�rHrO)r�rPrrKr<r<r=rJ,szScriptWriter.get_script_headerccs�|dkr|��}t|���}dD]Z}|d}|�|���D]>\}}|�|�|jt�}|�||||�}	|	D]
}
|
Vqlq:q dS)z�
        Yield write_script() argument tuples for a distribution's
        console_scripts and gui_scripts entry points.
        N�Zconsole�guiZ_scripts)	rOr'r>Z
get_entry_mapr}�_ensure_safe_namer�r��_get_script_args)r�r�rMr��type_r?r�ZeprPrzr�r<r<r=rK4s
zScriptWriter.get_argscCst�d|�}|rtd��dS)z?
        Prevent paths in *_scripts entry point names.
        z[\\/]z+Path separators not allowed in script namesN)r�searchr�)r�Zhas_path_sepr<r<r=rRFszScriptWriter._ensure_safe_namecCs t�dt�|rt��S|��S�NzUse best)rGr�rHrIrJ)r�Z
force_windowsr<r<r=�
get_writerOszScriptWriter.get_writercCs.tjdkstjdkr&tjdkr&t��S|SdS)zD
        Select the best ScriptWriter for this environment.
        �win32�javar�N)r�rtr?r��_namerIrJr1r<r<r=rJUszScriptWriter.bestccs|||fVdSrEr<)r�rTr�rMrPr<r<r=rS_szScriptWriter._get_script_argsr�cCs"|j���|�}|�|�|��S)z;Create a #! line, getting options (if any) from script_text)�command_spec_classrJr6r=rB)r�rPr�cmdr<r<r=rOds
zScriptWriter.get_header)NF)NF)N)r�N)r�r�r�r�rPrQr�r�r0r[r�rNrJrKr�rRrWrJrSrOr<r<r<r=rIs&


	
rIc@sLeZdZeZedd��Zedd��Zedd��Zedd��Z	e
d	d
��ZdS)rIcCst�dt�|��SrV)rGr�rHrJr1r<r<r=rWoszWindowsScriptWriter.get_writercCs"tt|d�}tj�dd�}||S)zC
        Select the best ScriptWriter suitable for Windows
        )rZnaturalZSETUPTOOLS_LAUNCHERr)r��WindowsExecutableLauncherWriterr?r�rz)r�Z
writer_lookupZlauncherr<r<r=rJus�zWindowsScriptWriter.bestc	#s�tddd�|}|tjd���d�krBdjft��}t�|t	�dddd	d
ddg}|�
|�|�||�}�fdd
�|D�}�|||d|fVdS)z For Windows, add a .py extensionz.pyar,rPZPATHEXT�;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.r\�
-script.py�.pyc�.pyor[csg|]}�|�qSr<r<rU�r�r<r=r��sz8WindowsScriptWriter._get_script_args.<locals>.<listcomp>rTN)r�r?r�rr�r�r�rGr��UserWarningr;�_adjust_header)	r�rTr�rMrP�extr�r�r�r<rbr=rS�s��
z$WindowsScriptWriter._get_script_argscCsNd}d}|dkr||}}t�t�|�tj�}|j||d�}|�|�rJ|S|S)z�
        Make sure 'pythonw' is used for gui and and 'python' is used for
        console (regardless of what sys.executable is).
        rr
rQ)r9�repl)rr�escape�
IGNORECASE�sub�_use_header)r�rTZorig_headerrrfZ
pattern_ob�
new_headerr<r<r=rd�s
z"WindowsScriptWriter._adjust_headercCs$|dd��d�}tjdkp"t|�S)z�
        Should _adjust_header use the replaced header?

        On non-windows systems, always use. On
        Windows systems, only use the replaced header if it resolves
        to an executable on the system.
        r�r��"rX)rRr�rtr)rkZclean_headerr<r<r=rj�s	zWindowsScriptWriter._use_headerN)r�r�r�rFr[r�rWrJrSrdr�rjr<r<r<r=rIls




rIc@seZdZedd��ZdS)r]c#s�|dkrd}d}dg}nd}d}dddg}|�||�}�fd	d
�|D�}	�|||d|	fV�dt|�d
fVt�s��d}
|
t��dfVdS)zG
        For Windows, add a .py extension and an .exe launcher
        rQz-script.pywr,Zclir_r\r`racsg|]}�|�qSr<r<rUrbr<r=r��szDWindowsExecutableLauncherWriter._get_script_args.<locals>.<listcomp>rTr[rdz
.exe.manifestN)rd�get_win_launcherr>�load_launcher_manifest)r�rTr�rMrPZ
launcher_typerer�Zhdrr�Zm_namer<rbr=rS�s"
�z0WindowsExecutableLauncherWriter._get_script_argsN)r�r�r�r�rSr<r<r<r=r]�sr]cCs2d|}t�r|�dd�}n|�dd�}td|�S)z�
    Load the Windows launcher (executable) suitable for launching a script.

    `type` should be either 'cli' or 'gui'

    Returns the executable as a byte string.
    z%s.exe�.z-64.z-32.r�)r>rSr#)�typeZlauncher_fnr<r<r=rm�s
rmcCs0t�td�}tjr|t�S|�d�t�SdS)Nzlauncher manifest.xmlrR)rr#r�r�PY2�varsrS)r�Zmanifestr<r<r=rn�s
rnFcCst�|||�SrE)rBr�)r@�
ignore_errors�onerrorr<r<r=r��sr�cCst�d�}t�|�|S)N�)r?�umask)Ztmpr<r<r=rV�s

rVcCs:ddl}tj�|jd�}|tjd<tj�|�t�dS)Nr)	r�r?r@r�__path__r��argvr�r6)r�Zargv0r<r<r=�	bootstrap�s

ryc	s�ddlm}ddlm�G�fdd�d��}|dkrBtjdd�}t��0|fddd	g|tjdpfd|d
�|��W5QRXdS)Nr)�setup�r)cseZdZdZ�fdd�ZdS)z-main.<locals>.DistributionWithoutHelpCommandsr�c	s(t���j|f|�|�W5QRXdSrE)�_patch_usage�
_show_help)r�rz�kwr{r<r=r}	sz8main.<locals>.DistributionWithoutHelpCommands._show_helpN)r�r�r�Zcommon_usager}r<r{r<r=�DistributionWithoutHelpCommands	srrr�r3z-v)Zscript_argsrZ	distclass)r�rzZsetuptools.distr)r�rxr|)rxr~rzrr<r{r=r6�s��c#sLddl}t�d�����fdd�}|jj}||j_z
dVW5||j_XdS)Nrze
        usage: %(script)s [options] requirement_or_url ...
           or: %(script)s --help
        cs�ttj�|�d�S)N)Zscript)r�r?r@r)r�ZUSAGEr<r=�	gen_usage	s
�z_patch_usage.<locals>.gen_usage)Zdistutils.corerPrQr�Zcorer�)r�r�Zsavedr<r�r=r|	s
r|c@seZdZdZdS)rHzuClass for warning about deprecations in EasyInstall in SetupTools. Not ignored by default, unlike DeprecationWarning.N)r�r�r�r�r<r<r<r=rH(	srH)N)r)N)�r�rr�rrrZdistutils.errorsrrrr	Zdistutils.command.installr
rr�rr
Zdistutils.command.build_scriptsrrrr�r?rirBr%r�rr�r�rPrGr�r:r�r)r7r�Z	sysconfigrrr�rZsetuptools.externrZsetuptools.extern.six.movesrrrZsetuptools.sandboxrZsetuptools.py27compatrZsetuptools.commandrZsetuptools.archive_utilrZsetuptools.package_indexrrrrrZsetuptools.wheelr rr!r"r#r$r%r&r'r(r)r*r+r,r-r.r/Zpkg_resources.py31compatrpZ
__metaclass__�filterwarningsZ
PEP440Warning�__all__r>r2rqrHrLrr3rr�r�r5r7r4r�r�rzrr	rrrrr
r
�builtin_module_namesrr#r'r+rMrWr.�ImportErrorr�r0r3Zsys_executablerFrIrIr]rNrJrmrnr�rVryr6r�r|rHr<r<r<r=�<module>s�D�
{A))'lR
 �


T^A 




?>