3 (\T @s4dZddlmZddlmZddlmZmZddlmZmZm 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&m'Z'm(Z(dd l)m*Z*dd l+m,Z,ddl-m.Z.m/Z/ddl)m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;mZ>ddl?m@Z@ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPdd lQZAeRZSejTdeAjUdddddddgZVd d!ZWd"dZXe,jYrBd#d$ZZd%d&Z[nd'd$ZZd(d&Z[d)d*Z\Gd+dde0Z]d,d-Z^d.d/Z_d0d1Z`d2dZad3dZbGd4ddeHZcGd5d6d6ecZdejejfd7d8d9kredZcd:d;Zgdd?Zid@dAZjdsdBdCZkdDdEZldFdGZmdHejnkremZondIdJZodtdLdMZpdNdOZqdPdQZrdRdSZsyddTlmtZuWnevk rndUdVZuYnXdWdXZtGdYdZdZewZxexjyZzGd[d\d\exZ{Gd]d^d^Z|Gd_d`d`e|Z}Gdadbdbe}Z~e|jZe|jZdcddZdedfZdgehfdhdiZdjdkZdldmZdudndZe"jdodpZGdqdrdre*Zd 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)DistutilsArgErrorDistutilsOptionErrorDistutilsErrorDistutilsPlatformError)INSTALL_SCHEMES SCHEME_KEYS)logdir_util) first_line_re)find_executableN)get_config_varsget_path)SetuptoolsDeprecationWarning)six) configparsermap)Command) run_setup) rmtree_safe)setopt)unpack_archive) PackageIndexparse_requirement_arg URL_SCHEME) bdist_eggegg_info)Wheel) yield_linesnormalize_pathresource_stringensure_directoryget_distributionfind_distributions Environment Requirement Distribution PathMetadata EggMetadata WorkingSetDistributionNotFoundVersionConflict DEVELOP_DISTdefault)categorysamefile easy_installPthDistributionsextract_wininst_cfgmainget_exe_prefixescCstjddkS)NP)structcalcsizer<r<{/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-rm6ck8ia/setuptools/setuptools/command/easy_install.pyis_64bitPsr>cCsjtjj|otjj|}ttjdo&|}|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. r2)ospathexistshasattrr2normpathnormcase)p1p2Z both_existZ use_samefileZnorm_p1Znorm_p2r<r<r=r2TscCs|S)Nr<)sr<r<r= _to_bytesfsrHc Cs*ytj|ddStk r$dSXdS)NasciiTF)r text_type UnicodeError)rGr<r<r=isasciiis  rLcCs |jdS)Nutf8)encode)rGr<r<r=rHqsc Cs(y|jddStk r"dSXdS)NrITF)rNrK)rGr<r<r=rLts  cCstj|jjddS)N z; )textwrapdedentstripreplace)textr<r<r=|srUc@seZdZdZdZdZdddddddddddddddddddddgZdd dd dd0d3d9ddddZ?ejdj Z@ddZAddZBddZCddZDddZEddZFddZGddZHejdj ZIddZJddZKddZLeMeMddddZNeMdddZOddZPdS)r3z'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=rGinstall 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'usercCs,d|_d|_|_d|_|_|_d|_d|_d|_d|_ d|_ |_ d|_ |_ |_d|_|_|_d|_|_|_d|_d|_d|_d|_d|_d|_d|_d|_d|_tjrtj |_!tj"|_#n d|_!d|_#d|_$d|_%d|_&|_'d|_(i|_)d|_*d|_+|j,j-|_-|j,j.||j,j/ddS)NrFr3)0rzip_oklocal_snapshots_ok install_dir script_direxclude_scripts index_url find_linksbuild_directoryargsoptimizerecordr^ always_copy multi_versionrno_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)selfr<r<r=initialize_optionssF     zeasy_install.initialize_optionscCs"dd|D}tt|j|dS)Ncss*|]"}tjj|stjj|r|VqdS)N)r?r@rAislink).0filenamer<r<r= sz/easy_install.delete_blockers..)listr _delete_path)rblockersZextant_blockersr<r<r=delete_blockersszeasy_install.delete_blockerscCsJtjd||jrdStjj|o.tjj| }|r8tntj}||dS)Nz Deleting %s) r infodry_runr?r@isdirrrmtreeunlink)rr@Zis_treeZremoverr<r<r=rs  zeasy_install._delete_pathcCs6tjdd}td}d}t|jfttdS)zT Render the Setuptools version and installation details, then exit. N setuptoolsz=setuptools {dist.version} from {dist.location} (Python {ver}))sysrr%printformatlocals SystemExit)verdisttmplr<r<r=_render_versions zeasy_install._render_versionc Cst|jo |jtjjd}tdd\}}|jj|jj|jj||dd|d|d||||t tddd |_ t j r|j |j d <|j|j d <|j|j|j|jd d d d|jdkr|j|_|jdkrd|_|jdd!|jdd"|jr|jr|j|_|j|_|jdd#tttj}t|_|jdk rdd|jjdD}xV|D]N}t jj!|s~t"j#d|n,t||krt$|dn|jj%t|q^W|j&s|j'|j(pd|_(|jdd|_)x4|jt|jfD] }||j)kr|j)j*d|qW|j+dk r8dd|j+jdD}ndg}|j,dkr`|j-|j(|j)|d|_,t.|j)tj|_/|j0dk rt1|j0t2j3r|j0j|_0ng|_0|j4r|j,j5|j)tj|js|j,j6|j0|jdd$t1|j7t8s@y2t8|j7|_7d|j7kodknst9Wnt9k r>t$dYnX|j&rZ|j: rZt;d|j<sjt;d g|_=dS)%Nrr exec_prefixrabiflags) dist_name dist_version dist_fullname py_versionpy_version_shortpy_version_nodot sys_prefixrsys_exec_prefixrruserbaseusersiterrrrFrrinstallrcSsg|]}tjj|jqSr<)r?r@ expanduserrR)rrGr<r<r= :sz1easy_install.finalize_options..,z"%s (in --site-dirs) does not existz$ (in --site-dirs) is not on sys.pathzhttps://pypi.org/simple/cSsg|] }|jqSr<)rR)rrGr<r<r=rOs*) 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))rr)rr)rr)rr)>rrrsplitrrget_name get_version get_fullnamegetattr config_varsrrrr_fix_install_dir_for_user_siteexpand_basedirs expand_dirs_expandrrrset_undefined_optionsrrrrr"r@ get_site_dirs all_site_dirsrr?rr warnrappendrcheck_site_dirr shadow_pathinsertrr create_indexr' local_indexr isinstancer string_typesrZscan_egg_linksadd_find_linksrint ValueErrorrrroutputs) rrrrrCrrb path_itemrr<r<r=finalize_optionss                zeasy_install.finalize_optionscCs`|j stj rdS|j|jdkr2d}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?namerS select_scheme)rmsgZ scheme_namer<r<r=rts z+easy_install._fix_install_dir_for_user_sitecCs\xV|D]N}t||}|dk rtjdks0tjdkr.zInstalling %s script to %sNr*i)rr rrr?r@r'rQr current_umaskr$rArr,rAchmod)rrLr|modertargetmaskrpr<)rr=r<s   zeasy_install.write_scriptcCs`|jjdr|j||gS|jjdr8|j||gS|jjdrT|j||gS|}tjj|r|jd rt|||j ntjj |rtjj |}|j |r|j r|dk r|j|||}tjj|d}tjj|s2ttjj|dd}|stdtjj |t|dkr*td tjj ||d }|jrPtj|j||gS|j||SdS) Nz.eggz.exez.whlz.pyzsetup.pyrz"Couldn't find a setup script in %sr4zMultiple setup scripts in %sr)rCrc install_egg install_exe install_wheelr?r@isfilerunpack_progressrabspath startswithrr}r'rArrrrr rreport_editablebuild_and_install)rrryrXrz setup_scriptZsetupsr<r<r=rePs<   zeasy_install.install_eggscCs>tjj|r"t|tjj|d}nttj|}tj ||dS)NzEGG-INFO)metadata) r?r@rr*r'r+ zipimport zipimporterr) from_filename)regg_pathrr<r<r=rf|s    zeasy_install.egg_distributionc Cstjj|jtjj|}tjj|}|js2t||j|}t ||s|tjj |rttjj | rtt j ||jdn"tjj|r|jtj|fd|yd}tjj |r|j|rtjd}}n tjd}}nL|j|r|j||jd}}n*d}|j|rtjd}}n tjd}}|j|||f|dtjj|tjj|ft||d Wn$tk rzt|dd YnX|j||j|S) N)rz Removing FZMovingZCopyingZ ExtractingTz %s to %s)fix_zipimporter_caches)r?r@r'rrErrr$rfr2rrr remove_treerArrrrwrxcopytreerumkpathunpack_and_compilecopy2r=update_dist_cachesr#rQ)rrrX destinationrZnew_dist_is_zippedrpr\r<r<r=rsT               zeasy_install.install_eggc sTt|}|dkrtd|td|jdd|jddtd}tjj||jd}||_ |d}tjj|d}tjj|d }t |t |||_ |j ||tjj|st|d } | jd x<|jdD].\} } | d kr| jd | jddj| fqW| jtjj|d|jfddtj|Dtj|||j|jd|j||S)Nz(%s is not a valid distutils Windows .exerr r)rdrplatformz.eggz.tmpzEGG-INFOzPKG-INFOr*zMetadata-Version: 1.0 target_versionz%s: %s _-rFcsg|]}tjj|dqS)r)r?r@r')rr)rr<r=rsz,easy_install.install_exe..)rr)r5rr)getrr?r@r'egg_namer`r$r* _provider exe_to_eggrAr,rAitemsrStitler-rr~rr make_zipfilerrr) rryrXcfgrregg_tmpZ _egg_infoZpkg_infrpkvr<)rr=rs<      " zeasy_install.install_exec s>t|ggifdd}t||g}xtD]l}|jjdr>|jd}|d}tj|dd|d<tjj f|}j ||j |tj ||q>W|j tj tjj dtj|xbdD]Z} t| rtjj d| d } tjj| st| d } | jd j t| d | jqWd S)z;Extract a bdist_wininst to the directories an egg would usecs|j}xԈD]\}}|j|r||t|d}|jd}tjjf|}|j}|jdsl|jdrtj |d |d <dtjj |dd<j |n4|jdr|dkrdtjj |dd<j ||SqW|jdst j d |dS) N/z.pydz.dllr4rz.pyzSCRIPTS/z.pthzWARNING: can't process %sr)rCrrrr?r@r'rcr strip_modulesplitextrr r)srcr{rGoldnewpartsrb)r native_libsprefixes to_compile top_levelr<r=processs$      z(easy_install.exe_to_egg..processz.pydrr4z.pyzEGG-INFOrrz.txtr*rONrrr)rr)r7rrCrcrrrr?r@r'rZ write_stub byte_compileZwrite_safety_flagZ analyze_eggrrAr,rAr-) rryrrZstubsresrresourceZpyfiler txtrpr<)rrrrrr=rs6           zeasy_install.exe_to_eggc Cst|}|jsttjj|j|j}tjj|}|j sBt |tjj |rntjj | rnt j||j dn"tjj|r|jtj|fd|z.|j|j|fdtjj|tjj|fWdt|ddX|j||j|S)N)rz Removing zInstalling %s to %sF)r)r Z is_compatibleAssertionErrorr?r@r'rrrrr$rrr rrArrZinstall_as_eggrEr=rrQrf)r wheel_pathrXwheelrr<r<r=rs.      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}|jtttjkr@|d|j7}|j }|j }|j }d}|t S)z9Helpful installation message for display to package usersz %(what)s %(eggloc)s%(extras)srOr) rr_easy_install__mv_warningrrr"rr@_easy_install__id_warningr`rdrr) rreqrwhatrZegglocr rextrasr<r<r=rnJsz 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)NrO)r?r@r=rrB_easy_install__editable_msgr)rrrr=pythonr<r<r=rcs zeasy_install.report_editablecCstjjdttjjdtt|}|jdkrNd|jd}|jdd|n|jdkrd|jdd|jrv|jdd t j d |t |ddd j |yt ||Wn6tk 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)rrrzrrr<r<r=rhs      zeasy_install.run_setupc Csddg}tjdtjj|d}z|jtjj||j||j|||t|g}g}x2|D]*}x$||D]}|j|j |j |qlWq^W| r|j rt j d||St|t j|jXdS)Nrz --dist-dirz egg-dist-tmp-)rdirz+No eggs found in %s (setup script problem?))rUrVr?r@r=_set_fetcher_optionsrrr'rr`rr rrrr) rrrzrZdist_dirZall_eggseggsrSrr<r<r=r|s$   zeasy_install.build_and_installc Cst|jjdj}d }i}x2|jD]&\}}||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. r3rrrrrr4rr)r3z setup.cfgN)rrrrrr) rrcopyrrSdictr?r@r'rZ edit_config) rrOZei_optsZfetch_directivesZ fetch_optionsrSrsettingsZ cfg_filenamer<r<r=rs  z!easy_install._set_fetcher_optionscCs0|jdkrdSxX|j|jD]H}|js2|j|jkrtjd||jj||j|jkr|jj|jqW|js|j|jjkrtjd|n2tjd||jj ||j|jkr|jj |j|j s,|jj |jdkr,t jj|jd}t jj|rt j|t|d}|j|jj|jd|jdS)Nz&Removing %s from easy-install.pth filez4%s is already the active version in easy-install.pthz"Adding %s to easy-install.pth filerzsetuptools.pthwtrO)rrSrr`r rrmrpathsrlrrsaver?r@r'rrrr,rA make_relativer-)rrrbrrpr<r<r=rks4           zeasy_install.update_pthcCstjd|||S)NzUnpacking %s to %s)r debug)rrr{r<r<r=rszeasy_install.unpack_progresscshggfdd}t|||jjsdx.D]&}tj|tjdBd@}t||q:WdS)Ncs\|jdr"|jd r"j|n|jds6|jdr@j|j||j rX|pZdS)Nz.pyz EGG-INFO/z.dllz.so)rcrrrr)rr{)rto_chmodrr<r=pfs    z+easy_install.unpack_and_compile..pfimi)rrrr?statST_MODEr)rrrrrprr<)rrrr=rs   zeasy_install.unpack_and_compilec Csjtjr dSddlm}z@tj|jd||dd|jd|jrT|||jd|jdWdtj|jXdS)Nr)rr4)rforcer) rdont_write_bytecodedistutils.utilrr rrrr)rrrr<r<r=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)rtemplater<r<r=r1sz#easy_install.no_default_version_msgcCs|jr dStjj|jd}tdd}|jd}d}tjj|rtj d|jt j |}|j }WdQRX|j dstd |||krtjd ||jst|t j |d dd }|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#rrAr rior,readrrrrr$rAr)rZsitepysourcecurrentstrmr<r<r=r[s,       zeasy_install.install_site_pycCsj|js dSttjjd}xJtj|jD]:\}}|j|r(tjj | r(|j d|tj |dq(WdS)zCreate directories under ~.N~zos.makedirs('%s', 0o700)i) rrr?r@rr iteritemsrrr debug_printr@)rhomer r@r<r<r=r ?szeasy_install.create_home_pathz/$base/lib/python$py_version_short/site-packagesz $base/bin)rr)rz$base/Lib/site-packagesz $base/ScriptscGs|jdj}|jrh|j}|j|d<|jjtj|j}x0|j D]$\}}t ||ddkr@t |||q@Wddl m }xJ|D]B}t ||}|dk rz|||}tjdkrtjj|}t |||qzWdS)NrrOr)rr)get_finalized_commandrrrr rr?r DEFAULT_SCHEMErrrrrr@r)rrrrirrrr<r<r=rUs         zeasy_install._expand)rVNrW)rXrYrZ)r[r\r])r^r_r`)rarbrc)rdrGre)rfrgrh)rirjrk)rlrmrn)rorprq)rrrsrt)rurvrw)rxNry)rzr{r|)r}r~r)rrr)rrr)rrr)rrr)rNr)rNr)F)F)T)N)r)Q__name__ __module__ __qualname____doc__ descriptionZcommand_consumes_arguments user_optionsboolean_optionsrrrZhelp_msgr negative_optrrrrr staticmethodrrrrrrr!r)rrrPrQlstripr5r7r8r0r+rMrQrRrT contextlibcontextmanagerrYr3r]r r_rur}rKrIrrrerfrrrrrrrnrrrrrrkrrrrr1r[r rr rrr<r<r<r=r3s    0 z   *    ;  $ $ '  ,6-5   %    cCs tjjddjtj}td|S)Nrr)r?rrrpathsepfilter)rr<r<r=r2lsr2c Csg}|jttjg}tjtjkr0|jtjx|D]}|r6tjdkr`|jtjj |ddn\tj dkr|jtjj |ddtj dd dtjj |dd gn|j|tjj |ddgtjd kr6d |kr6tj j d }|r6tjj |ddtj dd d}|j|q6Wtdtdf}x"|D]}||kr |j|q WtjrR|jtjy|jtjWntk rzYnXttt|}|S)z& Return a list of 'site' dirs os2emxriscosLibz site-packagesrlibrNrz site-pythondarwinzPython.frameworkHOMELibraryPythonpurelibplatlib)rr)extendr2rrrrrr?r@r'seprrrrrrrgetsitepackagesAttributeErrorrrr")sitedirsrrrZhome_spZ lib_pathsZsite_libr<r<r=rqsV            rccsi}x|D]}t|}||kr q d||<tjj|s6q tj|}||fVx|D]}|jds`qP|dkrjqPttjj||}tt |}|j xP|D]H}|j dst|j }||krd||<tjj|sq|tj|fVqWqPWq WdS)zBYield sys.path directories that might contain "old-style" packagesr4z.ptheasy-install.pthsetuptools.pthimportN)rr) r"r?r@rrvrcr,r'rr!r-rrstrip)inputsseenr=rPr rplinesliner<r<r= expand_pathss4           rc Cs&t|d}z tj|}|dkr$dS|d|d|d}|dkrHdS|j|dtjd|jd\}}}|dkrzdS|j|d|d d d }tj|}y<|j|} | j d d d} | j t j } |j tj| Wntjk rdSX|jd s|jd rdS|S|jXdS)znExtract configuration data from a bdist_wininst .exe Returns a configparser.RawConfigParser, or None rbN  zegg 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/cSsg|]\}}|j|fqSr<)rC)rrgyr<r<r=r%sz$get_exe_prefixes..)r3r)r4r)r5r)r6r7)r8r)r9r:)r$ZipFileinfolistrrrrcrr'upperrrPY3rr!rRrSrrr-sortreverse)Z exe_filenamerrYrr rr|pthr<r<r=r7s>     & c@sTeZdZdZdZffddZddZddZed d Z d d Z d dZ ddZ dS)r4z)A .pth file with Distribution paths in itFcCsp||_ttt||_ttjj|j|_|j t j |gddx(t |j D]}tt|jt|dqNWdS)NT)rrrr"rr?r@r=basedir_loadr'__init__r!rrlr&)rrrr@r<r<r=rF0szPthDistributions.__init__cCsg|_d}tj|j}tjj|jrt|jd}x|D]}|j drJd}q6|j }|jj ||j s6|j j drxq6t tjj|j|}|jd<tjj| s||kr|jjd|_q6d||<q6W|j|jr| rd|_x&|jo|jdj r |jjqWdS) NFrtrT#r4rr)rrfromkeysrr?r@rrr,rrrrRr"r'rDrApopdirtyr-)rZ saw_importrrprr@r<r<r=rE9s2        zPthDistributions._loadc Cs|js dStt|j|j}|rtjd|j|j|}dj |d}t j j |jr`t j |jt|jd}|j|WdQRXn(t j j|jrtjd|jt j |jd|_dS)z$Write changed .pth file back to diskNz Saving %srOrzDeleting empty %sF)rKrrrrr rr _wrap_linesr'r?r@rrr,rArA)rZ rel_pathsrdatarpr<r<r=rXs   zPthDistributions.savecCs|S)Nr<)rr<r<r=rLnszPthDistributions._wrap_linescCsN|j|jko$|j|jkp$|jtjk}|r>|jj|jd|_tj||dS)z"Add `dist` to the distribution mapTN) r`rrr?getcwdrrKr'rl)rrnew_pathr<r<r=rlrs  zPthDistributions.addcCs6x$|j|jkr$|jj|jd|_qWtj||dS)z'Remove `dist` from the distribution mapTN)r`rrmrKr')rrr<r<r=rms zPthDistributions.removecCstjjt|\}}t|j}|g}tjdkr2dp6tj}xVt||kr||jkrn|jtj |j |j |Stjj|\}}|j|q:W|SdS)Nr) r?r@rr"rrDaltseprrcurdirrBr')rr@npathlastZbaselenrrr<r<r=rs    zPthDistributions.make_relativeN) rrrrrKrFrErrrLrlrmrr<r<r<r=r4+s  c@s(eZdZeddZedZedZdS)RewritePthDistributionsccs(|jVx|D] }|VqW|jVdS)N)preludepostlude)clsrrr<r<r=rLs  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 classmethodrLr<rUrVr<r<r<r=rTs  rTZSETUPTOOLS_SYS_PATH_TECHNIQUErawZrewritecCs ttjtrtStjtjjS)z_ Return a regular expression based on first_line_re suitable for matching strings. )rrpatternrWrecompilerr<r<r<r=_first_line_res r]cCsd|tjtjgkr.tjdkr.t|tj||Stj\}}}t j ||d|dd||ffdS)Nrrr4z %s %s) r?rrmr rrS_IWRITErr6rreraise)funcargexcetZevrr<r<r= auto_chmods  rdcCs.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"_uncacherpath_importer_cache!_replace_zip_directory_cache_data*_remove_and_clear_zip_directory_cache_data) dist_pathrnormalized_pathr<r<r=rs <  rcCsTg}t|}xB|D]:}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)rr"rr?rr)rjcacheresult prefix_lenpnpr<r<r="_collect_zipimporter_cache_entriess   rpcCsDx>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)rp)rjrkupdaterrn old_entryZ new_entryr<r<r=_update_zipimporter_cache+s  rscCst||dS)N)rs)rjrkr<r<r=reKsrecCsdd}t|tj|ddS)NcSs |jdS)N)clear)r@rrr<r<r=2clear_and_remove_cached_zip_archive_directory_dataPszf_remove_and_clear_zip_directory_cache_data..clear_and_remove_cached_zip_archive_directory_data)rq)rsr_zip_directory_cache)rjrur<r<r=rhOsrhZ__pypy__cCsdd}t|tj|ddS)NcSs&|jtj||jtj||S)N)rtrrupdaterv)r@rrr<r<r=)replace_cached_zip_archive_directory_datafs zT_replace_zip_directory_cache_data..replace_cached_zip_archive_directory_data)rq)rsrrv)rjrxr<r<r=rges rgc Cs2yt||dWnttfk r(dSXdSdS)z%Is this string a valid Python script?execFTN)r\ SyntaxError TypeError)rTrr<r<r= is_pythonxs r}cCsJy(tj|dd}|jd}WdQRXWnttfk r@|SX|dkS)zCDetermine if the specified executable is a .sh (contains a #! line)zlatin-1)rrNz#!)rr,rr.r/)rBfpmagicr<r<r=is_shs rcCs tj|gS)z@Quote a command line argument according to Windows parsing rules) subprocess list2cmdline)rar<r<r= nt_quote_argsrcCsH|jds|jdrdSt||r&dS|jdrDd|jdjkSdS)zMIs this text, as a whole, a Python script? (as opposed to shell/bat/etc. z.pyz.pywTz#!rrF)rcr}r splitlinesrC)rrr<r<r=rs  r)rcGsdS)Nr<)rr<r<r=_chmodsrcCsRtjd||yt||Wn0tjk rL}ztjd|WYdd}~XnXdS)Nzchanging mode of %s to %ozchmod failed: %s)r rrr?error)r@rrr<r<r=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. r<)rWr<r<r=rszCommandSpec.bestcCstjjtj}tjjd|S)N__PYVENV_LAUNCHER__)r?r@rCrrBrr)rW_defaultr<r<r=_sys_executableszCommandSpec._sys_executablecCs:t||r|St|tr ||S|dkr0|jS|j|S)zg Construct a CommandSpec from a parameter to build_scripts, which may be None. N)rrfrom_environment from_string)rWparamr<r<r= from_params  zCommandSpec.from_paramcCs||jgS)N)r)rWr<r<r=rszCommandSpec.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)rWstringrr<r<r=rszCommandSpec.from_stringcCs8tj|j||_tj|}t|s4dg|jdd<dS)Nz-xr)rr_extract_optionsoptionsrrrL)rrcmdliner<r<r=install_optionss zCommandSpec.install_optionscCs:|djd}tj|}|r.|jdp0dnd}|jS)zH Extract any options from the first line of the script. rOrr4r)rr]matchgrouprR)Z orig_scriptfirstrrr<r<r=rs zCommandSpec._extract_optionscCs|j|t|jS)N)_renderrr)rr<r<r= as_headerszCommandSpec.as_headercCs6d}x,|D]$}|j|r |j|r |ddSq W|S)Nz"'r4r)rrc)itemZ_QUOTESqr<r<r= _strip_quotess  zCommandSpec._strip_quotescCs tjdd|D}d|dS)Ncss|]}tj|jVqdS)N)rrrR)rrr<r<r=rsz&CommandSpec._render..z#!rO)rr)rrr<r<r=rszCommandSpec._renderN)rrrrrrrrXrrrrrrrrrrrr<r<r<r=rs       rc@seZdZeddZdS)WindowsCommandSpecF)rN)rrrrrr<r<r<r=rsrc@seZdZdZejdjZeZ e dddZ e dddZ e dd d Z ed d Ze d dZe ddZe ddZe dddZdS)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)() ) NFcCs6tjdt|rtntj}|jd||}|j||S)Nz Use get_argsr)warningsrEasyInstallDeprecationWarningWindowsScriptWriterr~rget_script_headerr)rWrrBwininstwriterheaderr<r<r=get_script_args s zScriptWriter.get_script_argscCs$tjdtdd|rd}|j||S)NzUse get_headerr) stacklevelz python.exe)rrrr)rWrrBrr<r<r=r(szScriptWriter.get_script_headerc cs|dkr|j}t|j}xjdD]b}|d}xT|j|jD]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. NconsoleguiZ_scripts)rr) rrWrq get_entry_mapr_ensure_safe_namerr_get_script_args) rWrrrtype_rr eprrrr<r<r=r0s     zScriptWriter.get_argscCstjd|}|rtddS)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=rBs zScriptWriter._ensure_safe_namecCs tjdt|rtjS|jS)NzUse best)rrrrr)rWZ force_windowsr<r<r= get_writerKs zScriptWriter.get_writercCs.tjdkstjdkr&tjdkr&tjS|SdS)zD Select the best ScriptWriter for this environment. win32javarN)rrr?r _namerr)rWr<r<r=rQszScriptWriter.bestccs|||fVdS)Nr<)rWrr rrr<r<r=r[szScriptWriter._get_script_argsrcCs"|jjj|}|j||jS)z;Create a #! line, getting options (if any) from script_text)command_spec_classrrrr)rWrrBcmdr<r<r=r`s zScriptWriter.get_header)NF)NF)N)rN)rrrrrPrQrrrrrXrrrrrrrrrr<r<r<r=r~ s       r~c@sLeZdZeZeddZeddZeddZeddZ e d d Z d S) rcCstjdt|jS)NzUse best)rrrr)rWr<r<r=rks zWindowsScriptWriter.get_writercCs"tt|d}tjjdd}||S)zC Select the best ScriptWriter suitable for Windows )rBZnaturalZSETUPTOOLS_LAUNCHERrB)rWindowsExecutableLauncherWriterr?rr)rWZ writer_lookuplauncherr<r<r=rqs zWindowsScriptWriter.bestc #stddd|}|tjdjjdkrBdjft}tj|t dddd d dd g}|j ||j ||}fd d |D}|||d|fVdS)z For Windows, add a .py extensionz.pyaz.pyw)rrPATHEXT;zK{ext} not listed in PATHEXT; scripts will not be recognized as executables.z.pyz -script.pyz.pycz.pyoz.execsg|] }|qSr<r<)rrg)r r<r=rsz8WindowsScriptWriter._get_script_args..rN) rr?rrCrrrrr UserWarningrm_adjust_header) rWrr rrextrrrr<)r r=r~s   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). z pythonw.exez python.exer)rrepl)r[r\escape IGNORECASEsub _use_header)rWrZ orig_headerrZrZ pattern_ob new_headerr<r<r=rs z"WindowsScriptWriter._adjust_headercCs$|ddjd}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. rr4"rr)rRrrr)rZ clean_headerr<r<r=rs zWindowsScriptWriter._use_headerN) rrrrrrXrrrrrrr<r<r<r=rhs    rc@seZdZeddZdS)rc #s|dkrd}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|] }|qSr<r<)rrg)r r<r=rszDWindowsExecutableLauncherWriter._get_script_args..rz.exersz .exe.manifestN)rget_win_launcherr>load_launcher_manifest) rWrr rrZ launcher_typerrhdrrZm_namer<)r r=rs   z0WindowsExecutableLauncherWriter._get_script_argsN)rrrrXrr<r<r<r=rsrcCs2d|}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>rSr#)typeZ launcher_fnr<r<r=rs  rcCs0tjtd}tjr|tS|jdtSdS)Nzlauncher manifest.xmlzutf-8)r>r#rrPY2varsr)r manifestr<r<r=rs  rFcCstj|||S)N)rwr)r@ ignore_errorsonerrorr<r<r=rsrcCstjd}tj||S)N)r?umask)tmpr<r<r=rs  rcCs:ddl}tjj|jd}|tjd<tjj|tdS)Nr) rr?r@r=__path__rargvrr6)rZargv0r<r<r= bootstraps   rc sddlm}ddlmGfddd}|dkrBtjdd}t0|fddd g|tjdpfd|d |WdQRXdS) Nr)setup)r)cseZdZdZfddZdS)z-main..DistributionWithoutHelpCommandsrc s(tj|f||WdQRXdS)N) _patch_usage _show_help)rrkw)r)r<r=r sz8main..DistributionWithoutHelpCommands._show_helpN)rrr common_usagerr<)r)r<r=DistributionWithoutHelpCommandssrr4z-qr3z-v) script_argsrL distclass)rrZsetuptools.distr)rrr)rrrrr<)r)r=r6s    c #sLddl}tjdjfdd}|jj}||j_z dVWd||j_XdS)Nrze usage: %(script)s [options] requirement_or_url ... or: %(script)s --help csttjj|dS)N)script)rr?r@rE)rL)USAGEr<r= gen_usage sz_patch_usage..gen_usage)distutils.corerPrQrcorer)rrZsavedr<)rr=r s   rc@seZdZdZdS)rzuClass for warning about deprecations in EasyInstall in SetupTools. Not ignored by default, unlike DeprecationWarning.N)rrrrr<r<r<r=r$ sr)N)ry)N)rrrrrrdistutils.errorsrrrr distutils.command.installr r rr r Zdistutils.command.build_scriptsrrDrrr?rrwrUr$r[rr$rPrrr:rrrr sysconfigrrrrZsetuptools.externrZsetuptools.extern.six.movesrrrZsetuptools.sandboxrZsetuptools.py27compatrZsetuptools.commandrZsetuptools.archive_utilrZsetuptools.package_indexrrrrrZsetuptools.wheelr r>r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/Zpkg_resources.py31compatr __metaclass__filterwarnings PEP440Warning__all__r>r2rrHrLr<r3r2rrr5r7r4rTrrr]rdrrprsrerhbuiltin_module_namesrgr}rrrrr ImportErrorrrrZsys_executablerr~rrrrrrrrrr6rrrr<r<r<r= s            D vA))'l R    T^A