a ljH@szdZddlZddlZddlmZddlmZddlmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZdd lmZmZmZmZmZmZdd lmZdd lmZdd lm Z dd l!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl/m2Z2ddl3m4Z4e5e6Z7ee8e e$fZ9dee e:e:e:fe;ddddZto-satisfy-onlyonly-if-neededeagerN.) preparerfinder wheel_cachemake_install_req use_user_siteignore_dependenciesignore_installedr$force_reinstallupgrade_strategypy_version_infor%c szt| dur"tjdd} nt| } | |_||_||_||_| |_ | |_ ||_ ||_ ||_ ||_||_tt|_dS)N)super__init__sysr#r_py_version_infor;r<r=rCrBr@rAr$r?_make_install_reqrlist_discovered_dependencies) selfr;r<r=r>r?r@rAr$rBrCrD __class__r4r5rGus  zResolver.__init__) root_reqscheck_supported_wheelsr%c Cst|d}|D]}|jr t|||qg}t}t|j|D]P}z||||WqBt y}z||_ | |WYd}~qBd}~00qB|r||S)aResolve what operations need to be done As a side-effect of this method, the packages (and their dependencies) are downloaded, unpacked and prepared for installation. This preparation is done by ``pip.operations.prepare``. Once PyPI has static dependency metadata available, it would be possible to move the preparation to become a step separated from dependency resolution. )rQN) r constraintradd_requirementrrZall_requirementsextend _resolve_onerreqappend)rMrPrQrequirement_setrVZdiscovered_reqsZ hash_errorsr2r4r4r5resolves  "zResolver.resolverVr%cCs,|jdkrdS|jdkrdS|jp&|jSdS)Nr8Fr:T)rCZ user_suppliedrRrMrVr4r4r5_is_upgrade_alloweds   zResolver._is_upgrade_allowedcCs*|jrt|jr t|jr d|_d|_dS)z4 Set a requirement to be installed. TN)r?r satisfied_byr Zshould_reinstallr[r4r4r5_set_req_to_reinstallszResolver._set_req_to_reinstall)req_to_installr%cCs|jr dS||j|js dS|jr4||dS||sP|jdkrLdSdS|jsz|j j |ddWn$t y~YdSt yYn0||dS)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. Nr9z#already satisfied, skipping upgradezalready satisfiedT)upgradezalready up-to-date) rAcheck_if_existsr?r]rBr^r\rClinkr<find_requirementr r)rMr_r4r4r5_check_skip_installeds*       zResolver._check_skip_installedcCsR||}|j||}|s dS|j}|jrN|jp4d}dj||d}t||S)Nz zqThe candidate selected for download or install is a yanked version: {candidate} Reason for being yanked: {reason}) candidatereason) r\r<rcrbZ is_yankedZ yanked_reasonr0r*r+)rMrVr`Zbest_candidaterbrfmsgr4r4r5_find_requirement_link s   zResolver._find_requirement_linkcCs~|jdur|||_|jdus(|jjr,dS|jj|j|jtd}|durzt d|j|j|j urr|j rrd|_ |j|_dS)afEnsure that if a link can be found for this, that it is found. Note that req.link may still be None - if the requirement is already installed and not needed to be upgraded based on the return value of _is_upgrade_allowed(). If preparer.require_hashes is True, don't use the wheel cache, because cached wheels, always built locally, have different hashes than the files downloaded from the index server and thus throw false hash mismatches. Furthermore, cached wheels at present have undeterministic contents due to file modification times. N)rbZ package_nameZsupported_tagszUsing cached wheel link: %sT) rbrhr=r;Zrequire_hashesZget_cache_entrynamerr*r/Z original_linkZ persistentZoriginal_link_is_in_wheel_cache)rMrVZ cache_entryr4r4r5_populate_link!s  zResolver._populate_linkcCs|jr|j|S||}|jr0|j||S|||j|}|jsX| |j |jr|j dkp~|j p~|jp~|j jdk}|r||n td||S)zzTakes a InstallRequirement and returns a single AbstractDist representing a prepared variant of the same. r8filezs0        zResolver._get_dist_for)rXr_r%c s,js jrgSd_}t|jjdgtttddfdd }t  j sxj ddj sjrtdd jttjt|}|D]}td |j|j|qtt|tj@}||D]}|||d qWdn1s0YS) zxPrepare a single requirements file. :return: A list of additional InstallRequirements to also install. T)r#r$N)subreqextras_requestedr%csPt|}j}j|||d\}}|rB|rBj|||dS)N)parent_req_namerp)rJr'rirSrLrWrT)rorpZsub_install_reqrqZ to_scan_againZ add_to_parentZ more_reqsr_rXrMr4r5add_reqs z&Resolver._resolve_one..add_req)rqz!Installing extra requirements: %r,z%%s %s does not provide the extra '%s')rp)rRZpreparedrnr6rIr$r rr'rZhas_requirementrirSr@extrasr*r/r-sortedsetZiter_provided_extrasr+r,r3Ziter_dependencies) rMrXr_r"rsZmissing_requestedmissingZavailable_requestedror4rrr5rUlsH     .zResolver._resolve_one)req_setr%cs@gttddfdd |jD] }|q.S)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. NrZcsN|js|vrdS|jrdS|j|jD] }|q2|dS)N)r]rRaddrLrirW)rVZdeporderZ ordered_reqsschedulerMr4r5r}s  z1Resolver.get_installation_order..schedule)rwrZ requirementsvalues)rMryZ install_reqr4r{r5get_installation_orders   zResolver.get_installation_order)N)__name__ __module__ __qualname____doc__Z_allowed_strategiesrrrr rboolr'r intrGrrrrYr\r^rdrrhrjrrnrUr __classcell__r4r4rNr5r7nsF' %   60 Pr7)F)>rZloggingrH collectionsr itertoolsrtypingrrrrrr Zpip._vendor.packagingr Z"pip._vendor.packaging.requirementsr Zpip._internal.cacher Zpip._internal.exceptionsr rrrrrZ"pip._internal.index.package_finderrZpip._internal.metadatarZpip._internal.models.linkrZ pip._internal.operations.preparerZpip._internal.req.req_installrrZpip._internal.req.req_setrZpip._internal.resolution.baserrZ&pip._internal.utils.compatibility_tagsrZpip._internal.utils.loggingrZpip._internal.utils.miscrrr Zpip._internal.utils.packagingr!Z getLoggerrr*r'ZDiscoveredDependenciesrrr6r7r4r4r4r5s>                   7