3 Pf@s~ddlmZddlmZddlmZddlZddlZddlm Z ddlm Z ddl m Z ddl mZmZmZmZmZdd lmZmZmZmZmZmZmZmZmZmZdd lmZdd l m!Z!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/ej0e1Z2Gddde3Z4Gddde3Z5ddZ6Gddde5Z7Gddde5Z8Gddde5Z9Gddde3Z:dS))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_usersitedist_in_install_path 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&/usr/lib/python3.6/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__4szRequirements.__getitem__cs$fddjD}ddj|S)Ncs$g|]}dt|t|fqS)z%s: %s)repr)r*k)r%r&r'r,8sz)Requirements.__repr__..zRequirements({%s})z, )r)join)r%r-r&)r%r'__repr__7szRequirements.__repr__N) __name__ __module__ __qualname__r(r)r-r/r2r3r7r&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(OszDistAbstraction.__init__cCst|jdS)z Return a setuptools Dist object.N)NotImplementedErrordist)r%finderr&r&r'r>RszDistAbstraction.distcCst|jdS)z3Ensure that we can get a Dist for this requirement.N)r=r>)r%r&r&r' prep_for_distVszDistAbstraction.prep_for_distN)r8r9r:__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_dist[s rGc@seZdZddZddZdS)rFcCsttj|jjdS)Nr)listrZfind_distributionsr< source_dir)r%r?r&r&r'r>msz IsWheel.distcCsdS)Nr&)r%r&r&r'r@qszIsWheel.prep_for_distN)r8r9r:r>r@r&r&r&r'rFksrFc@seZdZddZddZdS)rCcCs(|jj}|jdr$|j|jd|S)Nzdependency_links.txt)r<Zget_distZ has_metadataZadd_dependency_linksZget_metadata_lines)r%r?r>r&r&r'r>xs    z IsSDist.distcCs|jj|jjdS)N)r<Z run_egg_infoZassert_source_matches_version)r%r&r&r'r@s zIsSDist.prep_for_distN)r8r9r:r>r@r&r&r&r'rCvs rCc@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)r8r9r:r>r@r&r&r&r'rJsrJc@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_hashesrrH _dependencies)r%rNrOrPrQrRrSr]r_rXrTr^r`rarbrc wheel_cachererYr&r&r'r(s<zRequirementSet.__init__cCs8dd|jjD}|jddddjdd|DS)NcSsg|]}|js|qSr&)Z comes_from)r*reqr&r&r'r,sz*RequirementSet.__str__..cSs |jjS)N)namelower)rhr&r&r'sz(RequirementSet.__str__..)r+ cSsg|]}t|jqSr&)strrh)r*rhr&r&r'r,s)rUr-sortr6)r%reqsr&r&r'__str__szRequirementSet.__str__cCsNdd|jjD}|jddddjdd|D}d|jjt||fS) NcSsg|]}|qSr&r&)r*rhr&r&r'r,sz+RequirementSet.__repr__..cSs |jjS)N)rirj)rhr&r&r'rksz)RequirementSet.__repr__..)r+z, cSsg|]}t|jqSr&)rmrh)r*rhr&r&r'r,sz"<%s object; %d requirement(s): %s>)rUr-rnr6 __class__r8len)r%roZreqs_strr&r&r'r7s 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)#riZ match_markersloggerwarningZmarkersrDrEr!filenameZ supportedr r]r^r_ra is_directrWr0get_requirementKeyError constraintextrasrhZ specifierrUrjrVpathr\tuplesortedsetuniondebugrf) r% install_reqZparent_req_nameextras_requestedriZwheelZ existing_reqresultZ parent_reqr&r&r'add_requirementsp             zRequirementSet.add_requirementcCsF|j}||jkr |j|j s>||jkrB|j|j|j rBdSdS)NTF)rjrUryrV)r% project_namerir&r&r'has_requirement4s  zRequirementSet.has_requirementcCstdd|jjDp|jS)Ncss|]}|js|VqdS)N)ry)r*rhr&r&r' ?sz2RequirementSet.has_requirements..)rHrUr-rW)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) rProsr{existsrscriticalr r)r%r&r&r' is_downloadBs  zRequirementSet.is_downloadcCsTxB||jfD]2}||jkr&|j|S||jkr|j|j|SqWtd|dS)NzNo project with the name %r)rjrUrVrx)r%rrir&r&r'rwOs    zRequirementSet.get_requirementcCs4x.|jjD] }|jrq |j|d|jq WdS)N) auto_confirm)rUr-ry uninstallcommit_uninstall)r%rrhr&r&r'rWs  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)Zhas_hash_options)r*rhr&r&r'rjsz/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.)rerXN)rcrrWrUr-reanyr]r rrextend _prepare_filerXrrhr0)r%r?Z root_reqsreZdiscovered_reqsZ hash_errorsrhexcr&r&r' prepare_files^s,   zRequirementSet.prepare_filescCs |jo|jdkp|jdko|jS)NZeagerzonly-if-needed)rQrRrv)r%rhr&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|jr~t |j pt |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_existsrKrrTrDZfind_requirementrrr^rrconflicts_withrR)r%r<r?Zupgrade_allowedZbest_installed skip_reasonr&r&r'_check_skip_installeds4      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}|jjrjjjn0jrD|r8tjd t}n jjtjjtjjj 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 t5j6krjjjsjjrPj7sjrDj8r&t9j p0t:j s<j_;d_n tjd|j<|} y t=| WnHt>k r}z*j?rtj@|jAdn jBWYdd}~XnXgfdd}jCjDsވjEd|spjFrtjddjjFtGtHjFtH| jF}x|D]}tj@d| |qWtGtH| jFtHjF@}x | jI|D]}|||dqZWjJjKj rj rjLjKWdQRXS)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.)Ztrust_internetF)r`hashesz4Could 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)MryZpreparedrBrsinforKAssertionErrorrSrrDschemer Zurlrrr Zensure_has_source_dirrOZupdate_editablerrGr@archiverPrrrJrNrr{rr6rIrZ populate_linkrr rrr rZ original_linkZ is_pinnedrrrrErcr r`rZ HTTPErrorrr Z all_schemesrQr^rrrr>rrrYrtargsremove_temporary_sourcerrirrzr}r~Zrequiresr\r0rZ)r%r?r<rerXrr{Z abstract_distrDrrPZautodelete_unpackedrr>erZmissing_requestedZmissingZavailable_requestedrr&)rr<r%r'rs                    "        zRequirementSet._prepare_filec Cs8tjdtx|jD] }|jqWWdQRXdS)zClean up files, remove builds.zCleaning up...N)rsrrr\r)r%rhr&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)rKryaddrfr0)rhZdep)order ordered_reqsscheduler%r&r'rs  z,RequirementSet._to_install..schedule)r~rUr-)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&)ri)r*rhr&r&r'r,sz*RequirementSet.install..zFound existing installation: %sT)rN) rrsrr6rrrinstallZinstall_succeededZrollback_uninstallrrr[)r%Zinstall_optionsZglobal_optionsrkwargsZ to_installZ requirementr&r&r'rs:  zRequirementSet.install)FNFFNFFFNTFNNFF)NN)F)FF)r8r9r:r(rpr7rrpropertyrrrwrrrrrrrrr&r&r&r'rLs4 4 [   'E  rL);Z __future__r collectionsr itertoolsrZloggingrZ pip._vendorrrZ pip.compatrZ pip.downloadrr r r r Zpip.exceptionsr rrrrrrrrrZpip.req.req_installrZ pip.utilsrrrrrZpip.utils.hashesrZpip.utils.loggingrZpip.utils.packagingrZpip.vcsr Z pip.wheelr!Z getLoggerr8rsobjectr"r;rGrFrCrJrLr&r&r&r's0      0