a [›ýfÄ\ã@sÒddlZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z m Z mZmZmZddlmZddlmZddlmZddlmZmZddlmZdd lmZdd lmZm Z dd l!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*m+Z+ee,ƒZ-ee.e/e e.d œdd„Z0e de efe de efdœdd„Z1e1ee e.dœdd„ƒZ2e e.ee.dœdd„Z3e e.ee.dœdd„Z4e e.eee.ee.fdœdd„Z5Gdd„dƒZ6Gd d!„d!ƒZ7Gd"d#„d#ƒZ8dS)$éN)Úcache_from_source) ÚAnyÚCallableÚDictÚIterableÚIteratorÚListÚOptionalÚSetÚTuple)Ú pkg_resources)Ú Distribution)ÚUninstallationError)Úget_bin_prefixÚ get_bin_user)ÚWINDOWS)Úegg_link_path_from_location)Ú getLoggerÚ indent_log)ÚaskÚdist_in_usersiteÚ dist_is_localÚis_localÚnormalize_pathÚrenamesÚrmtree)ÚAdjacentTempDirectoryÚ TempDirectory)ÚdistÚ script_nameÚis_guiÚreturncCspt|ƒrtƒ}ntƒ}tj ||¡}|g}trl| |d¡| |d¡|r^| |d¡n| |d¡|S)z‘Create the fully qualified name of the files created by {console,gui}_scripts for the given ``dist``. Returns the list of file names z.exez .exe.manifestz -script.pywz -script.py)rrrÚosÚpathÚjoinrÚappend)rrr Úbin_dirZexe_nameÚpaths_to_remove©r(úC/usr/lib/python3.9/site-packages/pip/_internal/req/req_uninstall.pyÚ _script_namessr*.)Úfnr!cs(t ˆ¡ttttdœ‡fdd„ ƒ}|S)N)ÚargsÚkwr!c?s6tƒ}ˆ|i|¤ŽD]}||vr| |¡|VqdS©N)ÚsetÚadd)r,r-ÚseenÚitem©r+r(r)Úunique5s  z_unique..unique)Ú functoolsÚwrapsrr)r+r4r(r3r)Ú_unique4sr7©rr!c cs8zt | d¡¡}Wn¤ty¸}zŒdj|d}z$t| d¡ƒ}|rL|dkrRtƒ‚Wn6tttfyŠd |j |j ¡}|d |¡7}Yn0|d |¡7}t |ƒ|‚WYd }~n d }~00|D]t}t j  |j|d ¡}|V| d ¡r¾t j  |¡\}} | d d …} t j  || d ¡}|Vt j  || d¡}|Vq¾d S)aÒ Yield all the uninstallation paths for dist based on RECORD-without-.py[co] Yield paths to all the files in RECORD. For each .py file in RECORD, add the .pyc and .pyo in the same directory. UninstallPathSet.add() takes care of the __pycache__ .py[co]. If RECORD is not found, raises UninstallationError, with possible information from the INSTALLER file. https://packaging.python.org/specifications/recording-installed-packages/ ZRECORDz/Cannot uninstall {dist}, RECORD file not found.)rZ INSTALLERZpipz{}=={}zZ You might be able to recover from this via: 'pip install --force-reinstall --no-deps {}'.z' Hint: The package was installed by {}.Nrú.pyéýÿÿÿú.pycú.pyo)ÚcsvÚreaderZget_metadata_linesÚFileNotFoundErrorÚformatÚnextÚ ValueErrorÚOSErrorÚ StopIterationÚ project_nameÚversionrr"r#r$ÚlocationÚendswithÚsplit) rÚrZmissing_record_exceptionÚmsgZ installerZdepÚrowr#Zdnr+Úbaser(r(r)Úuninstallation_paths@s6   ÿÿ    rN)Úpathsr!csJtjj‰tƒ}t|tdD]*‰t‡‡fdd„|Dƒƒ}|s| ˆ¡q|S)zÈCompact a path set to contain the minimal number of paths necessary to contain all paths in the set. If /a/path/ and /a/path/to/a/file.txt are both in the set, leave only the shorter path.©Úkeyc3s:|]2}ˆ | d¡¡o0ˆt| d¡ ˆ¡ƒˆkVqdS)Ú*N)Ú startswithÚrstripÚlen)Ú.0Z shortpath©r#Úsepr(r)Ú usþzcompact..)r"r#rXr/ÚsortedrUÚanyr0)rOZ short_pathsZ should_skipr(rWr)Úcompactlsý r\c sødd„|Dƒ}t|ƒ}tdd„| ¡Dƒtd}tƒ}ttdœdd„‰|D]˜‰t‡fd d „|DƒƒrfqJtƒ}tƒ}t ˆ¡D]B\‰}}| ‡‡‡fd d „|Dƒ¡| ‡‡‡fd d „|Dƒ¡q|||sJ|  |¡|  ˆtj ¡qJtt |j |ƒƒ|BS) z«Returns a set containing the paths that need to be renamed. This set may include directories when the original sequence of paths included every file on disk. cSsi|]}tj |¡|“qSr()r"r#Únormcase©rVÚpr(r(r)Ú …óz'compress_for_rename..cSsh|]}tj |¡d’qS)r)r"r#rIr^r(r(r)Ú ‡raz&compress_for_rename..rP)Úar!cWstj tjj|Ž¡Sr.)r"r#r]r$)rcr(r(r)Ú norm_joinŠsz&compress_for_rename..norm_joinc3s |]}tj ˆ¡ |¡VqdSr.)r"r#r]rS)rVÚw)Úrootr(r)rYŽraz&compress_for_rename..c3s|]}ˆˆˆ|ƒVqdSr.r()rVÚd©Údirnamerdrfr(r)rY•rac3s|]}ˆˆˆ|ƒVqdSr.r()rVÚfrhr(r)rY–ra)r/rZÚvaluesrUÚstrr[r"ÚwalkÚupdateÚdifference_updater0rXÚmapÚ __getitem__) rOZcase_mapZ remainingZ uncheckedZ wildcardsZ all_filesZ all_subdirsÚsubdirsÚfilesr(rhr)Úcompress_for_renames" rtc Csüt|ƒ}tƒ}tƒ}tƒ}|D]>}| d¡r.q| d¡s@d|vrR| tj |¡¡| |¡qtttjj|ƒƒ}t|ƒ}|D]d}t  |¡D]T\}} } | D]D} |  d¡r¨q˜tj  || ¡} tj  | ¡r˜tj | ¡|vr˜| | ¡q˜qŠq||dd„|DƒB}||fS)asReturns a tuple of 2 sets of which paths to display to user The first set contains paths that would be deleted. Files of a package are not added and the top-level directory of the package has a '*' added at the end - to signify that all it's contents are removed. The second set contains files that would have been skipped in the above folders. r;z __init__.pyú .dist-infocSsh|]}tj |d¡’qS)rR)r"r#r$)rVÚfolderr(r(r)rbÎraz.compress_for_output_listing..) r/rHr0r"r#rirpr]r\rmr$Úisfile) rOÚ will_removeÚ will_skipZfoldersrsr#Z_normcased_filesrvÚdirpathÚ_ZdirfilesÚfnameZfile_r(r(r)Úcompress_for_output_listing¡s2     ÿþr}c@s|eZdZdZddœdd„Zeedœdd„Zeedœd d „Zeedœd d „Zddœd d„Z ddœdd„Z e e dœdd„ƒZ dS)ÚStashedUninstallPathSetzWA set of file rename operations to stash files while tentatively uninstalling them.N©r!cCsi|_g|_dSr.)Ú _save_dirsÚ_moves©Úselfr(r(r)Ú__init__×sz StashedUninstallPathSet.__init__©r#r!cCsBz t|ƒ}Wnty(tdd}Yn0||jtj |¡<|jS)zStashes a directory. Directories are stashed adjacent to their original location if possible, or else moved/copied into the user's temp dir.Ú uninstall©Úkind)rrCrr€r"r#r])rƒr#Úsave_dirr(r(r)Ú_get_directory_stashßs   z,StashedUninstallPathSet._get_directory_stashcCs¸tj |¡}tj |¡d}}d}||krdz|j|}Wq„WntyNYn0tj |¡|}}q"tj |¡}tdd}||j|<tj ||¡}|r²|tjjkr²tj  |j|¡S|jS)z‚Stashes a file. If no root has been provided, one will be created for the directory in the user's temp directory.Nr†r‡) r"r#r]rir€ÚKeyErrorrÚrelpathÚcurdirr$)rƒr#ÚheadZold_headr‰rŒr(r(r)Ú_get_file_stashís"      z'StashedUninstallPathSet._get_file_stashcCsltj |¡otj |¡ }|r*| |¡}n | |¡}|j ||f¡|r^tj |¡r^t |¡t ||ƒ|S)zStashes the directory or file and returns its new location. Handle symlinks as files to avoid modifying the symlink targets. ) r"r#ÚisdirÚislinkrŠrrr%Úrmdirr)rƒr#Z path_is_dirÚnew_pathr(r(r)Ústashs    zStashedUninstallPathSet.stashcCs,|j ¡D]\}}| ¡q g|_i|_dS)z0Commits the uninstall by removing stashed files.N)r€ÚitemsZcleanupr)rƒr{r‰r(r(r)Úcommits zStashedUninstallPathSet.commitc CsÌ|jD]}tjdg|¢RŽq|jD]š\}}zTt d||¡tj |¡sTtj |¡r`t |¡ntj  |¡rtt |ƒt ||ƒWq$t y¼}z$t  d|¡t d|¡WYd}~q$d}~00q$| ¡dS)z2Undoes the uninstall by moving stashed files back.zMoving to %s from %szReplacing %s from %szFailed to restore %sz Exception: %sN)rÚloggerÚinfoÚdebugr"r#rwr‘ÚunlinkrrrrCÚerrorr–)rƒr_r“r#Úexr(r(r)Úrollback$s    $z StashedUninstallPathSet.rollbackcCs t|jƒSr.)Úboolrr‚r(r(r)Ú can_rollback7sz$StashedUninstallPathSet.can_rollback)Ú__name__Ú __module__Ú __qualname__Ú__doc__r„rlrŠrr”r–rÚpropertyržrŸr(r(r(r)r~Ósr~c@s¦eZdZdZeddœdd„Zeedœdd„Zeddœd d „Z eedd œd d „Z deeddœdd„Z eedœdd„Z ddœdd„Z ddœdd„Zeeddœdd„ƒZdS)ÚUninstallPathSetzMA set of file paths to be removed in the uninstallation of a requirement.Nr8cCs(tƒ|_tƒ|_i|_||_tƒ|_dSr.)r/rOÚ_refuseÚpthrr~Ú _moved_paths)rƒrr(r(r)r„@s zUninstallPathSet.__init__r…cCst|ƒS)zs Return True if the given path is one we are permitted to remove/modify, False otherwise. )r)rƒr#r(r(r)Ú _permittedGszUninstallPathSet._permittedcCs„tj |¡\}}tj t|ƒtj |¡¡}tj |¡s:dS| |¡rR|j  |¡n |j   |¡tj  |¡ddkr€|  t |ƒ¡dS)Nér9) r"r#rIr$rr]Úexistsr©rOr0r¦Úsplitextr)rƒr#rŽÚtailr(r(r)r0Os   zUninstallPathSet.add)Úpth_fileÚentryr!cCsLt|ƒ}| |¡r<||jvr*t|ƒ|j|<|j| |¡n |j |¡dSr.)rr©r§ÚUninstallPthEntriesr0r¦)rƒr®r¯r(r(r)Úadd_pthbs   zUninstallPathSet.add_pthF)Ú auto_confirmÚverboser!cCsÎ|jst d|jj¡dS|jjd|jj}t d|¡tƒz|sP| |¡r¬|j}t |jƒ}t t |ƒƒD]}|  |¡t  d|¡ql|j ¡D] }| ¡q’t d|¡Wdƒn1sÀ0YdS)z[Remove paths in ``self.paths`` with confirmation (unless ``auto_confirm`` is True).z7Can't uninstall '%s'. No files were found to uninstall.Nú-zUninstalling %s:zRemoving file or directory %szSuccessfully uninstalled %s)rOr—r˜rrErFrÚ_allowed_to_proceedr¨rtrZr\r”r³r§rkÚremove)rƒr²r³Zdist_name_versionZmovedZ for_renamer#r§r(r(r)r¶ks$þ    zUninstallPathSet.remove)r³r!cCs|tttddœdd„}|s*t|jƒ\}}nt|jƒ}tƒ}|d|ƒ|d|ƒ|d|jƒ|rn|dt|jƒƒtd d ƒd kS) z@Display which files would be deleted and prompt for confirmationN)rKrOr!cSsX|sdSt |¡tƒ,tt|ƒƒD]}t |¡q&Wdƒn1sJ0YdSr.)r—r˜rrZr\)rKrOr#r(r(r)Ú_display‹s  z6UninstallPathSet._allowed_to_proceed.._displayz Would remove:z+Would not remove (might be manually added):z%Would not remove (outside of prefix):zWill actually move:zProceed (Y/n)? )ÚyÚnÚr¹)rlrr}rOr/r¦rtr)rƒr³r·rxryr(r(r)rµˆs     z$UninstallPathSet._allowed_to_proceedrcCsR|jjst d|jj¡dSt d|jj¡|j ¡|j  ¡D] }| ¡q@dS)z1Rollback the changes previously made by remove().z'Can't roll back %s; was not uninstalledNzRolling back uninstall of %s) r¨rŸr—r›rrEr˜rr§rk)rƒr§r(r(r)r¤sþ zUninstallPathSet.rollbackcCs|j ¡dS)z?Remove temporary save dir: rollback will no longer be possible.N)r¨r–r‚r(r(r)r–±szUninstallPathSet.commitcsÆt|jƒ}t|ƒs.t d|j|tj¡||ƒS|dd„t  d¡t  d¡hDƒvrht d|j|¡||ƒS||ƒ}t |j ƒ}d  t  |j ¡¡}|jožtj |j¡}t|jddƒ}|r´|j d ¡r´|j |¡s´| |j¡| d ¡r | d ¡ ¡D]&}tj tj |j|¡¡} | | ¡qön| d ¡rØ| d ¡rD| d ¡‰ng‰‡fd d„| d ¡ ¡DƒD]J} tj |j| ¡} | | ¡| | d¡| | d¡| | d¡qdn$|rÎtd  |j ¡ƒ‚n |j d¡r$| |j¡tj |j¡d} tj tj |j¡d¡} | | d| ¡n´|rT|j d¡rTt |ƒD]} | | ¡q@n„|rÈt!|ƒ$} tj "|  #¡ $¡¡}Wdƒn1sŽ0Y| |¡tj tj |¡d¡} | | |j¡nt %d||j¡| d¡rL| &d¡rL| 'd¡D]P}t(|ƒrt)ƒ}nt*ƒ}| tj ||¡¡t+rú| tj ||¡d¡qúg}|j,dd}| -¡D]}| .t/||dƒ¡qd|j,dd}| -¡D]}| .t/||dƒ¡q’|D]}| |¡q°|S) Nz1Not uninstalling %s at %s, outside environment %scSsh|] }|r|’qSr(r(r^r(r(r)rbÁsþz-UninstallPathSet.from_dist..ZstdlibZ platstdlibzîs þz.UninstallPathSet.from_dist..r9r;r<z©Cannot uninstall {!r}. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.z.eggrªzeasy-install.pthz./ruz)Not sure how to uninstall: %s - Check: %sZscriptsz.batÚconsole_scripts)ÚgroupFÚ gui_scriptsT)0rrGrr—r˜rQÚsysÚprefixÚ sysconfigZget_pathrrEr@r Z to_filenameZegg_infor"r#r«ÚgetattrZ _providerrHr0Z has_metadataZ get_metadataÚ splitlinesÚnormpathr$rrIrir±rNÚopenr]ÚreadlineÚstripr™Zmetadata_isdirZmetadata_listdirrrrrZ get_entry_mapÚkeysÚextendr*)ÚclsrZ dist_pathr'Zdevelop_egg_linkZdevelop_egg_link_egg_infoZegg_info_existsZdistutils_egg_infoZinstalled_filer#Z top_level_pkgZeasy_install_eggZeasy_install_pthÚfhZ link_pointerZscriptr&Z_scripts_to_remover½Únamer¿Úsr(r»r)Ú from_distµs üþý  ÿÿ þ ý  ÿ      þ  ýÿ ÿ  4  ÿý     zUninstallPathSet.from_dist)FF)r r¡r¢r£r r„rlržr©r0r±r¶rµrr–Ú classmethodrÏr(r(r(r)r¥<s  r¥c@sHeZdZeddœdd„Zeddœdd„Zddœd d „Zedœd d „ZdS) r°N)r®r!cCs||_tƒ|_d|_dSr.)Úfiler/ÚentriesÚ _saved_lines)rƒr®r(r(r)r„CszUninstallPthEntries.__init__)r¯r!cCs<tj |¡}tr,tj |¡ds,| dd¡}|j |¡dS)Nrú\ú/)r"r#r]rÚ splitdriveÚreplacerÒr0)rƒr¯r(r(r)r0Hs  zUninstallPthEntries.addrc Cs2t d|j¡tj |j¡s.t d|j¡dSt|jdƒ}| ¡}||_ Wdƒn1s^0Yt dd„|Dƒƒr€d}nd}|r²|d  |  d ¡¡s²|d|  d ¡|d<|j D]<}z$t d |¡| ||  d ¡¡Wq¸tyòYq¸0q¸t|jd ƒ}| |¡Wdƒn1s$0YdS) NzRemoving pth entries from %s:z.Cannot remove entries from nonexistent file %sÚrbcss|]}d|vVqdS)s Nr()rVÚliner(r(r)rYbraz-UninstallPthEntries.remove..z Ú éÿÿÿÿzutf-8zRemoving entry: %sÚwb)r—r³rÑr"r#rwZwarningrÆÚ readlinesrÓr[rHÚencoderÒr¶rBÚ writelines)rƒrÌÚlinesZendliner¯r(r(r)r¶Ws($   zUninstallPthEntries.removecCsf|jdurt d|j¡dSt d|j¡t|jdƒ}| |j¡Wdƒn1sX0YdS)Nz.Cannot roll back changes to %s, none were madeFz!Rolling %s back to previous staterÜT)rÓr—r›rÑr™rÆrß)rƒrÌr(r(r)rrs *zUninstallPthEntries.rollback) r r¡r¢rlr„r0r¶ržrr(r(r(r)r°Bsr°)9r=r5r"rÀrÂÚimportlib.utilrÚtypingrrrrrrr r r Z pip._vendorr Zpip._vendor.pkg_resourcesr Zpip._internal.exceptionsrZpip._internal.locationsrrZpip._internal.utils.compatrZpip._internal.utils.egg_linkrZpip._internal.utils.loggingrrZpip._internal.utils.miscrrrrrrrZpip._internal.utils.temp_dirrrr r—rlržr*r7rNr\rtr}r~r¥r°r(r(r(r)Ús8 ,     $ ( +"$2i