YO @sdZddlmZddlmZddlmZmZddlmZmZm Z m Z ddl m 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%dd l&Z&dd l'm(Z(m)Z)dd l*m+Z+dd l,m-Z-ddl.m/Z/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9m:Z:ddl3m;Z;m<Z<ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLdd l=Z=ejMdde=jNddddddgZOddZPddZQe&jRr d d!ZSd"d#ZTnd$d!ZSd%d#ZTd&d'ZUGd(dde+ZVd)d*ZWd+d,ZXd-d.ZYd/dZZd0dZ[Gd1ddeDZ\Gd2d3d3e\Z]ej^j_d4d5d6kre]Z\d7d8Z`d9d:Zad;d<Zbd=d>Zcd d?d@ZddAdBZedCdDZfdEejgkr<efZhn dFdGZhdHdIdJZidKdLZjdMdNZkdOdPZlyddQlmmZnWneok rdRdSZnYnXdTdUZmGdVdWdWepZqeqjrZsGdXdYdYeqZtGdZd[d[euZvGd\d]d]evZwGd^d_d_ewZxevjyZyevjzZzd`daZ{dbdcZ|ddeadedfZ}dgdhZ~didjZd dkdZe"jdldmZd S)na% 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)DistutilsArgErrorDistutilsOptionErrorDistutilsErrorDistutilsPlatformError)INSTALL_SCHEMES SCHEME_KEYS)logdir_util) first_line_re)find_executableN) configparsermap)Command) run_setup)get_pathget_config_vars) rmtree_safe)setopt)unpack_archive) PackageIndexparse_requirement_arg URL_SCHEME) bdist_eggegg_info) yield_linesnormalize_pathresource_stringensure_directoryget_distributionfind_distributions Environment Requirement Distribution PathMetadata EggMetadata WorkingSetDistributionNotFoundVersionConflict DEVELOP_DISTdefaultcategorysamefile easy_installPthDistributionsextract_wininst_cfgmainget_exe_prefixescCstjddkS)NP)structcalcsizer9r9E/tmp/pip-build-3puug3g5/setuptools/setuptools/command/easy_install.pyis_64bitIsr;cCstjj|o!tjj|}ttjdo9|}|rUtjj||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. r/)ospathexistshasattrr/normpathnormcase)p1p2Z both_existZ use_samefileZnorm_p1Znorm_p2r9r9r:r/Ms$cCs|S)Nr9)sr9r9r: _to_ascii_srEc Cs5ytj|ddSWntk r0dSYnXdS)NasciiTF)six text_type UnicodeError)rDr9r9r:isasciibs  rJcCs |jdS)NrF)encode)rDr9r9r:rEjsc Cs2y|jddSWntk r-dSYnXdS)NrFTF)rKrI)rDr9r9r:rJms   cCstj|jjddS)N z; )textwrapdedentstripreplace)textr9r9r:usrRc@seZdZdZdZdZdddddddddddddddddddddgZdd dd dd0d3d9d<g Zej rd@ej Z ej dAde fej dAd*diZ eZdBdCZdDdEZdFdGZedHdIZdJdKZdLdMZdNdOZdPdQZdRdSZdTdUZdVdWZdXdYZdZd[Zejd\j Z!ejd]j Z"ejd^j Z#d_d`Z$dadbZ%dcddZ&dedfZ'dgdhZ(didjZ)e*j+dkdlZ,dmdndoZ-dmdpdqZ.drdsZ/ddtduZ0dvdwZ1dxdyZ2dzd{Z3dd|d}Z4ed~dZ5dfddZ6ddZ7ddZ8ddZ9ddZ:ddZ;ejdj Z<ejdZ=dddZ>ejdj Z?ddZ@ddZAddZBddZCddZDddZEddZFddZGejdj ZHddZIddZJddZKeLdeLddddZMeLddddZNddZOdS)r0z'Manage a download/build/install processz Find/get/install Python packagesTprefix=Ninstallation prefixzip-okzinstall package as a zipfile multi-versionm%make apps have to require() a versionupgradeU1force upgrade (searches PyPI for latest versions) install-dir=dinstall package to DIR script-dir=rDinstall scripts to DIRexclude-scriptsxDon't install scripts always-copya'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 packagesbuild-directory=b/download/extract/build in DIR; keep the results optimize=Olalso 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-unzipZ*don't install as a zipfile, no matter what site-dirs=S)list of directories where .pth files workeditablee+Install specified packages in editable formno-depsNdon't install dependencies allow-hosts=H$pattern(s) that hostnames must matchlocal-snapshots-okl(allow building eggs from local checkoutsversion"print version information and exit no-find-links9Don't load find-links defined in packages being installedz!install in user site-package '%s'usercCsd|_d|_|_d|_|_|_d|_d|_d|_d|_ d|_ |_ d|_ |_ |_d|_|_|_d|_|_|_d|_d|_d|_d|_d|_d|_d|_d|_d|_tjrtj |_!tj"|_#nd|_!d|_#d|_$d|_%d|_&|_'d|_(i|_)d|_*d|_+|j,j-|_-|j,j.||j,j/ddS)NrFr0)0rzip_oklocal_snapshots_ok install_dir script_direxclude_scripts index_url find_linksbuild_directoryargsoptimizerecordr[ always_copy multi_versionr}no_deps allow_hostsrootprefix no_reportrinstall_purelibinstall_platlibinstall_headers install_libinstall_scripts install_data install_baseinstall_platbasesiteENABLE_USER_SITE USER_BASEinstall_userbase USER_SITEinstall_usersite no_find_links package_indexpth_filealways_copy_from site_dirsinstalled_projectssitepy_installed_dry_run distributionverbose_set_command_optionsget_option_dict)selfr9r9r:initialize_optionssF                         zeasy_install.initialize_optionscCs-dd|D}tt|j|dS)Ncss9|]/}tjj|s-tjj|r|VqdS)N)r<r=r>islink).0filenamer9r9r: sz/easy_install.delete_blockers..)listr _delete_path)rblockersZextant_blockersr9r9r:delete_blockersszeasy_install.delete_blockerscCsetjd||jrdStjj|o?tjj| }|rNtntj}||dS)Nz Deleting %s) r infodry_runr<r=isdirrrmtreeunlink)rr=Zis_treeZremoverr9r9r:rs  %zeasy_install._delete_pathcCsHtjdd}td}d}t|jttdS)zT Render the Setuptools version and installation details, then exit. N setuptoolsz=setuptools {dist.version} from {dist.location} (Python {ver}))sysrr"printformatlocals SystemExit)verdisttmplr9r9r:_render_versions  zeasy_install._render_versionc Cs|jo|jtjjd}tdd\}}d|jjd|jjd|jjd|d|dd d |d|d d |d|d |d|dt tddi |_ t j r|j |j d<|j|j d<|j|j|j|jdddd|jdkr;|j|_|jdkrSd|_|jdd)|jdd*|jr|jr|j|_|j|_|jdd+tttj}t|_|jdk rjdd|jjdD}xn|D]f}t jj!|s+t"j#d|qt||krPt$|dq|jj%t|qW|j&s}|j'|j(pd |_(|jdd|_)xB|jt|jfD](}||j)kr|j)j*d|qW|j+dk rd!d|j+jdD}n d"g}|j,dkrW|j-|j(d#|j)d$||_,t.|j)tj|_/|j0dk rt1|j0t2j3r|j0j|_0n g|_0|j4r|j,j5|j)tj|js|j,j6|j0|jdd,t1|j7t8soy;t8|j7|_7d|j7koBd knsMt9Wnt9k rnt$d&YnX|j&r|j: rt;d'|j<st;d(g|_=dS)-Nrr exec_prefix dist_name dist_version dist_fullname py_versionpy_version_shortrpy_version_nodot sys_prefixsys_exec_prefixabiflagsuserbaseusersiterrrrFrrinstallrcSs(g|]}tjj|jqSr9)r<r= expanduserrO)rrDr9r9r: 3s z1easy_install.finalize_options..,z"%s (in --site-dirs) does not existz$ (in --site-dirs) is not on sys.pathzhttps://pypi.python.org/simplecSsg|]}|jqSr9)rO)rrDr9r9r:rHs * search_pathhostsrz--optimize must be 0, 1, or 2z9Must specify a build directory (-b) when using --editablez:No urls, filenames, or requirements specified (see --help)) install_dirr)rz script_dir)recordr)optimizer)>rrrsplitrrget_name get_version get_fullnamegetattr config_varsrrrr_fix_install_dir_for_user_siteexpand_basedirs expand_dirs_expandrrrset_undefined_optionsrrrrrr= get_site_dirs all_site_dirsrr<rr warnrappendr}check_site_dirr shadow_pathinsertrr create_indexr$ local_indexr isinstancerG string_typesrZscan_egg_linksadd_find_linksrint ValueErrorrrroutputs) rrrrr@rr_ path_itemrr9r9r:finalize_optionss                "         zeasy_install.finalize_optionscCs|j stj rdS|j|jdkrCd}t||j|_|_tj j ddd}|j |dS)z; Fix the install_dir if "--user" was used. Nz$User base directory is not specifiedposixunix_user) rrrcreate_home_pathrr rrr<namerP select_scheme)rmsgZ scheme_namer9r9r:rms  z+easy_install._fix_install_dir_for_user_sitecCsx{|D]s}t||}|dk rtjdksFtjdkrXtjj|}t||j}t|||qWdS)Nrnt)rr<r r=rrrsetattr)rattrsattrvalr9r9r: _expand_attrs|s  zeasy_install._expand_attrscCs|jdddgdS)zNCalls `os.path.expanduser` on install_base, install_platbase and root.rrrN)r)rr9r9r:rszeasy_install.expand_basedirscCs)ddddddg}|j|dS)z+Calls `os.path.expanduser` on install dirs.rrrrrrN)r)rdirsr9r9r:rs zeasy_install.expand_dirsc Cs |j|jjkr%tj|jzx%|jD]}|j||j q2W|jr|j}|j rt |j }x2t t |D]}|||d||ropencloseOSErrorIOErrorcant_write_to_targetrno_default_version_msgrr1r _pythonpathr)rinstdirrZ is_site_dirZtestfileZ test_existsr9r9r:rs4     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. cCsj|jtjd|jf}tjj|jsI|d|j7}n|d|j7}t |dS)NrL) _easy_install__cant_write_msgrexc_inforr<r=r>_easy_install__not_exists_id_easy_install__access_msgr)rrr9r9r:r0 s  z!easy_install.cant_write_to_targetc Cs1|j}tjd||jd}|d}tjj|}tdd}yW|rktj|tjj |}tjj|stj |t |d}Wn"t t fk r|jYnDXz|j|jt|jd}tj}tjdkrrtjj|\}} tjj|d } | jd koctjj| } | rr| }d d lm} | |d ddgd tjj|rtjd|dSWd|r|jtjj|rtj|tjj|rtj|X|js-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() rLr*Nrz pythonw.exez python.exer)spawnz-Ez-cpassz-TEST PASSED: %s appears to support .pth filesTz+TEST FAILED: %s does NOT support .pth filesF)rr rr)r<r=r> _one_linerrdirnamemakedirsr,r.r/r0writerrr-r executabler rr'lowerdistutils.spawnr9rr) rr3rZok_fileZ ok_existsrr<rmr?basenameZaltZuse_altr9r9r9r:r+sX          z!easy_install.check_pth_processingcCsz|j ri|jdrixM|jdD]<}|jd|rEq)|j|||jd|q)W|j|dS)z=Write all the scripts for `dist`, unless scripts are excludedscriptszscripts/N)rmetadata_isdirmetadata_listdirinstall_script get_metadatainstall_wrapper_scripts)rr script_namer9r9r:install_egg_scriptsNsz easy_install.install_egg_scriptscCs|tjj|rhxctj|D]?\}}}x-|D]%}|jjtjj||q8Wq"Wn|jj|dS)N)r<r=rwalkrrr')rr=baserfilesrr9r9r: add_output\s  *zeasy_install.add_outputcCs |jrtd|fdS)NzjInvalid argument %r: you can't use filenames or URLs with --editable (except via the --find-links option).)r}r)rrr9r9r: not_editableds zeasy_install.not_editablecCsT|js dStjjtjj|j|jrPtd|j|jfdS)Nz2%r already exists in %s; can't do a checkout there)r}r<r=r>r'rkeyr)rrr9r9r:check_editablels  'zeasy_install.check_editablec csTtjdtjd}zt|VWdtjj|oNtt |XdS)Nrz easy_install-) tempfilemkdtemprGustrr<r=r>rr)rtmpdirr9r9r:_tmpdirvszeasy_install._tmpdirFcCs||js|j|jV}t|tst|rx|j||jj||}|j d|||dSt j j |r|j||j d|||dSt |}|j||jj|||j|j|j |j}|dkr/d|}|jr |d7}t|nB|jtkrX|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_pyrWrr%rrOrdownload install_itemr<r=r>rrQZfetch_distributionr[rrr precedencer,process_distributionlocation)rrdepsrVdlrrr9r9r:r0s2            zeasy_install.easy_installcCsx|p |j}|p*tjj||k}|p@|jd }|p||jdk o|tjjt|t|jk}|r| rx.|j|jD]}|j |krPqWd}t j dtjj ||r|j |||}xP|D]}|j|||qWn,|j|g}|j||d|d|dk rtx|D]}||krZ|SqZWdS)Nz.eggTz Processing %srrX)rr<r=r<endswithrrr project_namer^r rrB install_eggsr]egg_distribution)rrrZrVr_Zinstall_neededrdistsr9r9r:r[s.     zeasy_install.install_itemcCsRt|}xAtD]9}d|}t||dkrt||||qWdS)z=Sets the install directories by applying the install schemes.install_N)r r rr)rr schemerPattrnamer9r9r:r s    zeasy_install.select_schemecGs?|j||jj|||j|jkrC|jj||jj||j|||j|jr rrr<rlistdirrr!shutilmove)rr dist_filename setup_basedstrcontentsr9r9r: maybe_moves"   zeasy_install.maybe_movecCs>|jr dSx*tjj|D]}|j|q#WdS)N)r ScriptWriterbestget_args write_script)rrrr9r9r:rHs z$easy_install.install_wrapper_scriptscCsmt|j}t||}|rP|j|t}tj||}|j|t|ddS)z/Generate a legacy script wrapper and install itrpN) rUrois_python_script_load_templaterr| get_headerrrE)rrrI script_textdev_pathrZ is_scriptbodyr9r9r:rFs zeasy_install.install_scriptcCs:d}|r|jdd}td|}|jdS)z There are a couple of template scripts in the package. This function loads one of them and prepares it for use. z script.tmplz.tmplz (dev).tmplrzutf-8)rPr decode)rr Z raw_bytesr9r9r:r's zeasy_install._load_templatetc sjfdd|Dtjd|jtjjj|}j|t}j st |tjj |rtj |t |d|}|j|WdQRXt|d|dS)z1Write an executable file to the scripts directorycs(g|]}tjjj|qSr9)r<r=r'r)rrd)rr9r:r9s z-easy_install.write_script..zInstalling %s script to %sr*Ni)rr rrr<r=r'rN current_umaskrr!r>rr,r>chmod)rrIrzmodertargetmaskrmr9)rr:r6s     zeasy_install.write_scriptcCs|jjdr(|j||gS|jjdrP|j||gS|}tjj|r|jd rt|||jn$tjj |rtjj |}|j |r|j r|dk r|j |||}tjj|d}tjj|sttjj|dd}|sRtdtjj |t|dkrtdtjj ||d }|jrtj|j||gS|j||SdS) Nz.eggz.exez.pyzsetup.pyrz"Couldn't find a setup script in %sr4zMultiple setup scripts in %sr)r@ra install_egg install_exer<r=isfilerunpack_progressrabspath startswithrr{r'r>rrrr}r rreport_editablebuild_and_install)rrrwrVrx setup_scriptZsetupsr9r9r:rcHs8"  zeasy_install.install_eggscCs[tjj|r3t|tjj|d}nttj|}tj |d|S)NzEGG-INFOmetadata) r<r=rr'r'r( zipimport zipimporterr& from_filename)regg_pathrr9r9r:rdrs zeasy_install.egg_distributionc Cstjj|jtjj|}tjj|}|jsIt||j|}t ||stjj |rtjj | rt j |d|jn/tjj|r|jtj|fd|yd}tjj |r$|j|rtjd}}qtjd}}ng|j|rS|j||jd}}n8d}|j|r{tjd}}ntjd}}|j|||f|dtjj|tjj|ft|d |Wn%tk rt|d dYnX|j||j|S) Nrz Removing FZMovingZCopyingZ ExtractingTz %s to %sfix_zipimporter_caches)r<r=r'rrBrrr!rdr/rrr remove_treer>rrrrurvcopytreersmkpathunpack_and_compilecopy2r<update_dist_cachesr#rN)rrrV destinationrZnew_dist_is_zippedrmrYr9r9r:rzsT   %      zeasy_install.install_eggc st|}|dkr(td|tdd|jddd|jdddt}tjj||jd}||_ |d}tjj|d }tjj|d }t |t |||_ |j ||tjj|svt|d } | jd xR|jdD]A\} } | d kr'| jd| jddj| fq'W| jtjj|d|jfddtj|Dtj||d|jd|j|j||S)Nz(%s is not a valid distutils Windows .exerbrr rplatformz.eggz.tmpzEGG-INFOzPKG-INFOr*zMetadata-Version: 1.0 target_versionz%s: %s _-rCcs)g|]}tjj|dqS)r)r<r=r')rr)rr9r:rs z,easy_install.install_exe..rr)r2rr&getrr<r=r'egg_namer^r!r' _provider exe_to_eggr>r,r>itemsrPtitler-rr|r~r make_zipfilerrr) rrwrVcfgrregg_tmpZ _egg_infoZpkg_infrmkvr9)rr:rs<        - zeasy_install.install_exec st|ggifdd}t||g}xD]}|jjdrY|jd}|d}tj|dd|d.processz.pydrr4z.pyzEGG-INFOrrz.txtr*rLNrrr)z top_levelz native_libs)r4rr@rarrrr<r=r'rZ write_stub byte_compileZwrite_safety_flagZ analyze_eggrr>r,r>r-) rrwrrZstubsresrresourceZpyfiler Ztxtrmr9)rrrrrr:rs6        !zeasy_install.exe_to_egga( 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 Csd}|jrV|j rV|d|j7}|jtttjkrV|d|j7}|j }|j }|j }d}|t S)z9Helpful installation message for display to package usersz %(what)s %(eggloc)s%(extras)srLr) rr_easy_install__mv_warningrrrrr=_easy_install__id_warningr^rbrr) rreqrwhatrZegglocr rextrasr9r9r:rl#s   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-tjj|}tj}d|jtS)NrL)r<r=r<rr?_easy_install__editable_msgr)rrrr<pythonr9r9r:r<s zeasy_install.report_editablecCs(tjjdttjjdtt|}|jdkrid|jd}|jdd|n|jdkr|jdd|jr|jdd t j d |t |ddd j |yt ||Wn?tk r#}ztd |jdfWYdd}~XnXdS) Nzdistutils.command.bdist_eggzdistutils.command.egg_inforrr4rrz-qz-nz Running %s %s zSetup script exited with %s)rmodules setdefaultrrrrrrr rrr'rrrr)rrrxrrr9r9r:rAs   *zeasy_install.run_setupc Cs ddg}tjdddtjj|}z|jtjj||j||j|||t|g}g}x?|D]7}x.||D]"}|j|j |j |qWqW| r|j rt j d||SWdt|t j|jXdS)Nrz --dist-dirrz egg-dist-tmp-dirz+No eggs found in %s (setup script problem?))rRrSr<r=r<_set_fetcher_optionsrrr$rr^rr rrrr) rrrxrZdist_dirZall_eggseggsrPrr9r9r:rUs$    $  zeasy_install.build_and_installc Cs|jjdj}d }i}xC|jD]5\}}||krLq1|d||jdd  make_relativer-)rrr_rrmr9r9r:ris4      zeasy_install.update_pthcCstjd|||S)NzUnpacking %s to %s)r debug)rrryr9r9r:rszeasy_install.unpack_progresscsggfdd}t|||jjsx9D]1}tj|tjdBd@}t||qQWdS)Ncs~|jdr/|jd r/j|n+|jdsM|jdrZj|j||j rz|p}dS)Nz.pyz EGG-INFO/z.dllz.so)rarrrr)rry)rto_chmodrr9r:pfs  z+easy_install.unpack_and_compile..pfimi)rrrr<statST_MODEr)rrrrrmrr9)rrrr:rs   zeasy_install.unpack_and_compilecCstjr|jddSddlm}zbtj|jd||ddddd|j|j r||d|j ddd|jWdtj|jXdS)Nz%byte-compiling is disabled, skipping.r)rr4rforcer) rdont_write_bytecoderdistutils.utilrr rrrr)rrrr9r9r:rs   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}||jtjjddfS)N PYTHONPATHr)_easy_install__no_default_msgrr<environr)rtemplater9r9r:r1s z#easy_install.no_default_version_msgcCs-|jr dStjj|jd}tdd}|jd}d}tjj|rtj d|jt j |}|j }WdQRX|j dstd |||kr tjd ||jst|t j |d d d}|j|WdQRX|j|gd |_dS)z8Make sure there's a site.py in the target dir, if neededNzsite.pyrz site-patch.pyzutf-8rzChecking existing site.py in %sz def __boot():z;%s is not a setuptools-generated site.py; please remove it.z Creating %sr*encodingT)rr<r=r'rr rr>r rior,readrrrrr!r>r)rZsitepysourcecurrentstrmr9r9r:rYs,     zeasy_install.install_site_pycCs|js dSttjjd}xctj|jD]O\}}|j|r8tjj | r8|j d|tj |dq8WdS)zCreate directories under ~.N~zos.makedirs('%s', 0o700)i) rrr<r=rrG iteritemsrrr debug_printr=)rhomer r=r9r9r:r s "zeasy_install.create_home_pathrrz/$base/lib/python$py_version_short/site-packagesrz $base/binz$base/Lib/site-packagesz $base/ScriptscGs|jdj}|jr|j}|j|d<|jjtj|j}xB|j D]4\}}t ||ddkr\t |||q\Wddl m }xi|D]a}t ||}|dk r|||}tjdkrtjj|}t |||qWdS)NrrLr)rr)get_finalized_commandrrrr rr<r DEFAULT_SCHEMErrrrrr=r)rrrrgrrrr9r9r:r/s      zeasy_install._expand)rSNrT)rUrVrW)rXrYrZ)zupgrader\r])r^r_r`)rarDrb)rcrdre)rfrgrh)rirjrk)rlrmrn)rorprq)rrrsrt)ruNrv)rwrxry)rzr{r|)zeditabler~r)rrr)rrr)rrr)zversionNr)rNr)P__name__ __module__ __qualname____doc__ descriptionZcommand_consumes_arguments user_optionsboolean_optionsrrrZhelp_msgr negative_optrrrrr staticmethodrrrrrrr!r)rrrMrNlstripr5r7r8r0r+rJrNrOrQ contextlibcontextmanagerrWr0r[r r]rsr{rHrFrrrcrdrrrrrrlrrrrrrirrrrr1rYr rr rrr9r9r9r:r0xs       0   z     *  <     $$ '    *  6 - 5        %       cCs.tjjddjtj}td|S)Nrr)r<rrrpathsepfilter)rr9r9r:r2Fs!r2c Csg}|jttjg}tjtjkrD|jtjx2|D]*}|rKtjdkr|jtjj |ddntj dkr|jtjj |ddtj dd dtjj |dd gn%|j|tjj |ddgtjd krKd |krKtj j d }|rKtjj |ddtj dd d}|j|qKWtdtdf}x'|D]}||kr|j|qWtjr|jtjy|jtjWntk rYnXttt|}|S)z& Return a list of 'site' dirs os2emxriscosLibz site-packagesrlibrNrz site-pythondarwinzPython.frameworkHOMELibraryPythonpurelibplatlib)zos2emxzriscos)extendr2rrrrrr<r=r'seprrrrrrrZgetsitepackagesAttributeErrorrrr)sitedirsrrrZhome_spZ lib_pathsZsite_libr9r9r:rKsV  "        rccsIi}x<|D]4}t|}||kr.q d||egg path translations for a given .exe filePURELIB/rPLATLIB/pywin32_system32PLATLIB/SCRIPTS/EGG-INFO/scripts/DATA/lib/site-packagesrrrzPKG-INFOr4z .egg-inforNz EGG-INFO/z.pthz -nspkg.pthPURELIBPLATLIB\rz%s/%s/cSs(g|]\}}|j|fqSr9)r@)rrdyr9r9r:rs z$get_exe_prefixes..)r+r)r,r)r-r)r.r/)r0r)r1r2)rZipFileinfolistrrrrarr'upperrrGPY3rrrOrPrrr-sortreverse)Z exe_filenamerrVrr rrzpthr9r9r:r4s>  ")"  -   c@syeZdZdZdZfddZddZddZed d Z d d Z d dZ ddZ dS)r1z)A .pth file with Distribution paths in itFcCs||_ttt||_ttjj|j|_|j t j |gddx6t |j D]%}tt|jt|dqoWdS)NT)rrrrr r<r=r<basedir_loadr$__init__rrrjr#)rrr r=r9r9r:r> s  zPthDistributions.__init__cCsug|_d}tj|j}tjj|jr't|jd}x|D]}|j drmd}qO|j }|jj ||j sO|j j drqOt tjj|j|}|jdpopdirtyr-)rZ saw_importrrmrr=r9r9r:r=s2   "&     zPthDistributions._loadc Cs|js dStt|j|j}|rtjd|j|j|}dj |d}t j j |jrt j |jt|jd}|j|WdQRXn8t j j|jrtjd|jt j |jd|_dS)z$Write changed .pth file back to diskNz Saving %srLrzDeleting empty %sF)rCrrrrr rr _wrap_linesr'r<r=rrr,r>r>)rZ rel_pathsrdatarmr9r9r:r2s zPthDistributions.savecCs|S)Nr9)rr9r9r:rDHszPthDistributions._wrap_linescCso|j|jko6|j|jkp6|jtjk}|r[|jj|jd|_tj||dS)z"Add `dist` to the distribution mapTN) r^rr r<getcwdrrCr$rj)rrnew_pathr9r9r:rjLs zPthDistributions.addcCsIx2|j|jkr4|jj|jd|_qWtj||dS)z'Remove `dist` from the distribution mapTN)r^rrkrCr$)rrr9r9r:rkZs zPthDistributions.removecCstjjt|\}}t|j}|g}tjdkrKdpQtj}xut||kr||jkr|jtj |j |j |Stjj|\}}|j|qWW|SdS)Nr) r<r=rrrr<altsepr rcurdirr:r')rr=npathlastZbaselenrr r9r9r:ras   zPthDistributions.make_relativeN) rrrrrCr>r=rrrDrjrkrr9r9r9r:r1s     c@s:eZdZeddZedZedZdS)RewritePthDistributionsccs*|jVx|D] }|VqW|jVdS)N)preludepostlude)clsrrr9r9r:rDrs  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)rrr classmethodrDr;rMrNr9r9r9r:rLqs  rLZSETUPTOOLS_SYS_PATH_TECHNIQUErawZrewritecCs,ttjtrtStjtjjS)z_ Return a regular expression based on first_line_re suitable for matching strings. )rrpatternrUrecompilerr9r9r9r:_first_line_resrUcCs|tjtjgkrAtjdkrAt|tj||Stj\}}}t j ||d|dd||ffdS)Nrrr4z %s %s) r<rrkr rrS_IWRITErr6rGreraise)funcargexcetevrr9r9r: auto_chmods ' r]cCs=t|}t|tj|r/t|n t|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_uncacherpath_importer_cache!_replace_zip_directory_cache_data*_remove_and_clear_zip_directory_cache_data) dist_pathrnormalized_pathr9r9r:rs <  rcCsrg}t|}xY|D]Q}t|}|j|r|||dtjdfkr|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. r4r)rrrr<r r)rccacheresult prefix_lenpnpr9r9r:"_collect_zipimporter_cache_entriess    #ricCsZxSt||D]B}||}||=|o9|||}|dk r|||.clear_and_remove_cached_zip_archive_directory_datarj)rlr_zip_directory_cache)rcrnr9r9r:ra)s  raZ__pypy__cCs&dd}t|tjd|dS)NcSs/|jtj||jtj||S)N)rmrrupdatero)r=rkr9r9r:)replace_cached_zip_archive_directory_data@s  zT_replace_zip_directory_cache_data..replace_cached_zip_archive_directory_datarj)rlrro)rcrqr9r9r:r`?s  r`zc Cs;yt||dWnttfk r2dSYnXdSdS)z%Is this string a valid Python script?execFTN)rT SyntaxError TypeError)rQrr9r9r: is_pythonRs  rucCs[y2tj|dd}|jd}WdQRXWnttfk rP|SYnX|dkS)zCDetermine if the specified executable is a .sh (contains a #! line)rzlatin-1rNz#!)rr,rr.r/)r?fpmagicr9r9r:is_sh\s  rxcCstj|gS)z@Quote a command line argument according to Windows parsing rules) subprocess list2cmdline)rYr9r9r: nt_quote_argfsr{cCsb|jds|jdr"dSt||r5dS|jdr^d|jdjkSdS)zMIs this text, as a whole, a Python script? (as opposed to shell/bat/etc. z.pyz.pywTz#!rrF)rarur splitlinesr@)rrr9r9r:rksr)rcGsdS)Nr9)rr9r9r:_chmod}sr}cCsctjd||yt||Wn8tjk r^}ztjd|WYdd}~XnXdS)Nzchanging mode of %s to %ozchmod failed: %s)r rr}r<error)r=rr~r9r9r:rs rc@seZdZdZgZeZeddZeddZ eddZ edd Z ed d Z d d Z eddZddZeddZeddZdS) 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. r9)rOr9r9r:r}szCommandSpec.bestcCs(tjjtj}tjjd|S)NZ__PYVENV_LAUNCHER__)r<r=r@rr?rr)rO_defaultr9r9r:_sys_executableszCommandSpec._sys_executablecCsOt||r|St|tr,||S|dkrB|jS|j|S)zg Construct a CommandSpec from a parameter to build_scripts, which may be None. N)rrfrom_environment from_string)rOparamr9r9r: from_params   zCommandSpec.from_paramcCs||jgS)N)r)rOr9r9r:rszCommandSpec.from_environmentcCstj||j}||S)z} Construct a command spec from a simple string representing a command line parseable by shlex.split. )shlexr split_args)rOstringrr9r9r:rszCommandSpec.from_stringcCsPtj|j||_tj|}t|sLdg|jdd.z#!rL)ryrz)rrr9r9r:rszCommandSpec._renderN)rrrrrrrrPr}rrrrrrrrrrr9r9r9r:rs    rc@seZdZeddZdS)WindowsCommandSpecrFN)rrrrrr9r9r9r:rs rc@seZdZdZejdjZeZ e ddddZ e ddddZ e dd d Z ed d Ze d dZe ddZe ddZe ddddZdS)r|z` 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)() ) NFcCsMtjdt|rtntj}|jd||}|j||S)Nz Use get_argsr)warningsrDeprecationWarningWindowsScriptWriterr|r}get_script_headerr~)rOrr?wininstwriterheaderr9r9r:get_script_argsszScriptWriter.get_script_argscCsKtjdt|rd}|jjj|}|j||jS)NzUse get_headerz python.exe)rrrcommand_spec_classr}rrr)rOrr?rcmdr9r9r:rs  zScriptWriter.get_script_headerc cs|dkr|j}t|j}xdD]}|d}xn|j|jD]W\}}|j||jt}|j||||} x| D] } | VqWqWWq1WdS)z Yield write_script() argument tuples for a distribution's console_scripts and gui_scripts entry points. NconsoleguiZ_scripts)zconsolezgui) rrUro get_entry_mapr_ensure_safe_namerr_get_script_args) rOrrrtype_rr eprrrr9r9r:r~ s    "  zScriptWriter.get_argscCs(tjd|}|r$tddS)z? Prevent paths in *_scripts entry point names. z[\\/]z+Path separators not allowed in script namesN)rSsearchr)r Z has_path_sepr9r9r:rszScriptWriter._ensure_safe_namecCs*tjdt|r tjS|jS)NzUse best)rrrrr})rOZ force_windowsr9r9r: get_writer'szScriptWriter.get_writercCs?tjdks-tjdkr7tjdkr7tjS|SdS)zD Select the best ScriptWriter for this environment. win32javarN)rrr<r _namerr})rOr9r9r:r}-s- zScriptWriter.bestccs|||fVdS)Nr9)rOrr rrr9r9r:r7szScriptWriter._get_script_argsrcCs/|jjj|}|j||jS)z;Create a #! line, getting options (if any) from script_text)rr}rrr)rOrr?rr9r9r:r<s zScriptWriter.get_header)rrrrrMrNrrrrrPrrr~rrrr}rrr9r9r9r:r|s     r|c@speZdZeZeddZeddZeddZeddZ e d d Z d S) rcCstjdt|jS)NzUse best)rrrr})rOr9r9r:rGszWindowsScriptWriter.get_writercCs2tdtd|}tjjdd}||S)zC Select the best ScriptWriter suitable for Windows r?ZnaturalZSETUPTOOLS_LAUNCHER)rWindowsExecutableLauncherWriterr<rr)rOZ writer_lookuplauncherr9r9r:r}Ms  zWindowsScriptWriter.bestc #stdddd|}|tjdjjdkr]djt}tj|t ddd d d dd g}|j ||j ||}fd d|D}|||d|fVdS)z For Windows, add a .py extensionrz.pyarz.pywPATHEXT;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.z.pyz -script.pyz.pycz.pyoz.execsg|]}|qSr9r9)rrd)r r9r:rgs z8WindowsScriptWriter._get_script_args..rN) rr<rr@rrrrr UserWarningrk_adjust_header) rOrr rrextrrrr9)r r:rZs"  z$WindowsScriptWriter._get_script_argscCsrd}d}|dkr%||}}tjtj|tj}|jd|d|}|j|rn|S|S)z Make sure 'pythonw' is used for gui and and 'python' is used for console (regardless of what sys.executable is). z pythonw.exez python.exerrrepl)rSrTescape IGNORECASEsub _use_header)rOrZ orig_headerrRrZ pattern_ob new_headerr9r9r:rjs  z"WindowsScriptWriter._adjust_headercCs2|ddjd}tjdkp1t|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. rr4"rr)rOrrr)rZ clean_headerr9r9r:rxs zWindowsScriptWriter._use_headerN) rrrrrrPrr}rrrrr9r9r9r:rDs  rc@s"eZdZeddZdS)rc #s|dkr$d}d}dg}nd}d}dddg}|j||}fd d |D} |||d | fVd t|d fVtsd} | td fVdS)zG For Windows, add a .py extension and an .exe launcher rz -script.pywz.pywcliz -script.pyz.pyz.pycz.pyocsg|]}|qSr9r9)rrd)r r9r:rs zDWindowsExecutableLauncherWriter._get_script_args..rz.exerpz .exe.manifestN)rget_win_launcherr;load_launcher_manifest) rOrr rrZ launcher_typerrhdrrZm_namer9)r r:rs    z0WindowsExecutableLauncherWriter._get_script_argsN)rrrrPrr9r9r9r:rs rcCsGd|}tr(|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;rPr )typeZ launcher_fnr9r9r:rs   rcCs>tjtd}tjr&|tS|jdtSdS)Nzlauncher manifest.xmlzutf-8) pkg_resourcesr rrGPY2varsr)r manifestr9r9r:rs  rFcCstj|||S)N)rur)r= ignore_errorsonerrorr9r9r:rsrcCs tjd}tj||S)N)r<umask)tmpr9r9r:rs rcCsMddl}tjj|jd}|tjd.DistributionWithoutHelpCommandsrc s(tj|||WdQRXdS)N) _patch_usage _show_help)rrkw)r&r9r:rs z8main..DistributionWithoutHelpCommands._show_helpN)rrr common_usagerr9)r&r9r:DistributionWithoutHelpCommandss rr4 script_argsz-qr0z-vrI distclass)rrZsetuptools.distr&rrr)rrrrr9)r&r:r3s  c #shddl}tjdjfdd}|jj}||j_z dVWd||j_XdS)Nrze usage: %(script)s [options] requirement_or_url ... or: %(script)s --help cstdtjj|S)Nscript)rr<r=rB)rI)USAGEr9r: gen_usages z_patch_usage..gen_usage)distutils.corerMrNrcorer)rrZsavedr9)rr:rs    r)rrrrrrdistutils.errorsrrrr distutils.command.installr r rr r Zdistutils.command.build_scriptsrrArrr<rrurRrrSrr$rMrrr7rryrrrGZ six.movesrrrrZsetuptools.sandboxrZsetuptools.py31compatrrZsetuptools.py27compatrZsetuptools.commandrZsetuptools.archive_utilrZsetuptools.package_indexrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,filterwarnings PEP440Warning__all__r;r/rrErJr;r0r2rrr2r4r1rLrrrUr]rrirlr^rabuiltin_module_namesr`rurxr{rrr} ImportErrorrrrZsys_executablerobjectr|rrrrrrrrrr3rrr9r9r9r: s"                  d            A ) ) 'l  R         T `A