3 eN @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.ddl/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6ddl/m7Z7m8Z8ddl9m:Z:ddl;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJdd l;Z;ejKde;jLddddddgZMddZNddZOdd ZPd!d"ZQd#d$ZRGd%dde,ZSd&d'ZTd(d)ZUd*d+ZVd,dZWd-dZXGd.ddeBZYGd/d0d0eYZZej[j\d1d2d3kreZZYd4d5Z]d6d7Z^d8d9Z_d:d;Z`dhdd?Zbd@dAZcdBejdkrecZendCdDZedidFdGZfdHdIZgdJdKZhdLdMZiyddNlmjZkWnelk r.dOdPZkYnXdQdRZjGdSdTdTemZnenjoZpGdUdVdVenZqGdWdXdXZrGdYdZdZerZsGd[d\d\esZterjuZuerjvZvd]d^Zwd_d`Zxdae^fdbdcZydddeZzGdfdgdge+Z{d S)ja) 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.pypa.io/en/latest/deprecated/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)Command) run_setup)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_cfgget_exe_prefixescCstjddkS)NP)structcalcsizer7r7E/tmp/pip-build-vlmub77e/setuptools/setuptools/command/easy_install.pyis_64bitJsr9cCsjtjj|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. r.)ospathexistshasattrr.normpathnormcase)p1p2Z both_existZ use_samefileZnorm_p1Znorm_p2r7r7r8r.NscCs |jdS)Nutf8)encode)sr7r7r8 _to_bytes^srEc Cs(y|jddStk r"dSXdS)NasciiTF)rC UnicodeError)rDr7r7r8isasciibs  rHcCstj|jjddS)N z; )textwrapdedentstripreplace)textr7r7r8 _one_linerjsrOc@seZdZdZdZdZdddddddddddddddddddddd@ddAejfgZdd dd dd0d3d9dddZ?ddZ@ddZAddZBddZCddZDddZEejdjFZGddZHeIeIddddZJeIdddZKddZLdS)r/z'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 installeduserz!install in user site-package '%s'cCs2tjdtd|_d|_|_d|_|_|_d|_ d|_ d|_ d|_ d|_ |_d|_|_|_d|_|_|_d|_|_|_d|_d|_d|_d|_d|_d|_d|_d|_d|_ t!j"rt!j#|_$t!j%|_&n d|_$d|_&d|_'d|_(d|_)|_*d|_+i|_,d|_-|j.j/|_/|j.j0||j.j1ddS)NzVeasy_install command is deprecated. Use build and pip and other standards-based tools.rr/)2warningswarnEasyInstallDeprecationWarningrzip_oklocal_snapshots_ok install_dir script_direxclude_scripts index_url find_linksbuild_directoryargsoptimizerecordrX always_copy multi_versionrzno_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_projects_dry_run distributionverbose_set_command_optionsget_option_dict)selfr7r7r8initialize_optionssJ     zeasy_install.initialize_optionscCs"dd|D}tt|j|dS)Ncss*|]"}tjj|stjj|r|VqdS)N)r:r;r<islink).0filenamer7r7r8 sz/easy_install.delete_blockers..)listmap _delete_path)rblockersZextant_blockersr7r7r8delete_blockersszeasy_install.delete_blockerscCsJtjd||jrdStjj|o.tjj| }|r8tntj}||dS)Nz Deleting %s) r infodry_runr:r;isdirrrmtreeunlink)rr;Zis_treeZremoverr7r7r8rs  zeasy_install._delete_pathcCs4djtj}td}d}t|jfttdS)zT Render the Setuptools version and installation details, then exit. z{}.{} setuptoolsz=setuptools {dist.version} from {dist.location} (Python {ver})N)formatsys version_infor!printlocals SystemExit)verdisttmplr7r7r8_render_versions  zeasy_install._render_versionc Cs|jo |jtjjd}tdd\}}|jj|jj|jj||dd|d|d||||t tddd |_ t j r|j |j d <|j|j d <n|jrtjd |j|j|j|jd d dd|jdkr|j|_|jdkrd|_|jdd"|jdd#|jr(|jr(|j|_|j|_|jdd$tttj}t|_ |j!dk rdd|j!jdD}xV|D]N}t"jj#|stjd|n,t||krt$|dn|j j%t|qpW|j&s|j'|j(pd|_(|j dd|_)x4|jt|jfD] }||j)kr|j)j*d|qW|j+dk rJdd|j+jdD}ndg}|j,dkrr|j-|j(|j)|d|_,t.|j)tj|_/|j0dk rt1|j0t2r|j0j|_0ng|_0|j3r|j,j4|j)tj|js|j,j5|j0|jdd%t1|j6t7s`y2t7|j6|_6d|j6ko"dkns.t8Wn.t8k r^} zt$d| WYdd} ~ XnX|j&rz|j9 rzt:d |j;st:d!g|_.sz1easy_install.finalize_options..,z"%s (in --site-dirs) does not existz$ (in --site-dirs) is not on sys.pathzhttps://pypi.org/simple/cSsg|] }|jqSr7)rL)rrDr7r7r8rCs*) 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_varsrrrrrr r_fix_install_dir_for_user_siteexpand_basedirs expand_dirs_expandrrrset_undefined_optionsrrrrr; get_site_dirs all_site_dirsrr:rrappendrzcheck_site_dirr shadow_pathinsertrr create_indexr# local_indexr isinstancestrrZscan_egg_linksadd_find_linksrint ValueErrorrrroutputs) rrrrr>rr\ path_itemrr{r7r7r8finalize_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:namerM select_scheme)rmsgZ scheme_namer7r7r8rjs z+easy_install._fix_install_dir_for_user_sitecCs\xV|D]N}t||}|dk rtjdks0tjdkrrjr@basenameZaltZuse_altr<r7r7r8r/sV             z!easy_install.check_pth_processingcCs\|j rN|jdrNx:|jdD],}|jd|r2q|j|||jd|qW|j|dS)z=Write all the scripts for `dist`, unless scripts are excludedscriptszscripts/N)rmetadata_isdirmetadata_listdirinstall_script get_metadatainstall_wrapper_scripts)rr script_namer7r7r8install_egg_scriptsSsz easy_install.install_egg_scriptscCs\tjj|rLxJtj|D].\}}}x"|D]}|jjtjj||q(WqWn |jj|dS)N)r:r;rwalkrrr&)rr;baserfilesrr7r7r8 add_outputas    zeasy_install.add_outputcCs|jrtd|fdS)NzjInvalid argument %r: you can't use filenames or URLs with --editable (except via the --find-links option).)rzr)rrr7r7r8 not_editableiszeasy_install.not_editablecCs<|js dStjjtjj|j|jr8td|j|jfdS)Nz2%r already exists in %s; can't do a checkout there)rzr:r;r<r&rkeyr)rrr7r7r8check_editableqs zeasy_install.check_editablec cs6tjdd}zt|VWdtjj|o.t|XdS)Nz easy_install-)r)tempfilemkdtemprr:r;r<r)rtmpdirr7r7r8_tmpdir{s zeasy_install._tmpdirFcCs|j}t|tsvt|rF|j||jj||}|jd|||dStj j |rn|j||jd|||dSt |}|j ||jj |||j|j|j |j}|dkrd|}|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)rVrr$rrPrdownload install_itemr:r;r<rrRZfetch_distributionrXrzrrr precedencer+process_distributionlocation)rrdepsrUdlrr r7r7r8r/s.         zeasy_install.easy_installcCs|p|j}|ptjj||k}|p,|jd }|pT|jdk oTtjjt|t|jk}|r| rx$|j|jD]}|j |krnPqnWd}t j dtjj ||r|j |||}x<|D]}|j|||qWn |j|g}|j||d|d|dk rx|D]}||kr|SqWdS)Nz.eggTz Processing %srrW)rr:r;r>endswithrrr project_namer\r rrC install_eggsr[egg_distribution)rrrXrUr]Zinstall_neededrdistsr7r7r8rYs.         zeasy_install.install_itemcCs@t|}x2tD]*}d|}t||dkrt||||qWdS)z=Sets the install directories by applying the install schemes.install_N)r r rr )rr schemerQattrnamer7r7r8r s  zeasy_install.select_schemecGs|j||jj|||j|jkr2|jj||jj||j|||j|j<tj |j ||f||j dr|j r|jj |jd| r|j rdS|dk r|j|jkrtjd|dS|dks||kr|j}tt|}tj d|ytgj|g|j|j}Wnbtk rD}ztt||WYdd}~Xn2tk rt}zt|j|WYdd}~XnX|js|jrx*|D]"}|j|jkr|j|jqWtj d|dS)Nzdependency_links.txtzSkipping dependencies for %szProcessing dependencies for %sz'Finished processing dependencies for %s) update_pthraddrrQremoverKrr rinstallation_report has_metadatarrget_metadata_linesrras_requirementr$rr(resolver/r)rr*reportr)r requirementrr]rZdistreqZdistrosr{r7r7r8r[sB             z!easy_install.process_distributioncCs2|jdk r|j S|jdr dS|jds.dSdS)Nz not-zip-safeTzzip-safeF)rrk)rrr7r7r8 should_unzips   zeasy_install.should_unzipcCstjj|j|j}tjj|r:d}tj||j|j||Stjj|rL|}nRtjj ||krftj |tj |}t |dkrtjj||d}tjj|r|}t |tj|||S)Nz<%r already exists in %s; build directory %s will not be keptr6r)r:r;r&rrQr<r rrr>rlistdirrr shutilmove)rr dist_filename setup_basedstr contentsr7r7r8 maybe_moves"       zeasy_install.maybe_movecCs0|jr dSx tjj|D]}|j|qWdS)N)r ScriptWriterbestget_args write_script)rrrr7r7r8rIsz$easy_install.install_wrapper_scriptscCsNt|j}t||}|r8|j|t}tj||}|j|t|ddS)z/Generate a legacy script wrapper and install itrmN) rrmis_python_script_load_templaterrz get_headerr}rE)rrrJ script_textdev_pathrZ is_scriptbodyr7r7r8rG"s   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)rMrdecode)rr Z raw_bytesr7r7r8r,s   zeasy_install._load_templatetc sjfdd|Dtjd|jtjjj|}j|jrLdSt }t |tjj |rptj |t |d|}|j|WdQRXt|d|dS)z1Write an executable file to the scripts directorycsg|]}tjjj|qSr7)r:r;r&r)rra)rr7r8r>sz-easy_install.write_script..zInstalling %s script to %sNr)i)rr rrr:r;r&rOr current_umaskr r<rr0r?chmod)rrJrxmodertargetmaskrjr7)rr8r};s   zeasy_install.write_scriptc CsX|j|j|jd}y||jd d}Wntk r>YnX|||gS|}tjj|rx|jd rxt |||j ntjj |rtjj |}|j |r|jr|dk r|j|||}tjj|d}tjj|s*ttjj|dd}|stdtjj |t|dkr"tdtjj ||d }|jrHtj|j||gS|j||SdS) N)z.eggz.exez.whlz.pyzsetup.pyrz"Couldn't find a setup script in %sr6zMultiple setup scripts in %sr) install_egg install_exe install_wheelrAKeyErrorr:r;isfiler_runpack_progressrabspath startswithrryr&r<rrrrzr rreport_editablebuild_and_install) rrrurUZ installer_mapZ install_distrv setup_scriptZsetupsr7r7r8raOsB     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_pathrr7r7r8rbs    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&rrCrrr rbr.rrr remove_treer<rrrrsrtcopytreerqmkpathunpack_and_compilecopy2r>update_dist_cachesr"rO)rrrU destinationrZnew_dist_is_zippedrjrVr7r7r8rsT               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)r`rplatformz.eggz.tmpzEGG-INFOzPKG-INFOr)zMetadata-Version: 1.0 target_versionz%s: %s _-rDcsg|]}tjj|dqS)r)r:r;r&)rr)rr7r8rsz,easy_install.install_exe..)rr)r1rr%r3rr:r;r&egg_namer\r r& _provider exe_to_eggr<r0r?itemsrMtitler1rrzr|r make_zipfilerrr) rrurUcfgrregg_tmpZ _egg_infoZpkg_infrjkvr7)rr8rs<      " 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.dllr6rz.pyzSCRIPTS/z.pthzWARNING: can't process %sr)rArrrr:r;r&r_r strip_modulesplitextrr r)srcrwrDoldnewpartsr^)r native_libsprefixes to_compile top_levelr7r8processs$      z(easy_install.exe_to_egg..processz.pydrr6z.pyzEGG-INFOrrz.txtr)rINrrr)rr)r2rrAr_rrrr:r;r&rZ write_stub byte_compileZwrite_safety_flagZ analyze_eggrr<r0r?r1) rrurrZstubsresrresourceZpyfiler txtrjr7)rrrrrr8rs6           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)rZ is_compatibleAssertionErrorr:r;r&rrrrr rrr rr<rrZinstall_as_eggrCr>rrOrb)r wheel_pathrUwheelrr7r7r8r$s.      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)srIr) rr_easy_install__mv_warningrrrrr;_easy_install__id_warningr\r`rr) rreqrwhatr Zegglocr rextrasr7r7r8rjRsz 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)NrI)r:r;r>rr@_easy_install__editable_msgr)rrrr>pythonr7r7r8rks zeasy_install.report_editablecCstjjdttjjdtt|}|jdkrNd|jd}|jdd|n|jdkrd|jdd|jrv|jdd t j d |t |ddd j |yt ||Wn8tk r}ztd |jdf|WYdd}~XnXdS) Nzdistutils.command.bdist_eggzdistutils.command.egg_inforrr6rrz-qz-nz Running %s %s zSetup script exited with %s)rmodules setdefaultrrrrrrr rrr&rrrr)rrrvrrr7r7r8rps$     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?))rSrTr:r;r>_set_fetcher_optionsrrr#rr\rr rrrr) rrrvrZdist_dirZall_eggseggsrQrr7r7r8rs$   zeasy_install.build_and_installc Csl|jjdj}d }i}x*|jD]\}}||kr4q"|d||<q"Wt|d}tjj|d }tj ||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. r/rrrrrr6)r/z setup.cfgN)rrrrr) rrcopyrdictr:r;r&rZ edit_config) rrMZei_optsZfetch_directivesZ fetch_optionsrQrsettingsZ cfg_filenamer7r7r8rs  z!easy_install._set_fetcher_optionsc Cs<|jdkrdSx\|j|jD]L}|j r6|j|jkr6qtjd||jj||j|jkr|jj|jqW|js|j|jjkrtjd|n2tjd||jj ||j|jkr|jj |j|j rdS|jj |jdkrdSt jj|jd}t jj|r t j|t|d}|j|jj|jdWdQRXdS)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.pthwtrI)rrQrr\r rrirpathsrhrrsaver:r;r&rrrr0r? make_relative)rrr\rrjr7r7r8rgs8           zeasy_install.update_pthcCstjd|||S)NzUnpacking %s to %s)r debug)rrrwr7r7r8rszeasy_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)r_rrrr)rrw)rto_chmodrr7r8pfs    z+easy_install.unpack_and_compile..pfimi)rrrr:statST_MODEr)rrrrrjrr7)rrrr8rs   zeasy_install.unpack_and_compilec Csjtjr dSddlm}z@tj|jd||dd|jd|jrT|||jd|jdWdtj|jXdS)Nr)rr6)rforcer) rdont_write_bytecodedistutils.utilrr rrrr)rrrr7r7r8rs 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.pypa.io/en/latest/deprecated/easy_install.html#custom-installation-locations Please make the appropriate changes for your system and try again. cCsh|js dSttjjd}xH|jjD]:\}}|j|r&tjj| r&|j d|tj |dq&WdS)zCreate directories under ~.N~zos.makedirs('%s', 0o700)i) rrr:r;rrrrr debug_printr+)rhomer r;r7r7r8r)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)NrrMr)rr)get_finalized_commandrrrr r3r:r DEFAULT_SCHEMErrr rrr;r)rrrrerrrr7r7r8r?s         zeasy_install._expand)rPNrQ)rRrSrT)rUrVrW)rXrYrZ)r[r\r])r^rDr_)r`rarb)rcrdre)rfrgrh)rirjrk)rlrmrn)rorprq)rrNrs)rtrurv)rwrxry)rzr{r|)r}r~r)rrr)rrr)rNr)rNr)T)F)F)T)N)r)M__name__ __module__ __qualname____doc__ descriptionZcommand_consumes_argumentsrr user_optionsboolean_options negative_optrrrrr staticmethodrrrrrrr r(rrrJrKlstripr7r9r:r.r/rKrOrPrR contextlibcontextmanagerrVr/rYr r[rqryrIrGrr}rarbrrrrrrrjrrrrrrgrrrrLr4rrr rrr7r7r7r8r/ns 5    -    ;  ! $ (  3 6.5   )   cCs tjjddjtj}td|S)Nr*r)r:r2r3rpathsepfilter)rr7r7r8 _pythonpathVsrc s|gjttjg}tjtjkr0|jtjx|D]}|s@q6tjdkrbjtjj |ddnVtj dkrjtjj |ddj tj dtjj |ddgnj|tjj |ddgtjd krq6d |krq6tj jd }|sq6tjj |d d dj tj d}j|q6Wtdtdf}jfdd|DtjrFjtjtjtjtjWdQRXtttS)z& Return a list of 'site' dirs os2emxriscosLibz site-packagesrlibz python{}.{}z site-pythondarwinzPython.frameworkHOMELibraryPythonz{}.{}purelibplatlibc3s|]}|kr|VqdS)Nr7)rrD)sitedirsr7r8rsz get_site_dirs..N)rr)extendrrrrrrr:r;r&seprrr2r3rrrrrsuppressAttributeErrorgetsitepackagesrrr)rrrZhome_spZ lib_pathsr7)rr8r[sV            rccsi}x|D]}t|}||kr q d||<tjj|s6q tj|}||fVx|D]}|jds`qP|dkrjqPttjj||}tt |}|j xT|D]L}|j drqt|j }||krqd||<tjj|sq|tj|fVqWqPWq WdS)zBYield sys.path directories that might contain "old-style" packagesr6z.ptheasy-install.pthsetuptools.pthimportN)rr ) rr:r;rrrr_r0r&rrr1rrstrip)inputsseenr>rNr rjlinesliner7r7r8 expand_pathss8           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  zdddddg}tj|}zx|jD]}|j}|jd}t|d kr|d d kr|d jd r|jddj|dd dfPt|d ks&|jd rq&|jdrq&|dj dkr&|j |j }xDt |D]8}|j jdd}|jds|jd|d|fdfqWq&WWd|jXdd|D}|j|j|S) z4Get exe->egg path translations for a given .exe filePURELIB/rPLATLIB/pywin32_system32PLATLIB/SCRIPTS/EGG-INFO/scripts/DATA/lib/site-packagesrrrzPKG-INFOr6z .egg-inforNz EGG-INFO/z.pthz -nspkg.pthPURELIBPLATLIB\r z%s/%s/cSsg|]\}}|j|fqSr7)rA)rrayr7r7r8rsz$get_exe_prefixes..)r+r)r,r)r-r)r.r/)r0r)r1r2)rZipFileinfolistrrrr_rr&upperrrrrLrMrrr1sortreverse)Z exe_filenamerrSrr rrxpthr7r7r8r2s:    & c@sTeZdZdZdZffddZddZddZed d Z d d Z d dZ ddZ dS)r0z)A .pth file with Distribution paths in itFcCsp||_ttt||_ttjj|j|_|j t j |gddx(t |j D]}tt|jt|dqNWdS)NT)rrrrrr:r;r>basedir_loadr#__init__rrrhr")rrrr;r7r7r8r="szPthDistributions.__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) NFrtr T#r6rr)rrfromkeysrr:r;rrr0rr rrLrr&r;r<popdirtyr1)rZ saw_importr rjrr;r7r7r8r<+s2        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 %srIrzDeleting empty %sF)rBrrrrr rr _wrap_linesr&r:r;rrr0r?r<)rZ rel_pathsrdatarjr7r7r8rJs   zPthDistributions.savecCs|S)Nr7)rr7r7r8rC`szPthDistributions._wrap_linescCsN|j|jko$|j|jkp$|jtjk}|r>|jj|jd|_tj||dS)z"Add `dist` to the distribution mapTN) r\rrr:getcwdrrBr#rh)rrnew_pathr7r7r8rhds  zPthDistributions.addcCs6x$|j|jkr$|jj|jd|_qWtj||dS)z'Remove `dist` from the distribution mapTN)r\rrirBr#)rrr7r7r8rirs zPthDistributions.removecCstjjt|\}}t|j}|g}tjdkr2dp6tj}xVt||kr||jkrn|jtj |j |j |Stjj|\}}|j|q:W|SdS)Nr) r:r;rrrr;altseprrcurdirr9r&)rr;npathlastZbaselenrrr7r7r8rys    zPthDistributions.make_relativeN) rrrrrBr=r<rrrCrhrirr7r7r7r8r0s  c@s(eZdZeddZedZedZdS)RewritePthDistributionsccs(|jVx|D] }|VqW|jVdS)N)preludepostlude)clsrrr7r7r8rCs  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 classmethodrCrOrLrMr7r7r7r8rKs  rKZSETUPTOOLS_SYS_PATH_TECHNIQUErawZrewritecCs ttjtrtStjtjjS)z_ Return a regular expression based on first_line_re suitable for matching strings. )rrpatternrrecompilerr7r7r7r8_first_line_res rTcCs\|tjtjgkr.tjdkr.t|tj||Stj\}}}|d|dd||ffdS)Nr rr6z %s %s) r:rrir rrS_IWRITErr8)funcargexcetZevrr7r7r8 auto_chmods  rZcCs.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_pathr7r7r8rs <  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. r6r)rrrr:rr)r`cacheresult prefix_lenpnpr7r7r8"_collect_zipimporter_cache_entries s   rfcCsDx>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)rf)r`raupdaterrd old_entryZ new_entryr7r7r8_update_zipimporter_caches  ricCst||dS)N)ri)r`rar7r7r8r[>sr[cCsdd}t|tj|ddS)NcSs |jdS)N)clear)r;rhr7r7r82clear_and_remove_cached_zip_archive_directory_dataCszf_remove_and_clear_zip_directory_cache_data..clear_and_remove_cached_zip_archive_directory_data)rg)rir_zip_directory_cache)r`rkr7r7r8r^Bsr^Z__pypy__cCsdd}t|tj|ddS)NcSs&|jtj||jtj||S)N)rjrrupdaterl)r;rhr7r7r8)replace_cached_zip_archive_directory_dataYs zT_replace_zip_directory_cache_data..replace_cached_zip_archive_directory_data)rg)rirrl)r`rnr7r7r8r]Xs r]c Cs2yt||dWnttfk r(dSXdSdS)z%Is this string a valid Python script?execFTN)rS SyntaxError TypeError)rNrr7r7r8 is_pythonks rscCsJy(tj|dd}|jd}WdQRXWnttfk r@|SX|dkS)zCDetermine if the specified executable is a .sh (contains a #! line)zlatin-1)encodingrNz#!)r"r0rr,r-)r@fpmagicr7r7r8is_shus rwcCs tj|gS)z@Quote a command line argument according to Windows parsing rules) subprocess list2cmdline)rWr7r7r8 nt_quote_argsrzcCsH|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)r_rsr splitlinesrA)rrr7r7r8r~s  r~)rcGsdS)Nr7)rr7r7r8_chmodsr|cCsRtjd||yt||Wn0tjk rL}ztjd|WYdd}~XnXdS)Nzchanging mode of %s to %ozchmod failed: %s)r rr|r:error)r;rr{r7r7r8rs 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. r7)rNr7r7r8r{szCommandSpec.bestcCstjjtj}tjjd|S)N__PYVENV_LAUNCHER__)r:r;r>rr@r2r3)rN_defaultr7r7r8_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)rNparamr7r7r8 from_params  zCommandSpec.from_paramcCs||jgS)N)r)rNr7r7r8rszCommandSpec.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)rNstringrr7r7r8rszCommandSpec.from_stringcCs8tj|j||_tj|}t|s4dg|jdd<dS)Nz-xr)rr_extract_optionsoptionsrxryrH)rrcmdliner7r7r8install_optionss zCommandSpec.install_optionscCs:|djd}tj|}|r.|jdp0dnd}|jS)zH Extract any options from the first line of the script. rIrr6r)r{rTmatchgrouprL)Z orig_scriptfirstrrr7r7r8rs zCommandSpec._extract_optionscCs|j|t|jS)N)_renderrr)rr7r7r8 as_headerszCommandSpec.as_headercCs6d}x,|D]$}|j|r |j|r |ddSq W|S)Nz"'r6r)rr_)itemZ_QUOTESqr7r7r8 _strip_quotess  zCommandSpec._strip_quotescCs tjdd|D}d|dS)Ncss|]}tj|jVqdS)N)r~rrL)rrr7r7r8rsz&CommandSpec._render..z#!rI)rxry)rrr7r7r8rszCommandSpec._renderN)rrrrrrrrOr{rrrrrrrrrrr7r7r7r8r~s       r~c@seZdZeddZdS)WindowsCommandSpecF)rN)rrrrrr7r7r7r8rsrc@seZdZdZejdjZeZ e dddZ e dddZ e dd d Z ed d Ze d dZe ddZe ddZe dddZdS)rzz` Encapsulates behavior around writing entry point scripts for console and gui apps. aJ # EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r import re import sys # for compatibility with easy_install; see #2198 __requires__ = %(spec)r try: from importlib.metadata import distribution except ImportError: try: from importlib_metadata import distribution except ImportError: from pkg_resources import load_entry_point def importlib_load_entry_point(spec, group, name): dist_name, _, _ = spec.partition('==') matches = ( entry_point for entry_point in distribution(dist_name).entry_points if entry_point.group == group and entry_point.name == name ) return next(matches).load() globals().setdefault('load_entry_point', importlib_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)rrrWindowsScriptWriterrzr{get_script_headerr|)rNrr@wininstwriterheaderr7r7r8get_script_args(s zScriptWriter.get_script_argscCs$tjdtdd|rd}|j||S)NzUse get_headerr) stacklevelz python.exe)rrrr)rNrr@rr7r7r8r0s  zScriptWriter.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) rrrm get_entry_mapr_ensure_safe_nametemplater_get_script_args) rNrrrtype_rr eprrrr7r7r8r|9s     zScriptWriter.get_argscCstjd|}|rtddS)z? Prevent paths in *_scripts entry point names. z[\\/]z+Path separators not allowed in script namesN)rRsearchr)r Z has_path_sepr7r7r8rKs zScriptWriter._ensure_safe_namecCs tjdt|rtjS|jS)NzUse best)rrrrr{)rNZ force_windowsr7r7r8 get_writerTs zScriptWriter.get_writercCs.tjdkstjdkr&tjdkr&tjS|SdS)zD Select the best ScriptWriter for this environment. win32javar N)rrr:r _namerr{)rNr7r7r8r{ZszScriptWriter.bestccs|||fVdS)Nr7)rNrr rrr7r7r8rdszScriptWriter._get_script_argsrcCs"|jjj|}|j||jS)z;Create a #! line, getting options (if any) from script_text)command_spec_classr{rrr)rNrr@cmdr7r7r8ris zScriptWriter.get_header)NF)NF)N)rN)rrrrrJrKrrr~rrOrrr|rrrr{rrr7r7r7r8rzs !      rzc@sLeZdZeZeddZeddZeddZeddZ e d d Z d S) rcCstjdt|jS)NzUse best)rrrr{)rNr7r7r8rts zWindowsScriptWriter.get_writercCs"tt|d}tjjdd}||S)zC Select the best ScriptWriter suitable for Windows )r@ZnaturalZSETUPTOOLS_LAUNCHERr@)rWindowsExecutableLauncherWriterr:r2r3)rNZ writer_lookuplauncherr7r7r8r{zs 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|] }|qSr7r7)rra)r r7r8rsz8WindowsScriptWriter._get_script_args..rN) rr:r2rArrrrr UserWarningri_adjust_header) rNrr rrextr rrr7)r r8rs   z$WindowsScriptWriter._get_script_argscCsNd}d}|dkr||}}tjtj|tj}|j||d}|j|rJ|S|S)z Make sure 'pythonw' is used for gui and 'python' is used for console (regardless of what sys.executable is). z pythonw.exez python.exer)rrepl)rRrSescape IGNORECASEsub _use_header)rNrZ orig_headerrQrZ pattern_ob new_headerr7r7r8rs 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. rr6"rr)rLrrr)rZ clean_headerr7r7r8rs zWindowsScriptWriter._use_headerN) rrrrrrOrr{rrrrr7r7r7r8rqs    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|] }|qSr7r7)rra)r r7r8rszDWindowsExecutableLauncherWriter._get_script_args..rz.exermz .exe.manifestN)rget_win_launcherr9load_launcher_manifest) rNrr rrZ launcher_typerrhdrrZm_namer7)r r8rs   z0WindowsExecutableLauncherWriter._get_script_argsN)rrrrOrr7r7r7r8rsrcCsJd|}tr4tdkr&|jdd}q@|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.exez win-arm64.z-arm64.z-64.z-32.r)r9rrMr)typeZ launcher_fnr7r7r8rs  rcCstjtd}|jdtS)Nzlauncher manifest.xmlzutf-8) pkg_resourcesrrrvars)r manifestr7r7r8rs rFcCstj|||S)N)rsr)r; ignore_errorsonerrorr7r7r8rsrcCstjd}tj||S)N)r:umask)tmpr7r7r8rs  rc@seZdZdZdS)rzF Warning for EasyInstall deprecations, bypassing suppression. N)rrrrr7r7r7r8rsr)N)ro)|rrrrrrZdistutils.errorsrrrr distutils.command.installr r rr r Zdistutils.command.build_scriptsrrBrrr:rrsrSrrRrr#rJrrr5rrxrr"r sysconfigrrrrrZsetuptools.sandboxrZsetuptools.commandrZsetuptools.archive_utilrZsetuptools.package_indexrrrrrZsetuptools.wheelrrrrrr r!r"r#r$r%r&r'r(r)r*r+filterwarnings PEP440Warning__all__r9r.rErHrOr/rrrr1r2r0rKr2r3rTrZrrfrir[r^builtin_module_namesr]rsrwrzr~rr| ImportErrorrr~rZsys_executablerrzrrrrrrrrrr7r7r7r8 s          DqF.)%l  R    TtA