U .eRC@sFdZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z m Z mZddlmZddlmZmZmZmZdd lmZmZdd lmZerdd lmZmZmZmZm Z m!Z!dd l"m#Z#dd l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ee0e-ge-fZ1e2e3Z4dddZ5Gddde6Z7dS)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) specifiers)BestVersionAlreadyInstalledDistributionNotFound HashError HashErrorsUnsupportedPythonVersion) indent_log)dist_in_install_pathdist_in_usersite ensure_dirnormalize_version_info)check_requires_pythonget_requires_python)MYPY_CHECK_RUNNING)Callable DefaultDictListOptionalSetTuple) pkg_resources)AbstractDistribution) PipSession) PackageFinder)RequirementPreparer)InstallRequirement)RequirementSetFc Cst|}zt||d}Wn:tjk rR}ztd|j|WYdSd}~XYnX|r\dSdtt |}|rt d|j||dSt d |j||dS)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. ) version_infoz-Package %r has an invalid Requires-Python: %sN.zBIgnoring failed Requires-Python check for package %r: %s not in %rz8Package {!r} requires a different Python: {} not in {!r}) rrrZInvalidSpecifierloggerwarningZ project_namejoinmapstrdebugr format)distrignore_requires_pythonZrequires_pythonZ is_compatibleexcversionr,@/usr/lib/python3.8/site-packages/pip/_internal/legacy_resolve.py_check_dist_requires_python>s> r.csdeZdZdZdddhZdfdd Zdd Zd d Zd d ZddZ ddZ ddZ ddZ Z S)ResolverzResolves which packages need to be installed/uninstalled to perform the requested operation without breaking the requirements of any package. eageronly-if-neededto-satisfy-onlyNc stt|| |jkst| dkr4tjdd} nt| } | |_||_ ||_ ||_ d|_ | |_ | |_||_||_||_||_||_tt|_dS)N)superr/__init___allowed_strategiesAssertionErrorsysrr_py_version_infopreparerfindersessionrequire_hashesupgrade_strategyforce_reinstallignore_dependenciesignore_installedr) use_user_site_make_install_reqrlist_discovered_dependencies) selfr:r<r;Zmake_install_reqrBr@rAr)r?r>Zpy_version_info __class__r,r-r5us&zResolver.__init__c Cs|jjrt|jj|jt|j}|jp>tdd|D|_|j j }| }|r`t |g}t}t||D]N}z||||Wqttk r}z||_||W5d}~XYqtXqt|r|dS)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. css|] }|jVqdSN)Zhas_hash_options).0reqr,r,r- sz#Resolver.resolve..N)r:Zwheel_download_dirr Zunnamed_requirementsrD requirementsvaluesr=anyr; search_scopeZget_formatted_locationsr!inforrextend _resolve_onerrKappend) rFrequirement_setZ root_reqsrPZ locationsZdiscovered_reqsZ hash_errorsrKr*r,r,r-resolves2     zResolver.resolvecCs4|jdkrdS|jdkrdS|jdks*t|jSdS)Nr2Fr0Tr1)r>r7 is_directrFrKr,r,r-_is_upgrade_alloweds   zResolver._is_upgrade_allowedcCs,|jrt|jr"t|jr"|j|_d|_dS)z4 Set a requirement to be installed. N)rBr satisfied_byr Zconflicts_withrXr,r,r-_set_req_to_reinstallszResolver._set_req_to_reinstallcCs|jr dS||j|js dS|jr4||dS||sP|jdkrLdSdS|jsz|j j |ddWn(t k rYdSt k rYnX||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. Nr1z#already satisfied, skipping upgradezalready satisfiedT)Zupgradezalready up-to-date) rAcheck_if_existsrBrZr?r[rYr>linkr;Zfind_requirementrr)rFreq_to_installr,r,r-_check_skip_installeds*     zResolver._check_skip_installedcCs|jdk std|jr0|j||j|j|jS|jdks>t||}|jr`|j ||j|S| |}| |j||j|j ||j |j|j}|js||j|jr|jdkp|jp|jp|jjdk}|r||n td||S)zzTakes a InstallRequirement and returns a single AbstractDist representing a prepared variant of the same. Nz9require_hashes should have been set in Resolver.resolve()r2filezr?r]Zschemer[r!rQ)rFrKZ skip_reasonZupgrade_allowed abstract_distZ should_modifyr,r,r-_get_abstract_dist_forsV        zResolver._get_abstract_dist_forc s4js jrgSd_j}|}t|jjdgfdd}t  j sd_ j ddjs jrtddjttjt|j}|D]}td ||qtt|jtj@}||D]} || |d qjs&js&jW5QRXS) zxPrepare a single requirements file. :return: A list of additional InstallRequirements to also install. T)rr)csPt|}j}j|||d\}}|rB|rBj|||dS)N)parent_req_nameextras_requested)rCr%nameadd_requirementrErTrR)subreqreZsub_install_reqrdZ to_scan_againZ add_to_parentZ more_reqsr^rUrFr,r-add_req}s  z&Resolver._resolve_one..add_reqN)rdz!Installing extra requirements: %r,z"%s does not provide the extra '%s')re) constraintZpreparedZreqs_to_cleanuprTrcZget_pkg_resources_distributionr.r9r)r Zhas_requirementrfrWrgr@Zextrasr!r&r#sortedsetr"ZrequiresrarZZsuccessfully_downloaded) rFrUr^rbr(rjZmissing_requestedZmissingZavailable_requestedrhr,rir-rS[sV     zResolver._resolve_onecs8gtfdd|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. csN|js|krdS|jrdS|j|jD] }|q2|dSrI)rZrladdrErfrT)rKZdeporderZ ordered_reqsschedulerFr,r-rrs  z1Resolver.get_installation_order..schedule)rnrMrN)rFZreq_setZ install_reqr,rpr-get_installation_orders   zResolver.get_installation_order)N)__name__ __module__ __qualname____doc__r6r5rVrYr[r_rcrSrs __classcell__r,r,rGr-r/ns +3  5<Zr/)F)8rwZloggingr8 collectionsr itertoolsrZpip._vendor.packagingrZpip._internal.exceptionsrrrrr Zpip._internal.utils.loggingr Zpip._internal.utils.miscr r r rZpip._internal.utils.packagingrrZpip._internal.utils.typingrtypingrrrrrrZ pip._vendorrZpip._internal.distributionsrZpip._internal.network.sessionrZpip._internal.indexrZ pip._internal.operations.preparerZpip._internal.req.req_installrZpip._internal.req.req_setrr%ZInstallRequirementProviderZ getLoggerrtr!r.objectr/r,r,r,r-s4                0