3 ]@szddlmZddlmZddlmZddlZddlZddlm Z ddlm Z ddl m Z ddl mZmZmZmZmZdd lmZmZmZmZmZmZmZmZmZmZdd lmZdd l m!Z!m"Z"m#Z#m$Z$dd l%m&Z&dd l'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ej/e0Z1Gddde2Z3Gddde2Z4ddZ5Gddde4Z6Gddde4Z7Gddde4Z8Gddde2Z9dS))absolute_import) defaultdict)chainN) pkg_resources)requests) expanduser) is_file_url is_dir_url is_vcs_url url_to_path unpack_url) InstallationErrorBestVersionAlreadyInstalledDistributionNotFoundPreviousBuildDirError HashError HashErrors HashUnpinnedDirectoryUrlHashUnsupportedVcsHashUnsupportedUnsupportedPythonVersion)InstallRequirement) display_pathdist_in_usersite ensure_dirnormalize_path) MissingHashes) indent_log)check_dist_requires_python)vcs)Wheelc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) RequirementscCsg|_i|_dS)N)_keys_dict)selfr%./tmp/pip-build-8jg9gmni/pip/pip/req/req_set.py__init__!szRequirements.__init__cCs|jS)N)r")r$r%r%r&keys%szRequirements.keyscsfddjDS)Ncsg|]}j|qSr%)r#).0key)r$r%r& )sz'Requirements.values..)r")r$r%)r$r&values(szRequirements.valuescCs ||jkS)N)r")r$itemr%r%r& __contains__+szRequirements.__contains__cCs$||jkr|jj|||j|<dS)N)r"appendr#)r$r*valuer%r%r& __setitem__.s  zRequirements.__setitem__cCs |j|S)N)r#)r$r*r%r%r& __getitem__3szRequirements.__getitem__cs$fddjD}ddj|S)Ncs$g|]}dt|t|fqS)z%s: %s)repr)r)k)r$r%r&r+7sz)Requirements.__repr__..zRequirements({%s})z, )r(join)r$r,r%)r$r&__repr__6szRequirements.__repr__N) __name__ __module__ __qualname__r'r(r,r.r1r2r6r%r%r%r&r!sr!c@s(eZdZdZddZddZddZdS) DistAbstractionatAbstracts out the wheel vs non-wheel prepare_files logic. The requirements for anything installable are as follows: - we must be able to determine the requirement name (or we can't correctly handle the non-upgrade case). - we must be able to generate a list of run-time dependencies without installing any additional packages (or we would have to either burn time by doing temporary isolated installs or alternatively violate pips 'don't start installing unless all requirements are available' rule - neither of which are desirable). - for packages with setup requirements, we must also be able to determine their requirements without installing additional packages (for the same reason as run-time dependencies) - we must be able to create a Distribution object exposing the above metadata. cCs ||_dS)N)req_to_install)r$r;r%r%r&r'NszDistAbstraction.__init__cCst|jdS)z Return a setuptools Dist object.N)NotImplementedErrordist)r$finderr%r%r&r=QszDistAbstraction.distcCst|jdS)z3Ensure that we can get a Dist for this requirement.N)r<r=)r$r%r%r& prep_for_distUszDistAbstraction.prep_for_distN)r7r8r9__doc__r'r=r?r%r%r%r&r:;sr:cCs0|jrt|S|jr$|jjr$t|St|SdS)zFactory to make an abstract dist object. Preconditions: Either an editable req with a source_dir, or satisfied_by or a wheel link, or a non-editable req with a source_dir. :return: A concrete DistAbstraction. N)editableIsSDistlinkis_wheelIsWheel)r;r%r%r&make_abstract_distZs rFc@seZdZddZddZdS)rEcCsttj|jjdS)Nr)listrfind_distributionsr; source_dir)r$r>r%r%r&r=lsz IsWheel.distcCsdS)Nr%)r$r%r%r&r?pszIsWheel.prep_for_distN)r7r8r9r=r?r%r%r%r&rEjsrEc@seZdZddZddZdS)rBcCs(|jj}|jdr$|j|jd|S)Nzdependency_links.txt)r;get_dist has_metadataadd_dependency_linksget_metadata_lines)r$r>r=r%r%r&r=ws    z IsSDist.distcCs|jj|jjdS)N)r; run_egg_infoassert_source_matches_version)r$r%r%r&r?s zIsSDist.prep_for_distN)r7r8r9r=r?r%r%r%r&rBus rBc@seZdZddZddZdS) InstalledcCs|jjS)N)r; satisfied_by)r$r>r%r%r&r=szInstalled.distcCsdS)Nr%)r$r%r%r&r?szInstalled.prep_for_distN)r7r8r9r=r?r%r%r%r&rPsrPc@seZdZd$ddZddZdd Zd%d d Zd d ZeddZ eddZ ddZ d&ddZ ddZ ddZddZd'ddZddZd d!Zffd"d#ZdS)(RequirementSetFNTcCs| dkrtd||_||_||_||_||_||_| |_t|_ i|_ g|_ | |_ ||_ g|_g|_g|_||_| |_||_| |_| |_||_|rt|}||_||_||_tt|_dS)a3Create a RequirementSet. :param wheel_download_dir: Where still-packed .whl files should be written to. If None they are written to the download_dir parameter. Separate to download_dir to permit only keeping wheel archives for pip wheel. :param download_dir: Where still packed archives should be written to. If None they are not saved, and are deleted immediately after unpacking. :param wheel_cache: The pip wheel cache, for passing to InstallRequirement. Nz?RequirementSet() missing 1 required keyword argument: 'session') TypeError build_dirsrc_dir download_dirupgradeupgrade_strategyignore_installedforce_reinstallr! requirementsrequirement_aliasesunnamed_requirementsignore_dependenciesignore_requires_pythonsuccessfully_downloadedsuccessfully_installedreqs_to_cleanupas_egg use_user_site target_dirsession pycompileisolatedrwheel_download_dir _wheel_cacherequire_hashesrrG _dependencies)r$rTrUrVrWrXrYrcrer^rZrdrfrgrhri wheel_cacherkr_r%r%r&r's<zRequirementSet.__init__cCs8dd|jjD}|jddddjdd|DS)NcSsg|]}|js|qSr%) comes_from)r)reqr%r%r&r+sz*RequirementSet.__str__..cSs |jjS)N)namelower)ror%r%r&sz(RequirementSet.__str__..)r* cSsg|]}t|jqSr%)strro)r)ror%r%r&r+s)r[r,sortr5)r$reqsr%r%r&__str__szRequirementSet.__str__cCsNdd|jjD}|jddddjdd|D}d|jjt||fS) NcSsg|]}|qSr%r%)r)ror%r%r&r+sz+RequirementSet.__repr__..cSs |jjS)N)rprq)ror%r%r&rrsz)RequirementSet.__repr__..)r*z, cSsg|]}t|jqSr%)rtro)r)ror%r%r&r+sz"<%s object; %d requirement(s): %s>)r[r,rur5 __class__r7len)r$rvreqs_strr%r%r&r6s zRequirementSet.__repr__c Cs|j}|j|s&tjd|j|jgS|jrV|jjrVt|jj}|j sVt d|j|j |_ |j |_ |j |_ |j|_|dk|_|s|jj||gSy|j|}Wntk rd}YnX|dko|o|j o|j|jko|jj|jjk rt d|||f|s8||j|<|j|kr0||j|j<|g}ng}|j r|jr|jr|jol|jj|jjk r|jj|t d|d|_ttt|jj t|j|_tj!d||j|g}|}|r|j|}|j"|j||SdS)a'Add install_req as a requirement to install. :param parent_req_name: The name of the requirement that needed this added. The name is used because when multiple unnamed requirements resolve to the same name, we could otherwise end up with dependency links that point outside the Requirements set. parent_req must already be added. Note that None implies that this is a user supplied requirement, vs an inferred one. :param extras_requested: an iterable of extras used to evaluate the environement markers. :return: Additional requirements to scan. That is either [] if the requirement is not applicable, or [install_req] if the requirement is applicable and has just been added. z6Ignoring %s: markers '%s' don't match your environmentz-%s is not a supported wheel on this platform.Nz5Double requirement given: %s (already in %s, name=%r)zhCould not satisfy constraints for '%s': installation from path or url cannot be constrained to a versionFzSetting %s extras to: %s)#rp match_markersloggerwarningmarkersrCrDr filename supportedr rcrdrerg is_directr]r/get_requirementKeyError constraintextrasro specifierr[rqr\pathrbtuplesortedsetuniondebugrl) r$ install_reqparent_req_nameextras_requestedrpwheel existing_reqresult parent_reqr%r%r&add_requirementsp             zRequirementSet.add_requirementcCsF|j}||jkr |j|j s>||jkrB|j|j|j rBdSdS)NTF)rqr[rr\)r$ project_namerpr%r%r&has_requirement3s  zRequirementSet.has_requirementcCstdd|jjDp|jS)Ncss|]}|js|VqdS)N)r)r)ror%r%r& >sz2RequirementSet.has_requirements..)rGr[r,r])r$r%r%r&has_requirements<szRequirementSet.has_requirementscCsD|jr@t|j|_tjj|jr$dStjdtdt|jdS)NTz!Could not find download directoryz0Could not find or access download directory '%s'F) rVrosrexistsr|criticalr r)r$r%r%r& is_downloadAs  zRequirementSet.is_downloadcCsTxB||jfD]2}||jkr&|j|S||jkr|j|j|SqWtd|dS)NzNo project with the name %r)rqr[r\r)r$rrpr%r%r&rNs    zRequirementSet.get_requirementcCs4x.|jjD] }|jrq |j|d|jq WdS)N) auto_confirm)r[r,r uninstallcommit_uninstall)r$rror%r%r&rVs  zRequirementSet.uninstallcCs|jrt|j|j|jj}|jp6tdd|D}|rJ|jrJtdg}t }xdt ||D]V}y|j |j ||||j dWq`tk r}z||_|j|WYdd}~Xq`Xq`W|r|dS)zY Prepare process. Create temp directories, download and/or unpack files. css|] }|jVqdS)N)has_hash_options)r)ror%r%r&risz/RequirementSet.prepare_files..z--egg is not allowed with --require-hashes mode, since it delegates dependency resolution to setuptools and could thus result in installation of unhashed packages.)rkr^N)rirr]r[r,rkanyrcr rrextend _prepare_filer^rror/)r$r> root_reqsrkdiscovered_reqs hash_errorsroexcr%r%r& prepare_files]s,   zRequirementSet.prepare_filescCs |jo|jdkp|jdko|jS)Neagerzonly-if-needed)rWrXr)r$ror%r%r&_is_upgrade_alloweds z"RequirementSet._is_upgrade_allowedc Cs|j|jr|j|}d}|r|jp*|jshy|j||Wn*tk rTd}Yntk rfYnX|s|jo|t |j s|j|_ d|_|rd}n|j dkrd}nd}|SdSdS)aCheck if req_to_install should be skipped. This will check if the req is installed, and whether we should upgrade or reinstall it, taking into account all the relevant user options. After calling this req_to_install will only have satisfied_by set to None if the req_to_install is to be upgraded/reinstalled etc. Any other value will be a dist recording the current thing installed that satisfies the requirement. Note that for vcs urls and the like we can't assess skipping in this routine - we simply identify that we need to pull the thing down, then later on it is pulled down and introspected to assess upgrade/ reinstalls etc. :return: A text reason for why it was skipped, or None. FTNzalready up-to-datezonly-if-neededz%not upgraded as not directly requiredzalready satisfied) check_if_existsrQrrZrCfind_requirementrrrdrconflicts_withrX)r$r;r>upgrade_allowedbest_installed skip_reasonr%r%r&_check_skip_installeds2     z$RequirementSet._check_skip_installedc(sjs jrgSd_jr*tjdnjdks8tjsJj|}jrx|dk shtdjftjd|n<j rj j dkrt j j }tjdt |n tjdtjr |rtd jjjj t}|jjrjjjn"jrD|r8tjd t}njjtjjtjjj d r|t!d j fj"|j#|j stj }|rt$|rt%nt&|rt'|rt(j) rj* rt+j,| d } |r| rt-} yZj} d} j j.r4j/r4j/} j j.rN| rJd} nd} t0j j | | j1| dWnHt2j3k r} z(tj4d| td| j fWYdd} ~ XnXt}|jjrj j t5j6krjjjsjjrBj7sjr6j8o"t9j s.j_:d_n tjd|j;|} y t<| WnHt=k r}z*j>rtj?|j@dn jAWYdd}~XnXgfdd}jBjCsЈjDd|sbjErtjddjjEtFtGjEtG| jE}x|D]}tj?d| |qWtFtG| jEtGjE@}x | jH|D]}|||dqLWjIjJj rj rjKjJWdQRXS)zxPrepare a single requirements file. :return: A list of additional InstallRequirements to also install. Tz Obtaining %sNzP_check_skip_installed returned None but req_to_install.satisfied_by is set to %rzRequirement %s: %sfilez Processing %sz Collecting %szoThe editable requirement %s cannot be installed when requiring hashes, because there is no single file to hash.zSince it is already installed, we are trusting this package without checking its hash. To ensure a completely repeatable environment, install into an empty virtualenv.zsetup.pyzpip can't proceed with requirements '%s' due to a pre-existing build directory (%s). This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.)trust_internetF)rfhashesz4Could not install requirement %s because of error %szDCould not install requirement %s because of HTTP error %s for URL %sz.add_reqz!Installing extra requirements: %r,z"%s does not provide the extra '%s')r)LrpreparedrAr|inforQAssertionErrorrYrrCschemer urlrrr ensure_has_source_dirrUupdate_editablerrFr?archiverVrrrPrTrrrr5rIr populate_linkrr rrr r original_link is_pinnedrrrrDrir rfr HTTPErrorrr all_schemesrWrdrrr=rrr_r}argsremove_temporary_sourcerrprrrrrequiresrbr/r`)r$r>r;rkr^rr abstract_distrCrrVautodelete_unpackedrr=ermissing_requestedmissingavailable_requestedrr%)rr;r$r&rs                    "        zRequirementSet._prepare_filec Cs8tjdtx|jD] }|jqWWdQRXdS)zClean up files, remove builds.zCleaning up...N)r|rrrbr)r$ror%r%r& cleanup_filess  zRequirementSet.cleanup_filescs<gtfddxjjD] }|q(WS)zCreate the installation order. The installation order is topological - requirements are installed before the requiring thing. We break cycles at an arbitrary point, and make no other guarantees. csP|js|krdS|jrdSj|xj|D] }|q2Wj|dS)N)rQraddrlr/)rodep)order ordered_reqsscheduler$r%r&rs  z,RequirementSet._to_install..schedule)rr[r,)r$rr%)rrrr$r& _to_installs   zRequirementSet._to_installcOs|j}|r(tjddjdd|Dtx|D]}|jrltjd|jt|jddWdQRXy|j||f||Wn$|jr|j r|j YnX|jr|jr|j |j q6WWdQRX||_ dS) zl Install everything in this set (after having downloaded and unpacked the packages) z!Installing collected packages: %sz, cSsg|] }|jqSr%)rp)r)ror%r%r&r+sz*RequirementSet.install..zFound existing installation: %sT)rN) rr|rr5rrrinstallinstall_succeededrollback_uninstallrrra)r$install_optionsglobal_optionsrkwargs to_install requirementr%r%r&rs:  zRequirementSet.install)FNFFNFFFNTFNNFF)NN)F)FF)r7r8r9r'rwr6rrpropertyrrrrrrrrrrrr%r%r%r&rRs4 4 [   'C rR): __future__r collectionsr itertoolsrloggingr pip._vendorrr pip.compatr pip.downloadrr r r r pip.exceptionsr rrrrrrrrrZpip.req.req_installr pip.utilsrrrrpip.utils.hashesrpip.utils.loggingrpip.utils.packagingrpip.vcsr pip.wheelr getLoggerr7r|objectr!r:rFrErBrPrRr%r%r%r&s0      0