Your IP : 18.119.255.183


Current Path : /usr/lib/python3.6/site-packages/setuptools/command/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/setuptools/command/__pycache__/easy_install.cpython-36.pyc

3

9��f�T�@sdZddlmZddlmZddlmZmZddlmZmZm	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'ddl(m)Z)m*Z*dd
l+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9m:Z:m;Z;ddl4m<Z<m=Z=ddl>m?Z?ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOdd
lPZ@ejQde@jRd�ddddddgZSdd �ZTd!d�ZUe'jV�r2d"d#�ZWd$d%�ZXnd&d#�ZWd'd%�ZXd(d)�ZYGd*d�de,�ZZd+d,�Z[d-d.�Z\d/d0�Z]d1d�Z^d2d�Z_Gd3d�deG�Z`Gd4d5�d5e`�Zaejbjcd6d7�d8k�r�eaZ`d9d:�Zdd;d<�Zed=d>�Zfd?d@�ZgdpdAdB�ZhdCdD�ZidEdF�ZjdGejkk�rejZlndHdI�ZldqdKdL�ZmdMdN�ZndOdP�ZodQdR�ZpyddSlmqZrWnesk
�r^dTdU�ZrYnXdVdW�ZqGdXdY�dYet�Zueujv�ZwGdZd[�d[eu�ZxGd\d]�d]ey�ZzGd^d_�d_ez�Z{Gd`da�dae{�Z|ezj}Z}ezj~Z~dbdc�Zddde�Z�dfeefdgdh�Z�didj�Z�dkdl�Z�drdmd�Z�e"j�dndo��Z�d
S)sa%
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)�six)�configparser�map)�Command)�	run_setup)�get_path�get_config_vars)�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_prefixescCstjd�dkS)N�P�)�struct�calcsize�r;r;�"/usr/lib/python3.6/easy_install.py�is_64bitIsr=cCsjtjj|�otjj|�}ttjd�o&|}|r:tjj||�Stjjtjj|��}tjjtjj|��}||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.
    r1)�os�path�exists�hasattrr1�normpath�normcase)Zp1Zp2Z
both_existZuse_samefileZnorm_p1Znorm_p2r;r;r<r1MscCs|S)Nr;)�sr;r;r<�	_to_ascii_srEcCs*ytj|d�dStk
r$dSXdS)N�asciiTF)rZ	text_type�UnicodeError)rDr;r;r<�isasciibs
rHcCs
|jd�S)NrF)�encode)rDr;r;r<rEjscCs(y|jd�dStk
r"dSXdS)NrFTF)rIrG)rDr;r;r<rHms

cCstj|�j�jdd�S)N�
z; )�textwrap�dedent�strip�replace)�textr;r;r<�<lambda>usrPc@s�eZdZdZdZdZd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�gZdd
dd
dd0d3d9d<g	Zej	�r�d@ej
ZejdAdef�ejdA�d*diZ
eZdBdC�ZdDdE�ZdFdG�ZedHdI��ZdJdK�ZdLdM�ZdNdO�ZdPdQ�ZdRdS�ZdTdU�ZdVdW�ZdXdY�ZdZd[�Zejd\�j �Z!ejd]�j �Z"ejd^�j �Z#d_d`�Z$dadb�Z%dcdd�Z&dedf�Z'dgdh�Z(didj�Z)e*j+dkdl��Z,d�dndo�Z-d�dpdq�Z.drds�Z/d�dtdu�Z0dvdw�Z1dxdy�Z2dzd{�Z3d�d|d}�Z4ed~d��Z5d�ffd�d��Z6d�d��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<ejd��j �Z=ejd��Z>d�d�d��Z?ejd��j �Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHejd��j �ZId�d��ZJd�d��ZKd�d��ZLeMeMd�d�d��d��ZNeMd�d�d��ZOd�d��ZPdS)�r2z'Manage a download/build/install processz Find/get/install Python packagesT�prefix=N�installation prefix�zip-ok�z�install package as a zipfile�
multi-version�m�%make apps have to require() a version�upgrade�U�1force upgrade (searches PyPI for latest versions)�install-dir=�d�install package to DIR�script-dir=rD�install scripts to DIR�exclude-scripts�x�Don't install scripts�always-copy�a�'Copy all needed packages to install dir�
index-url=�i� base URL of Python Package Index�find-links=�f�(additional URL(s) to search for packages�build-directory=�b�/download/extract/build in DIR; keep the results�	optimize=�O�lalso compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]�record=�3filename in which to record list of installed files�always-unzip�Z�*don't install as a zipfile, no matter what�
site-dirs=�S�)list of directories where .pth files work�editable�e�+Install specified packages in editable form�no-deps�N�don't install dependencies�allow-hosts=�H�$pattern(s) that hostnames must match�local-snapshots-ok�l�(allow building eggs from local checkouts�version�"print version information and exit�
no-find-links�9Don't load find-links defined in packages being installedz!install in user site-package '%s'�usercCs,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.||j,j/d��dS)NrFr2)0r��zip_ok�local_snapshots_ok�install_dir�
script_dir�exclude_scripts�	index_url�
find_links�build_directory�args�optimize�recordrY�always_copy�
multi_versionr{�no_deps�allow_hosts�root�prefix�	no_reportr��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�sF

zeasy_install.initialize_optionscCs"dd�|D�}tt|j|��dS)Ncss*|]"}tjj|�stjj|�r|VqdS)N)r>r?r@�islink)�.0�filenamer;r;r<�	<genexpr>�sz/easy_install.delete_blockers.<locals>.<genexpr>)�listr�_delete_path)r��blockersZextant_blockersr;r;r<�delete_blockers�szeasy_install.delete_blockerscCsJtjd|�|jrdStjj|�o.tjj|�}|r8tntj}||�dS)NzDeleting %s)	r�info�dry_runr>r?�isdirr��rmtree�unlink)r�r?Zis_treeZremoverr;r;r<r��szeasy_install._delete_pathcCs6tjdd�}td�}d}t|jft���t��dS)zT
        Render the Setuptools version and installation details, then exit.
        N��
setuptoolsz=setuptools {dist.version} from {dist.location} (Python {ver}))�sysr�r$�print�format�locals�
SystemExit)Zver�dist�tmplr;r;r<�_render_version�s
zeasy_install._render_versionc	Cst|jo|j�tjj�d}tdd�\}}|jj�|jj�|jj�||dd�|d|d||||t	tdd�d�|_
tjr�|j
|j
d	<|j|j
d
<|j�|j�|j�|jddd
d�|jdkr�|j|_|jdkr�d|_|jdd!�|jdd"�|j�r|j�r|j|_|j|_|jdd#�tttj�}t�|_|jdk	�r�dd�|jjd�D�}xV|D]N}t jj!|��s~t"j#d|�n,t|�|k�r�t$|d��n|jj%t|���q^W|j&�s�|j'�|j(�p�d|_(|jdd�|_)x4|jt|j�fD] }||j)k�r�|j)j*d|��q�W|j+dk	�r8dd�|j+jd�D�}ndg}|j,dk�r`|j-|j(|j)|d�|_,t.|j)tj�|_/|j0dk	�r�t1|j0t2j3��r�|j0j�|_0ng|_0|j4�r�|j,j5|j)tj�|j�s�|j,j6|j0�|jdd$�t1|j7t8��s@y2t8|j7�|_7d|j7k�odkn�st9�Wnt9k
�r>t$d��YnX|j&�rZ|j:�rZt;d��|j<�sjt;d ��g|_=dS)%Nrr��exec_prefixr���abiflags�)Z	dist_nameZdist_versionZ
dist_fullname�
py_version�py_version_short�py_version_nodotZ
sys_prefixr�Zsys_exec_prefixr�r��userbaseZusersiter�r�r�r�Fr�r��installr�cSsg|]}tjj|j���qSr;)r>r?�
expanduserrM)r�rDr;r;r<�
<listcomp>3sz1easy_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|]}|j��qSr;)rM)r�rDr;r;r<r�Hs�*)Zsearch_path�hostsr�z--optimize must be 0, 1, or 2z9Must specify a build directory (-b) when using --editablez:No urls, filenames, or requirements specified (see --help))r�r�)r�r�)r�r�)r�r�)>r�r�r��splitrr�Zget_nameZget_versionZget_fullname�getattr�config_varsr�r�r�r��_fix_install_dir_for_user_site�expand_basedirs�expand_dirs�_expandr�r�r�Zset_undefined_optionsr�r�r�rr!r?�
get_site_dirs�
all_site_dirsr�r>r�r�warnr�appendr{�check_site_dirr��shadow_path�insertr�r��create_indexr&�local_indexr��
isinstancerZstring_typesr�Zscan_egg_links�add_find_linksr��int�
ValueErrorr�rr��outputs)	r�r�r�r�rBr�r]Z	path_itemr�r;r;r<�finalize_options�s�



zeasy_install.finalize_optionscCs`|jstjrdS|j�|jdkr2d}t|��|j|_|_tj	j
dd�d}|j|�dS)z;
        Fix the install_dir if "--user" was used.
        Nz$User base directory is not specified�posixZunixZ_user)r�r�r��create_home_pathr�r	r�r�r>�namerN�
select_scheme)r��msgZscheme_namer;r;r<r�ms
z+easy_install._fix_install_dir_for_user_sitecCs\xV|D]N}t||�}|dk	rtjdks0tjdkr<tjj|�}t||j�}t|||�qWdS)Nr��nt)r�r>r�r?r�rr��setattr)r��attrs�attr�valr;r;r<�
_expand_attrs|s

zeasy_install._expand_attrscCs|jdddg�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}|j|�dS)z+Calls `os.path.expanduser` on install dirs.r�r�r�r�r�r�N)r�)r��dirsr;r;r<r��szeasy_install.expand_dirscCs�|j|jjkrtj|j�z�x|jD]}|j||j�q$W|jr�|j}|j	r�t
|j	�}x(tt
|��D]}|||d�||<qfWddlm
}|j|j|j|fd|j�|j�Wdtj|jj�XdS)Nr)�	file_utilz'writing list of installed files to '%s')r�r�r�
set_verbosityr�r2r�r�r�r��len�range�	distutilsr��executeZ
write_file�warn_deprecated_options)r��specr�Zroot_lenZcounterr�r;r;r<�run�s$

zeasy_install.runcCsDytj�}Wn"tk
r.tjdtj�}YnXtjj|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?�joinr�)r��pidr;r;r<�pseudo_tempname�s
zeasy_install.pseudo_tempnamecCsdS)Nr;)r�r;r;r<r�sz$easy_install.warn_deprecated_optionscCsdt|j�}tjj|d�}tjj|�sTytj|�Wn ttfk
rR|j	�YnX||j
k}|rv|jrv|j�}nd|j
�d}tjj|�}y*|r�tj|�t|d�j�tj|�Wn ttfk
r�|j	�YnX|r�|jr�t|j���|�r|jdk�rt||j
�|_nd|_|ttt��k�r6d|_n$|j�rZtjj|��rZd|_d|_||_dS)z;Verify that self.install_dir is .pth-capable dir, if neededzeasy-install.pthz.write-test�wNT)r!r�r>r?rr@�makedirs�OSError�IOError�cant_write_to_targetr�r��check_pth_processingrr��open�closer�no_default_version_msgr�r3r�_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|jtj�d|jf}tjj|j�s6|d|j7}n|d|j7}t	|��dS)N�rJ)
�_easy_install__cant_write_msgr��exc_infor�r>r?r@�_easy_install__not_exists_id�_easy_install__access_msgr)r�r�r;r;r<rs
z!easy_install.cant_write_to_targetc
Cs�|j}tjd|�|j�d}|d}tjj|�}td�d}y8|rNtj|�tjj	|�}t
jj|dd�t
|d�}Wn ttfk
r�|j�Yn�Xz�|j|jft���|j�d	}tj}tjd
k�rtjj|�\}}	tjj|d�}
|	j�dk�otjj|
�}|�r|
}d
dlm}||dddgd
�tjj|��rJtjd|�dSWd	|�r\|j�tjj|��rttj|�tjj|��r�tj|�X|j�s�tjd|�dS)z@Empirically verify whether .pth files are supported in inst. dirz Checking .pth file support in %sz.pthz.okzz
            import os
            f = open({ok_file!r}, 'w')
            f.write('OK')
            f.close()
            rJT)�exist_okrNr�zpythonw.exez
python.exer)�spawnz-Ez-c�passz-TEST PASSED: %s appears to support .pth filesz+TEST FAILED: %s does NOT support .pth filesF)r�rr�rr>r?r@�
_one_linerr��dirname�
pkg_resourcesZ
py31compatrrrrr�writer�r�rr��
executabler�r�r�lower�distutils.spawnr r�r�)
r�rr�Zok_fileZ	ok_existsr�r#rkr&�basenameZaltZuse_altr r;r;r<rsV


z!easy_install.check_pth_processingcCs\|jrN|jd�rNx:|jd�D],}|jd|�r2q|j|||jd|��qW|j|�dS)z=Write all the scripts for `dist`, unless scripts are excluded�scriptszscripts/N)r�Zmetadata_isdirZmetadata_listdir�install_scriptZget_metadata�install_wrapper_scripts)r�r��script_namer;r;r<�install_egg_scriptsSsz easy_install.install_egg_scriptscCs\tjj|�rLxJtj|�D].\}}}x"|D]}|jjtjj||��q(WqWn|jj|�dS)N)r>r?r��walkr�r�r)r�r?�baser��filesr�r;r;r<�
add_outputas

 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).)r{r)r�rr;r;r<�not_editableiszeasy_install.not_editablecCs<|js
dStjjtjj|j|j��r8td|j|jf��dS)Nz2%r already exists in %s; can't do a checkout there)r{r>r?r@rr��keyr)r�rr;r;r<�check_editableqszeasy_install.check_editableccs@tjtjd�d�}zt|�VWdtjj|�o8tt	|��XdS)Nz
easy_install-)r�)
�tempfile�mkdtempr�u�strr>r?r@r�r)r��tmpdirr;r;r<�_tmpdir{szeasy_install._tmpdirFcCs|js|j�|j���}t|t�s�t|�rT|j|�|jj||�}|j	d|||d�St
jj|�r||j|�|j	d|||d�St
|�}|j|�|jj|||j|j|j|j�}|dkr�d|}|jr�|d7}t|��n0|jtkr�|j|||d�|S|j	||j||�SWdQRXdS)NTz+Could not find suitable distribution for %rz2 (--always-copy skips system and development eggs)�Using)r{�install_site_pyr;r�r'rr3r��download�install_itemr>r?r@rr5Zfetch_distributionrYr�r�rZ
precedencer.�process_distribution�location)r�r�depsr:�dlr�r�r;r;r<r2�s2






zeasy_install.easy_installcCs|p|j}|ptjj|�|k}|p,|jd�}|pT|jdk	oTtjjt|��t|j�k}|r�|r�x$|j|jD]}|j	|krnPqnWd}t
jdtjj|��|r�|j
|||�}x<|D]}|j|||�q�Wn |j|�g}|j||d|d�|dk	�rx|D]}||kr�|Sq�WdS)Nz.eggTz
Processing %srr<)r�r>r?r#�endswithr�r!r��project_namerArr�r)�install_eggsr@�egg_distribution)r�rr>r:rBZinstall_neededr�Zdistsr;r;r<r?�s.






zeasy_install.install_itemcCs@t|}x2tD]*}d|}t||�dkrt||||�qWdS)z=Sets the install directories by applying the install schemes.Zinstall_N)r
rr�r�)r�r��schemer4Zattrnamer;r;r<r��s

zeasy_install.select_schemecGs�|j|�|jj|�||j|jkr2|jj|�|jj|�|j|�||j|j<tj	|j
||f|���|jd�r�|jr�|jj
|jd��|r�|jr�dS|dk	r�|j|jkr�tjd|�dS|dks�||kr�|j�}tt|��}tj	d|�ytg�j|g|j|j�}Wn^tk
�rB}ztt|���WYdd}~Xn0tk
�rp}zt|j���WYdd}~XnX|j�s�|j�r�x*|D]"}|j|jk�r�|j|j���q�Wtj	d|�dS)Nzdependency_links.txtzSkipping dependencies for %szProcessing dependencies for %sz'Finished processing dependencies for %s)�
update_pthr��addr�r4�remover.r�rr��installation_report�has_metadatar�r�Zget_metadata_linesr�r��as_requirementr'r9r+Zresolver2r,rr-Zreportr�)r�Zrequirementr�rBr�ZdistreqZdistrosr|r;r;r<r@�sB



z!easy_install.process_distributioncCs2|jdk	r|jS|jd�r dS|jd�s.dSdS)Nznot-zip-safeTzzip-safeF)r�rM)r�r�r;r;r<�should_unzip�s


zeasy_install.should_unzipcCs�tjj|j|j�}tjj|�r:d}tj||j|j|�|Stjj|�rL|}nRtjj	|�|krftj
|�tj|�}t|�dkr�tjj||d�}tjj|�r�|}t
|�tj||�|S)Nz<%r already exists in %s; build directory %s will not be keptrr)r>r?rr�r4r@rr�r�r#r��listdirrr#�shutil�move)r�r�
dist_filename�
setup_base�dstr��contentsr;r;r<�
maybe_moves"

zeasy_install.maybe_movecCs0|jr
dSx tj�j|�D]}|j|�qWdS)N)r��ScriptWriter�best�get_args�write_script)r�r�r�r;r;r<r,sz$easy_install.install_wrapper_scriptscCsNt|j��}t||�}|r8|j|�t�}tj|�|}|j|t|�d�dS)z/Generate a legacy script wrapper and install itrnN)	r9rN�is_python_script�_load_templater�rX�
get_headerr[rE)r�r�r-�script_text�dev_pathrZ	is_scriptZbodyr;r;r<r+"s
zeasy_install.install_scriptcCs(d}|r|jdd�}td|�}|jd�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�zutf-8)rNr"�decode)r`r�Z	raw_bytesr;r;r<r],s

zeasy_install._load_template�tcs��j�fdd�|D��tjd|�j�tjj�j|�}�j|��jrLdSt	�}t
|�tjj|�rptj|�t
|d|��}|j|�WdQRXt|d|�dS)z1Write an executable file to the scripts directorycsg|]}tjj�j|��qSr;)r>r?rr�)r�rb)r�r;r<r�>sz-easy_install.write_script.<locals>.<listcomp>zInstalling %s script to %sNri�)r�rr�r�r>r?rr2r��
current_umaskr#r@r�rr%�chmod)r�r-rV�moder��target�maskrkr;)r�r<r[;s

zeasy_install.write_scriptcCs`|j�jd�r|j||�gS|j�jd�r8|j||�gS|j�jd�rT|j||�gS|}tjj|�r�|jd�r�t|||j	�ntjj
|�r�tjj|�}|j|�r�|j
r�|dk	r�|j|||�}tjj|d�}tjj|��s2ttjj|dd��}|�stdtjj|���t|�dk�r*td	tjj|���|d
}|j�rPtj|j||��gS|j||�SdS)Nz.eggz.exez.whlz.pyzsetup.pyr�z"Couldn't find a setup script in %srzMultiple setup scripts in %sr)r'rD�install_egg�install_exe�
install_wheelr>r?�isfiler�unpack_progressr��abspath�
startswithr�rWrr@rrrr{rr��report_editable�build_and_install)r�rrSr:rT�setup_scriptZsetupsr;r;r<rFOs<
zeasy_install.install_eggscCs>tjj|�r"t|tjj|d��}nttj|��}tj	||d�S)NzEGG-INFO)�metadata)
r>r?r�r)rr*�	zipimport�zipimporterr(Z
from_filename)r��egg_pathrrr;r;r<rG{s

zeasy_install.egg_distributionc
Cs�tjj|jtjj|��}tjj|�}|js2t|�|j|�}t	||��s|tjj
|�rttjj|�rttj
||jd�n"tjj|�r�|jtj|fd|�y�d}tjj
|�r�|j|�r�tjd}}ntjd}}nL|j|�r�|j|�|jd}}n*d}|j|��rtjd}}ntjd}}|j|||f|dtjj|�tjj|�f�t||d	�Wn$tk
�rzt|dd	��YnX|j|�|j|�S)
N)r�z	Removing FZMovingZCopyingZ
ExtractingTz	 %s to %s)�fix_zipimporter_caches)r>r?rr�r)rmr�r#rGr1r�r�r
�remove_treer@rr�rnrQrRZcopytreerOZmkpath�unpack_and_compileZcopy2r#�update_dist_cachesr	r2)r�rur:�destinationr�Znew_dist_is_zippedrkrWr;r;r<rh�sT






zeasy_install.install_eggcsTt|�}|dkrtd|��td|jdd�|jdd�t�d�}tjj||j�d�}||_	|d}tjj|d�}tjj|d	�}t
|�t||�|_|j
||�tjj|��st|d
�}	|	jd�x<|jd�D].\}
}|
dkr�|	jd
|
jdd�j�|f�q�W|	j�tjj|d��|j�fdd�tj|�D��tj|||j|jd�|j||�S)Nz(%s is not a valid distutils Windows .exerrr�r�)rEr��platformz.eggz.tmpzEGG-INFOzPKG-INFOrzMetadata-Version: 1.0
�target_versionz%s: %s
�_�-r*csg|]}tjj�|d��qS)r)r>r?r)r�r�)r�r;r<r��sz,easy_install.install_exe.<locals>.<listcomp>)r�r�)r4rr(�getrr>r?r�egg_namerAr#r)Z	_provider�
exe_to_eggr@rr%�itemsrN�titlerr�rXrZrZmake_zipfiler�r�rh)r�rSr:�cfgr�ru�egg_tmpZ	_egg_infoZpkg_infrk�k�vr;)r�r<ri�s<



"
zeasy_install.install_execs>t|��g�g�i������fdd�}t|�|�g}xt�D]l}|j�jd�r>|jd�}|d}tj|d�d|d<tjj	�f|��}�j
|�|j
|�tj||�q>W|j��tj
tjj	�d�tj�|��xbdD]Z}	t�|	r�tjj	�d|	d
�}
tjj|
�s�t|
d�}|jdj	t�|	�d�|j�q�Wd
S)z;Extract a bdist_wininst to the directories an egg would usecs�|j�}xԈD]�\}}|j|�r||t|�d�}|jd�}tjj�f|��}|j�}|jd�sl|jd�r�tj	|d
�|d<d�tjj
|d�d<�j|�n4|jd�r�|dkr�d�tjj
|d�d<�j|�|SqW|jd�s�tj
d	|�dS)N�/z.pydz.dllrrz.pyzSCRIPTS/z.pthzWARNING: can't process %s���r�)r'rnrr�r>r?rrDr�strip_module�splitextr�rr�)�srcrUrD�old�new�partsrC)r��native_libs�prefixes�
to_compile�	top_levelr;r<�process�s$



z(easy_install.exe_to_egg.<locals>.processz.pydr�rz.pyzEGG-INFOr�r�z.txtrrJNr�r�r�)r�r�)r6rr'rDr�rr�r>r?rr�Z
write_stub�byte_compileZwrite_safety_flagZanalyze_eggr�r@rr%r)r�rSr�r�Zstubs�resr�ZresourceZpyfiler�Ztxtrkr;)r�r�r�r�r�r<r��s6







zeasy_install.exe_to_eggc
Cs�t|�}|j�st�tjj|j|j��}tjj|�}|j	sBt
|�tjj|�rntjj|�rnt
j||j	d�n"tjj|�r�|jtj|fd|�z.|j|j|fdtjj|�tjj|�f�Wdt|dd�X|j|�|j|�S)N)r�z	Removing zInstalling %s to %sF)rv)rZ
is_compatible�AssertionErrorr>r?rr�r�rmr�r#r�r�r
rwr@rr�Zinstall_as_eggr)r#ryr2rG)r�Z
wheel_pathr:Zwheelrzr;r;r<rjs.


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@|jr@|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)srJr�)
r�r��_easy_install__mv_warningr�rr!r�r?�_easy_install__id_warningrArEr�r�)	r�Zreqr�Zwhatr�Zegglocr�r�Zextrasr;r;r<rLIsz 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"tjj|�}tj}d|jt�S)NrJ)r>r?r#r�r&�_easy_install__editable_msgr�)r�rrqr#�pythonr;r;r<robszeasy_install.report_editablecCs�tjjdt�tjjdt�t|�}|jdkrNd|jd}|jdd|�n|jdkrd|jdd�|jrv|jdd	�t	j
d
|t|�dd�dj|��yt
||�Wn6tk
r�}ztd|jdf��WYdd}~XnXdS)
Nzdistutils.command.bdist_eggzdistutils.command.egg_infor�r�rrr~z-qz-nz
Running %s %s� zSetup script exited with %s)r��modules�
setdefaultrrr�r�r�r�rr�rrrr�rr�)r�rqrTr�r�r;r;r<rgs 

 zeasy_install.run_setupc	Cs�ddg}tjdtjj|�d�}z�|jtjj|��|j|�|j|||�t|g�}g}x2|D]*}x$||D]}|j|j	|j
|��qlWq^W|r�|jr�tj
d|�|St|�tj|j�XdS)Nrz
--dist-dirz
egg-dist-tmp-)r��dirz+No eggs found in %s (setup script problem?))r6r7r>r?r#�_set_fetcher_optionsr�rr&rhrAr�rr�r�rr�)	r�rqrTr�Zdist_dirZall_eggsZeggsr4r�r;r;r<rp{s$


zeasy_install.build_and_installc	Cst|jjd�j�}d
}i}x2|j�D]&\}}||kr4q"|d||jdd	�<q"Wt|d
�}tjj|d�}t	j
||�dS)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.
        r2r�r�r�r�r�rr}r~)r2z	setup.cfgN)r�r�r�r�r�r�)r�r��copyr�rN�dictr>r?rrZedit_config)	r�r0Zei_optsZfetch_directivesZ
fetch_optionsr4r�ZsettingsZcfg_filenamer;r;r<r��s	
z!easy_install._set_fetcher_optionscCs0|jdkrdSxX|j|jD]H}|js2|j|jkrtjd|�|jj|�|j|jkr|jj|j�qW|js�|j|jjkr�tjd|�n2tjd|�|jj	|�|j|jkr�|jj
|j�|j�s,|jj�|jdk�r,t
jj|jd�}t
jj|��rt
j|�t|d�}|j|jj|j�d�|j�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�zsetuptools.pth�wtrJ)r�r4r�rArr�rKr��pathsrJr�r��saver>r?rr�r�r�rr%�
make_relativer)r�r�r]r�rkr;r;r<rI�s4



zeasy_install.update_pthcCstjd||�|S)NzUnpacking %s to %s)r�debug)r�r�rUr;r;r<rl�szeasy_install.unpack_progresscshg�g����fdd�}t|||��j���jsdx.�D]&}tj|�tjdBd@}t||�q:WdS)Ncs\|jd�r"|jd�r"�j|�n|jd�s6|jd�r@�j|��j||��jrX|pZdS)Nz.pyz	EGG-INFO/z.dllz.so)rDrnr�rlr�)r�rU)r��to_chmodr�r;r<�pf�s
z+easy_install.unpack_and_compile.<locals>.pfimi�)rr�r�r>�stat�ST_MODErd)r�rurzr�rkrer;)r�r�r�r<rx�s

zeasy_install.unpack_and_compilecCsjtjr
dSddlm}z@tj|jd�||dd|jd�|jrT|||jd|jd�Wdtj|j�XdS)Nr)r�r)r��forcer�)	r��dont_write_bytecode�distutils.utilr�rrr�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}||jtjjdd�fS)N�
PYTHONPATHr�)�_easy_install__no_default_msgr�r>�environr)r��templater;r;r<rsz#easy_install.no_default_version_msgcCs�|jr
dStjj|jd�}tdd�}|jd�}d}tjj|�r�tj	d|j�t
j|��}|j�}WdQRX|j
d�s�td	|��||kr�tjd
|�|js�t|�t
j|ddd��}|j|�WdQRX|j|g�d
|_dS)z8Make sure there's a site.py in the target dir, if neededNzsite.pyr�z
site-patch.pyzutf-8r�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r�r"rar@rr��ior�readrnrr�r�r#r%r�)r�Zsitepy�sourceZcurrentZstrmr;r;r<r=s,


zeasy_install.install_site_pycCsj|js
dSttjjd��}xJtj|j�D]:\}}|j|�r(tjj	|�r(|j
d|�tj|d�q(WdS)zCreate directories under ~.N�~zos.makedirs('%s', 0o700)i�)r�rr>r?r�rZ	iteritemsr�rnr�Zdebug_printr)r��homer�r?r;r;r<r�>szeasy_install.create_home_pathz/$base/lib/python$py_version_short/site-packagesz	$base/bin)r�r�)r�z$base/Lib/site-packagesz
$base/ScriptscGs�|jd�j}|jrh|j�}|j|d<|jjtj|j�}x0|j	�D]$\}}t
||d�dkr@t|||�q@Wddlm
}xJ|D]B}t
||�}|dk	rz|||�}tjdkr�tjj|�}t|||�qzWdS)Nr�r0r)rr�)Zget_finalized_commandr�r�r�r
rr>r��DEFAULT_SCHEMEr�r�r�r�rr?r�)r�r�r�rHr�r�rr;r;r<r�Ts 




zeasy_install._expand)rQNrR)rSrTrU)rVrWrX)rYrZr[)r\r]r^)r_rDr`)rarbrc)rdrerf)rgrhri)rjrkrl)rmrnro)rprqrr)rsNrt)rurvrw)rxryrz)r{r|r})r~rr�)r�r�r�)r�r�r�)r�Nr�)r�Nr�)F)F)T)N)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�rrrr�rKrL�lstriprrrrrr.r2r3r5�
contextlib�contextmanagerr;r2r?r�r@rOrWr,r+r]r[rFrGrhrir�rjr�r�rLr�rorrpr�rIrlrxr�r�rr=r�r�r
r�r�r;r;r;r<r2xs�



0	z	0


	;
	
$
$	
'	

,6-5	

	
%
 
cCs tjjdd�jtj�}td|�S)Nr�r�)r>r�rr��pathsep�filter)r�r;r;r<rksrcCs�g}|jt��tjg}tjtjkr0|jtj�x�|D]�}|r6tjdkr`|jtjj	|dd��n\tj
dkr�|jtjj	|ddtjdd	�d�tjj	|dd
�g�n|j|tjj	|dd�g�tjdkr6d|kr6tjj
d
�}|r6tjj	|ddtjdd	�d�}|j|�q6Wtd�td�f}x"|D]}||k�r |j|��q Wtj�rR|jtj�y|jtj��Wntk
�rzYnXttt|��}|S)z&
    Return a list of 'site' dirs
    �os2emx�riscosZLibz
site-packagesr��libr�Nr�zsite-python�darwinzPython.framework�HOME�Library�Python�purelib�platlib)r�r�)�extendrr�r�r�r�r{r>r?r�sepr�r�rrr�r�r��getsitepackages�AttributeErrorr�rr!)�sitedirsr�r�r�Zhome_spZ	lib_pathsZsite_libr;r;r<r�psV





r�ccs�i}x�|D]�}t|�}||kr q
d||<tjj|�s6q
tj|�}||fVx�|D]�}|jd�s`qP|dkrjqPttjj||��}tt	|��}|j
�xP|D]H}|jd�s�t|j��}||kr�d||<tjj|�s�q�|tj|�fVq�WqPWq
WdS)zBYield sys.path directories that might contain "old-style" packagesrz.pth�easy-install.pth�setuptools.pth�importN)r�r�)
r!r>r?r�rPrDrrr�r rrn�rstrip)Zinputs�seenr#r1r�rk�lines�liner;r;r<�expand_paths�s4






r�cCs&t|d�}�z
tj|�}|dkr$dS|d|d|d}|dkrHdS|j|d�tjd|jd��\}}}|dkrzdS|j|d|�d
d
d�}tj|�}y<|j|�}	|	j	dd
�d}
|
j
tj��}
|j
tj|
��Wntjk
r�dSX|jd��s|jd��rdS|S|j�XdS)znExtract configuration data from a bdist_wininst .exe

    Returns a configparser.RawConfigParser, or None
    �rbN�	���z<iii�zV4�{V4r�)r�r|�rrrrZSetup)r�r�)r�zipfileZ_EndRecData�seekr9�unpackr�rZRawConfigParserr�rar��getfilesystemencodingZreadfpr�StringIO�ErrorZhas_sectionr)rSrkZendrecZ	prepended�tagZcfglenZbmlenZinitr��part�configr;r;r<r4�s4




c
CsJdddddg}tj|�}�z�x�|j�D]�}|j}|jd�}t|�d	kr�|d
dkr�|djd
�r�|jddj|dd
��df�Pt|�d
ks(|jd�r�q(|jd�r�q(|dj	�dkr(|j
|�}tjr�|j
�}xDt|�D]8}|j�jdd�}|jd�s�|jd|d|fdf�q�Wq(WWd|j�Xdd�|D�}|j�|j�|S) z4Get exe->egg path translations for a given .exe file�PURELIB/r��PLATLIB/pywin32_system32�PLATLIB/�SCRIPTS/�EGG-INFO/scripts/�DATA/lib/site-packagesr�r�r�zPKG-INFOrz	.egg-inforNz	EGG-INFO/z.pthz
-nspkg.pth�PURELIB�PLATLIB�\r�z%s/%s/cSsg|]\}}|j�|f�qSr;)r')r�rb�yr;r;r<r�$sz$get_exe_prefixes.<locals>.<listcomp>)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�ZZipFileZinfolistr�r�rrDr�r�upperr�rZPY3rar rMrNrnr�r�sort�reverse)Zexe_filenamer�rTr�r�r�rVZpthr;r;r<r6s>




&
c@sTeZdZdZdZffdd�Zdd�Zdd�Zed	d
��Z	dd�Z
d
d�Zdd�ZdS)r3z)A .pth file with Distribution paths in itFcCsp||_ttt|��|_ttjj|j��|_|j	�t
j|gdd�x(t|j
�D]}tt|jt|d���qNWdS)NT)r�r�rr!r�r>r?r#�basedir�_loadr&�__init__r r�rJr%)r�r�r�r?r;r;r<r�/szPthDistributions.__init__cCsg|_d}tj|j�}tjj|j�r�t|jd�}x�|D]�}|j	d�rJd}q6|j
�}|jj|�|j�s6|j�j	d�rxq6t
tjj|j|��}|jd<tjj|�s�||kr�|jj�d|_q6d||<q6W|j�|jr�|r�d|_x&|jo�|jdj��r
|jj�q�WdS)	NFZrtr�T�#rr�r�)r�r��fromkeysr�r>r?rkr�rrnr�r�rMr!rr�r@�pop�dirtyr)r�Z
saw_importr�rkr�r?r;r;r<r�8s2


zPthDistributions._loadc	Cs�|js
dStt|j|j��}|r�tjd|j�|j|�}dj	|�d}t
jj|j�r`t
j
|j�t|jd��}|j|�WdQRXn(t
jj|j�r�tjd|j�t
j
|j�d|_dS)z$Write changed .pth file back to diskNz	Saving %srJr�zDeleting empty %sF)rr�rr�r�rr�r��_wrap_linesrr>r?r�r�rr%r@)r�Z	rel_pathsr��datarkr;r;r<r�Ws
zPthDistributions.savecCs|S)Nr;)r�r;r;r<rmszPthDistributions._wrap_linescCsN|j|jko$|j|jkp$|jtj�k}|r>|jj|j�d|_tj||�dS)z"Add `dist` to the distribution mapTN)	rAr�r�r>�getcwdr�rr&rJ)r�r��new_pathr;r;r<rJqszPthDistributions.addcCs6x$|j|jkr$|jj|j�d|_qWtj||�dS)z'Remove `dist` from the distribution mapTN)rAr�rKrr&)r�r�r;r;r<rKs
zPthDistributions.removecCs�tjjt|��\}}t|j�}|g}tjdkr2dp6tj}xVt|�|kr�||jkrn|jtj	�|j
�|j|�Stjj|�\}}|j|�q:W|SdS)Nr�)r>r?r�r!rr��altsepr�r��curdirr�r)r�r?ZnpathZlastZbaselenr�r�r;r;r<r��s


zPthDistributions.make_relativeN)
r�r�r�r�rr�r�r�r�rrJrKr�r;r;r;r<r3*s	c@s(eZdZedd��Zed�Zed�ZdS)�RewritePthDistributionsccs(|jVx|D]
}|VqW|jVdS)N)�prelude�postlude)�clsr�r�r;r;r<r�s

z#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��classmethodrr"rr	r;r;r;r<r�s
rZSETUPTOOLS_SYS_PATH_TECHNIQUE�rawZrewritecCs ttjt�rtStjtjj��S)z_
    Return a regular expression based on first_line_re suitable for matching
    strings.
    )r�r�patternr9�re�compilerar;r;r;r<�_first_line_re�srcCsd|tjtjgkr.tjdkr.t|tj�||�Stj�\}}}t	j
||d|dd||ff�dS)Nr�rrz %s %s)r>r�rKr�rdr��S_IWRITEr�rrZreraise)�func�arg�excZetZevr}r;r;r<�
auto_chmod�s
rcCs.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_pathrv�normalized_pathr;r;r<ry�s
<
rycCsTg}t|�}xB|D]:}t|�}|j|�r|||d�tjdfkr|j|�qW|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�)rr!rnr>r�r�)r�cache�resultZ
prefix_len�pZnpr;r;r<�"_collect_zipimporter_cache_entriess


rcCsDx>t||�D]0}||}||=|o*|||�}|dk	r|||<qWdS)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
r!cCst||�dS)N)r!)rrr;r;r<rJsrcCsdd�}t|tj|d�dS)NcSs|j�dS)N)�clear)r?r r;r;r<�2clear_and_remove_cached_zip_archive_directory_dataOszf_remove_and_clear_zip_directory_cache_data.<locals>.clear_and_remove_cached_zip_archive_directory_data)r)r!rs�_zip_directory_cache)rr#r;r;r<rNsrZ__pypy__cCsdd�}t|tj|d�dS)NcSs&|j�tj|�|jtj|�|S)N)r"rsrt�updater$)r?r r;r;r<�)replace_cached_zip_archive_directory_dataes
zT_replace_zip_directory_cache_data.<locals>.replace_cached_zip_archive_directory_data)r)r!rsr$)rr&r;r;r<rds
r�<string>cCs2yt||d�Wnttfk
r(dSXdSdS)z%Is this string a valid Python script?�execFTN)r�SyntaxError�	TypeError)rOr�r;r;r<�	is_pythonws
r+cCsJy(tj|dd��}|jd�}WdQRXWnttfk
r@|SX|dkS)zCDetermine if the specified executable is a .sh (contains a #! line)zlatin-1)r�r�Nz#!)r�rr�rr)r&�fp�magicr;r;r<�is_sh�sr.cCstj|g�S)z@Quote a command line argument according to Windows parsing rules)�
subprocess�list2cmdline)rr;r;r<�nt_quote_arg�sr1cCsH|jd�s|jd�rdSt||�r&dS|jd�rDd|j�dj�kSdS)zMIs this text, as a whole, a Python script? (as opposed to shell/bat/etc.
    z.pyz.pywTz#!r�rF)rDr+rn�
splitlinesr')r_r�r;r;r<r\�s

r\)rdcGsdS)Nr;)r�r;r;r<�_chmod�sr3cCsRtjd||�yt||�Wn0tjk
rL}ztjd|�WYdd}~XnXdS)Nzchanging mode of %s to %ozchmod failed: %s)rr�r3r>�error)r?rer|r;r;r<rd�s
rdc@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<rY�szCommandSpec.bestcCstjjtj�}tjjd|�S)N�__PYVENV_LAUNCHER__)r>r?rBr�r&r�r)r
Z_defaultr;r;r<�_sys_executable�szCommandSpec._sys_executablecCs:t||�r|St|t�r ||�S|dkr0|j�S|j|�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||j�g�S)N)r7)r
r;r;r<r8�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<r9�szCommandSpec.from_stringcCs8tj|j|��|_tj|�}t|�s4dg|jdd�<dS)Nz-xr)r;r��_extract_options�optionsr/r0rH)r�r_�cmdliner;r;r<�install_options�s
zCommandSpec.install_optionscCs:|dj�d}t�j|�}|r.|jd�p0dnd}|j�S)zH
        Extract any options from the first line of the script.
        rJrrr�)r2r�match�grouprM)Zorig_script�firstrBr?r;r;r<r>�szCommandSpec._extract_optionscCs|j|t|j��S)N)�_renderr�r?)r�r;r;r<�	as_header�szCommandSpec.as_headercCs6d}x,|D]$}|j|�r
|j|�r
|dd�Sq
W|S)Nz"'rr�)rnrD)�itemZ_QUOTES�qr;r;r<�
_strip_quotes�s

zCommandSpec._strip_quotescCs tjdd�|D��}d|dS)Ncss|]}tj|j��VqdS)N)r5rIrM)r�rGr;r;r<r��sz&CommandSpec._render.<locals>.<genexpr>z#!rJ)r/r0)r�r@r;r;r<rE�szCommandSpec._renderN)r�r�r�r�r?r�r<rrYr7r:r8r9rAr�r>rFrIrEr;r;r;r<r5�s	
r5c@seZdZedd�ZdS)�WindowsCommandSpecF)r�N)r�r�r�r�r<r;r;r;r<rJsrJc@s�eZdZdZejd�j�ZeZ	e
ddd��Ze
ddd��Ze
dd	d
��Z
edd��Ze
d
d��Ze
dd��Ze
dd��Ze
ddd��ZdS)rXz`
    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)()
            )
    NFcCs6tjdt�|rtntj�}|jd||�}|j||�S)NzUse get_argsr�)�warningsr��DeprecationWarning�WindowsScriptWriterrXrY�get_script_headerrZ)r
r�r&�wininst�writer�headerr;r;r<�get_script_argsszScriptWriter.get_script_argscCs6tjdt�|rd}|jj�j|�}|j|�|j�S)NzUse get_headerz
python.exe)rKr�rL�command_spec_classrYr:rArF)r
r_r&rO�cmdr;r;r<rN's
zScriptWriter.get_script_headerccs�|dkr|j�}t|j��}xjdD]b}|d}xT|j|�j�D]B\}}|j|�|jt�}|j||||�}	x|	D]
}
|
VqrWq>Wq"WdS)z�
        Yield write_script() argument tuples for a distribution's
        console_scripts and gui_scripts entry points.
        N�console�guiZ_scripts)rUrV)	r^r9rNZ
get_entry_mapr��_ensure_safe_namer�r��_get_script_args)r
r�rQr�type_rCr�Zepr_r�r�r;r;r<rZ1s


zScriptWriter.get_argscCstjd|�}|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<rWCszScriptWriter._ensure_safe_namecCs tjdt�|rtj�S|j�S)NzUse best)rKr�rLrMrY)r
Z
force_windowsr;r;r<�
get_writerLszScriptWriter.get_writercCs.tjdkstjdkr&tjdkr&tj�S|SdS)zD
        Select the best ScriptWriter for this environment.
        �win32�javar�N)r�r{r>r��_namerMrY)r
r;r;r<rYRszScriptWriter.bestccs|||fVdS)Nr;)r
rYr�rQr_r;r;r<rX\szScriptWriter._get_script_argsr�cCs"|jj�j|�}|j|�|j�S)z;Create a #! line, getting options (if any) from script_text)rSrYr:rArF)r
r_r&rTr;r;r<r^as
zScriptWriter.get_header)NF)NF)N)r�N)r�r�r�r�rKrLr�r�r5rSrrRrNrZr�rWr[rYrXr^r;r;r;r<rX	s 
		
rXc@sLeZdZeZedd��Zedd��Zedd��Zedd��Z	e
d	d
��ZdS)rMcCstjdt�|j�S)NzUse best)rKr�rLrY)r
r;r;r<r[lszWindowsScriptWriter.get_writercCs"tt|d�}tjjdd�}||S)zC
        Select the best ScriptWriter suitable for Windows
        )r&ZnaturalZSETUPTOOLS_LAUNCHERr&)r��WindowsExecutableLauncherWriterr>r�r)r
Z
writer_lookupZlauncherr;r;r<rYrs
zWindowsScriptWriter.bestc	#s�tddd�|}|tjdj�jd�krBdjft��}tj|t	�dddd	d
ddg}|j
|�|j||�}�fdd
�|D�}�|||d|fVdS)z For Windows, add a .py extensionz.pyaz.pyw)rUrVZPATHEXT�;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.z.pyz
-script.pyz.pycz.pyoz.execsg|]}�|�qSr;r;)r�rb)r�r;r<r��sz8WindowsScriptWriter._get_script_args.<locals>.<listcomp>rbN)r�r>r�r'r�r�r�rKr��UserWarningrK�_adjust_header)	r
rYr�rQr_�extr�r�r�r;)r�r<rXs
z$WindowsScriptWriter._get_script_argscCsNd}d}|dkr||}}tjtj|�tj�}|j||d�}|j|�rJ|S|S)z�
        Make sure 'pythonw' is used for gui and and 'python' is used for
        console (regardless of what sys.executable is).
        zpythonw.exez
python.exerV)r=�repl)rr�escape�
IGNORECASE�sub�_use_header)r
rYZorig_headerr
rdZ
pattern_ob�
new_headerr;r;r<rb�s
z"WindowsScriptWriter._adjust_headercCs$|dd�jd�}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�"r\r�)rMr�r{r)riZclean_headerr;r;r<rh�s	zWindowsScriptWriter._use_headerN)r�r�r�rJrSrr[rYrXrbr�rhr;r;r;r<rMis
rMc@seZdZedd��ZdS)r_c#s�|dkrd}d}dg}nd}d}dddg}|j||�}�fd	d
�|D�}	�|||d|	fV�dt|�d
fVt�s��d}
|
t��dfVdS)zG
        For Windows, add a .py extension and an .exe launcher
        rVz-script.pywz.pywZcliz
-script.pyz.pyz.pycz.pyocsg|]}�|�qSr;r;)r�rb)r�r;r<r��szDWindowsExecutableLauncherWriter._get_script_args.<locals>.<listcomp>rbz.exernz
.exe.manifestN)rb�get_win_launcherr=�load_launcher_manifest)r
rYr�rQr_Z
launcher_typercr�Zhdrr�Zm_namer;)r�r<rX�s
z0WindowsExecutableLauncherWriter._get_script_argsN)r�r�r�rrXr;r;r;r<r_�sr_cCs2d|}t�r|jdd�}n|jdd�}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=rNr")�typeZlauncher_fnr;r;r<rk�s
rkcCs0tjtd�}tjr|t�S|jd�t�SdS)Nzlauncher manifest.xmlzutf-8)r$r"r�r�PY2�varsra)r�Zmanifestr;r;r<rl�s
rlFcCstj|||�S)N)rQr�)r?�
ignore_errors�onerrorr;r;r<r��sr�cCstjd�}tj|�|S)N�)r>�umask)Ztmpr;r;r<rc�s

rccCs:ddl}tjj|jd�}|tjd<tjj|�t�dS)Nr)	r�r>r?r#�__path__r��argvr�r5)r�Zargv0r;r;r<�	bootstrap�s

rwc
s�ddlm}ddlm�G�fdd�d��}|dkrBtjdd�}t��0|fddd	g|tjdpfd|d
�|��WdQRXdS)Nr)�setup)r(cseZdZdZ�fdd�ZdS)z-main.<locals>.DistributionWithoutHelpCommandsr�c
s(t���j|f|�|�WdQRXdS)N)�_patch_usage�
_show_help)r�r��kw)r(r;r<rz	sz8main.<locals>.DistributionWithoutHelpCommands._show_helpN)r�r�r�Zcommon_usagerzr;)r(r;r<�DistributionWithoutHelpCommands�sr|rz-qr2z-v)Zscript_argsr-Z	distclass)r�rxZsetuptools.distr(r�rvry)rvr{rxr|r;)r(r<r5�sc#sLddl}tjd�j���fdd�}|jj}||j_z
dVWd||j_XdS)Nrze
        usage: %(script)s [options] requirement_or_url ...
           or: %(script)s --help
        cs�ttjj|�d�S)N)Zscript)r�r>r?r))r-)�USAGEr;r<�	gen_usage	sz_patch_usage.<locals>.gen_usage)Zdistutils.corerKrLr�Zcorer~)rr~Zsavedr;)r}r<ry	s

ry)N)r')N)�r�rr�rrrZdistutils.errorsrrrr	Zdistutils.command.installr
rrrr
Zdistutils.command.build_scriptsrr(rr�r>rsrQr6r�rr�r
rKrKr�r9r�r/r;r�Zsetuptools.externrZsetuptools.extern.six.movesrrr�rZsetuptools.sandboxrZsetuptools.py31compatrrZsetuptools.py27compatrZsetuptools.commandrZsetuptools.archive_utilrZsetuptools.package_indexrrrrrZsetuptools.wheelrr$r r!r"r#r$r%r&r'r(r)r*r+r,r-r.Zpkg_resources.py31compat�filterwarningsZ
PEP440Warning�__all__r=r1rorErHr"r2rr�r�r4r6r3rr�rrrryrr!rr�builtin_module_namesrr+r.r1r\rdr3�ImportErrorr�r5r7Zsys_executablerJ�objectrXrMr_rRrNrkrlr�rcrwr5r�ryr;r;r;r<�<module>s�D
|A))'lR
 


T`A 



?>