o 7]hpG @srdZddlZddlZddlmZddlmZddlmZm 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/m0Z0ddl1m2Z2e3e4Z5ee6e e$fZ7 ddede e8e8e8fde9ddfddZ:Gddde)Z;dS)ayDependency Resolution The dependency resolution in pip is performed as follows: for top-level requirements: a. only one spec allowed per project, regardless of conflicts or not. otherwise a "double requirement" exception is raised b. they override sub-dependency requirements. for sub-dependencies a. "first found, wins" (where the order is breadth first) N) defaultdict)chain) DefaultDictIterableListOptionalSetTuple) specifiers) Requirement) WheelCache)BestVersionAlreadyInstalledDistributionNotFound HashError HashErrorsNoneMetadataErrorUnsupportedPythonVersion) PackageFinder)BaseDistribution)Link)RequirementPreparer)InstallRequirementcheck_invalid_constraint_type)RequirementSet) BaseResolverInstallRequirementProvider) get_supported) indent_log)normalize_version_info)check_requires_pythonFdist version_infoignore_requires_pythonreturnc Cszt|j}Wnty}zt|t|d}~wwzt||d}Wntjy?}ztd|j |WYd}~dSd}~ww|rDdSd t t|}|rYt d|j ||dSt d|j ||)a Check whether the given Python version is compatible with a distribution's "Requires-Python" value. :param version_info: A 3-tuple of ints representing the Python major-minor-micro version to check. :param ignore_requires_python: Whether to ignore the "Requires-Python" value if the given Python version isn't compatible. :raises UnsupportedPythonVersion: When the given Python version isn't compatible. N)r!z-Package %r has an invalid Requires-Python: %s.zBIgnoring failed Requires-Python check for package %r: %s not in %rz8Package {!r} requires a different Python: {} not in {!r})strrequires_pythonFileNotFoundErrorrrr InvalidSpecifierloggerwarningraw_namejoinmapdebugrformat)r r!r"r&e is_compatibleexcversionr4J/usr/lib/python3/dist-packages/pip/_internal/resolution/legacy/resolver.py_check_dist_requires_python6sD r6cs,eZdZdZhdZ d+dededeede de d e d e d e d e d e dee e dfddffdd Zdeede defddZdede fddZdeddfddZdedee fddZdedeefdd Zdeddfd!d"Zdedefd#d$Zd%ededeefd&d'Zd(edeefd)d*ZZS),ResolverzResolves which packages need to be installed/uninstalled to perform the requested operation without breaking the requirements of any package. >eageronly-if-neededto-satisfy-onlyNpreparerfinder wheel_cachemake_install_req use_user_siteignore_dependenciesignore_installedr"force_reinstallupgrade_strategypy_version_info.r#c st| |jvs J| durtjdd} nt| } | |_||_||_||_ | |_ | |_ ||_ ||_ ||_||_||_tt|_dS)N)super__init___allowed_strategiessysr!r_py_version_infor;r<r=rCrBr@rAr"r?_make_install_reqrlist_discovered_dependencies) selfr;r<r=r>r?r@rAr"rBrCrD __class__r4r5rGts" zResolver.__init__ root_reqscheck_supported_wheelsc Cst|d}|D]}|jrt|||qg}t}t|j|D]'}z ||||Wq!t yH}z||_ | |WYd}~q!d}~ww|rM||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. )rRN) r constraintradd_requirementrrall_requirementsextend _resolve_onerreqappend)rNrQrRrequirement_setrXdiscovered_reqs hash_errorsr2r4r4r5resolves$  zResolver.resolverXcCs6|jdkrdS|jdkrdS|jdksJ|jp|jS)Nr:Fr8Tr9)rC user_suppliedrSrNrXr4r4r5_is_upgrade_alloweds   zResolver._is_upgrade_allowedcCs|jr|jjr d|_d|_dS)z4 Set a requirement to be installed. TN)r? satisfied_by in_usersiteshould_reinstallr_r4r4r5_set_req_to_reinstalls zResolver._set_req_to_reinstallreq_to_installcCs|jrdS||j|jsdS|jr||dS||s(|jdkr&dSdS|jsHz |j j |ddWnt y?YdSt yGYnw||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?rarBrdr`rClinkr<find_requirementr r)rNrer4r4r5_check_skip_installeds,       zResolver._check_skip_installedcCsR||}|j||}|sdS|j}|jr'|jpd}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<rirh is_yanked yanked_reasonr/r)r*)rNrXrfbest_candidaterhrlmsgr4r4r5_find_requirement_links   zResolver._find_requirement_linkcCs|jdur |||_|jdus|jjrdS|jj|j|jtd}|dur?t d|j|j|j ur9|j r9d|_ |j|_dSdS)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)rh package_namesupported_tagszUsing cached wheel link: %sT) rhrqr=r;require_hashesget_cache_entrynamerr)r. original_link persistentoriginal_link_is_in_wheel_cache)rNrX cache_entryr4r4r5_populate_links  zResolver._populate_linkcCs|jr |j|S|jdusJ||}|jr|j||S|||j|}|js3| |j |jrV|j dkpF|j pF|jpF|j jdk}|rP|||Std||S)zzTakes a InstallRequirement and returns a single AbstractDist representing a prepared variant of the same. Nr:filez.add_req)rz!Installing extra requirements: %r,z%%s %s does not provide the extra '%s')r)rSpreparedrr6rJr"r rr%rhas_requirementrvr^rTr@extrasr)r.r,sortedsetiter_provided_extrasr*r+r3iter_dependencies) rNrZrer rmissing_requestedmissingavailable_requestedrr4rr5rWisX  $    ! !!zResolver._resolve_onereq_setcsBgtdtddffdd |jD]}|qS)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. rXr#NcsN|js|vr dS|jrdS|j|jD]}|q|dSN)rarSaddrMrvrY)rXdeporder ordered_reqsschedulerNr4r5rs  z1Resolver.get_installation_order..schedule)rr requirementsvalues)rNr install_reqr4rr5get_installation_orders   zResolver.get_installation_orderr)__name__ __module__ __qualname____doc__rHrrrr rboolr%r intrGrrrr]r`rdrjrrqr{rrrWr __classcell__r4r4rOr5r7mst     & %   6. Or7)F)sD                   7