3 (\#B@sRdZddlZddlZddlmZmZddlmZddlm Z m Z m Z m Z m Z ddlmZmZmZmZmZddlmZddlmZdd lmZdd lmZmZdd lmZerdd lm Z m!Z!dd l"m#Z#ddl$m%Z%ddlm&Z&ddl'm(Z(ej)e*Z+ddZ,Gddde-Z.Gddde.Z/Gddde.Z0Gddde.Z1Gddde-Z2dS)z)Prepares a distribution for installation N) pkg_resourcesrequests)BuildEnvironment) is_dir_url is_file_url is_vcs_url unpack_url url_to_path)DirectoryUrlHashUnsupported HashUnpinnedInstallationErrorPreviousBuildDirErrorVcsHashUnsupported) expanduser) MissingHashes) indent_log) display_pathnormalize_path)MYPY_CHECK_RUNNING)AnyOptional)InstallRequirement) PackageFinder) PipSession)RequirementTrackercCs0|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)reqr!s/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/operations/prepare.pymake_abstract_dist!s r#c@s(eZdZdZddZddZddZdS) DistAbstractionayAbstracts out the wheel vs non-wheel Resolver.resolve() 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)r )selfr r!r!r"__init__EszDistAbstraction.__init__cCstdS)z Return a setuptools Dist object.N)NotImplementedError)r%r!r!r"distIszDistAbstraction.distcCstdS)z3Ensure that we can get a Dist for this requirement.N)r')r%finderbuild_isolationr!r!r" prep_for_distNszDistAbstraction.prep_for_distN)__name__ __module__ __qualname____doc__r&r(r+r!r!r!r"r$2sr$c@seZdZddZddZdS)rcCsttj|jjdS)Nr)listrfind_distributionsr source_dir)r%r!r!r"r(Vsz IsWheel.distcCsdS)Nr!)r%r)r*r!r!r"r+[szIsWheel.prep_for_distN)r,r-r.r(r+r!r!r!r"rTsrc@s,eZdZddZddZddZddZd S) rcCs |jjS)N)r get_dist)r%r!r!r"r(csz IsSDist.distcCs0ddt|D}td|j|dj|fdS)NcSsg|]\}}d||fqS)z%s is incompatible with %sr!).0 installedZwantedr!r!r" hsz,IsSDist._raise_conflicts..z4Some build dependencies for %s conflict with %s: %s.z, )sortedr r join)r%Zconflicting_withZconflicting_reqsZconflict_messagesr!r!r"_raise_conflictsfs  zIsSDist._raise_conflictsc Cs^|j}|jd|_|jj}WdQRX|jj|\}}|rH|jd||jj||dddS)z Install any extra build dependencies that the backend requests. :param finder: a PackageFinder object. z#Getting requirements to build wheelNzthe backend dependenciesZnormalzInstalling backend dependencies)r build_env spin_messageZpep517_backendZget_requires_for_build_wheelcheck_requirementsr9install_requirements)r%r)r reqs conflictingmissingr!r!r"install_backend_dependenciesps z$IsSDist.install_backend_dependenciescCs|jj|jjo|}|rt|j_|jjj||jjdd|jjj|jj\}}|rb|j d||rt j d|jt j ddj t tt||j|d|jj|jjdS)NZoverlayzInstalling build dependenciesz"PEP 517/518 supported requirementsz4Missing build requirements in pyproject.toml for %s.z`The project does not specify a build backend, and pip cannot fall back to setuptools without %s.z and )r))r Zload_pyproject_tomlZ use_pep517rr:r=Zpyproject_requiresr<Zrequirements_to_checkr9loggerwarningr8mapreprr7rAZprepare_metadataassert_source_matches_version)r%r)r*Zshould_isolater?r@r!r!r"r+s,      zIsSDist.prep_for_distN)r,r-r.r(r9rAr+r!r!r!r"ras rc@seZdZddZddZdS) InstalledcCs|jjS)N)r satisfied_by)r%r!r!r"r(szInstalled.distcCsdS)Nr!)r%r)r*r!r!r"r+szInstalled.prep_for_distN)r,r-r.r(r+r!r!r!r"rGsrGcsDeZdZdZfddZeddZddZdd Zd d Z Z S) RequirementPreparerzPrepares a Requirement csHtt|j||_||_||_||_|r2t|}||_||_ ||_ dS)N) superrIr&src_dir build_dir req_tracker download_dirrwheel_download_dir progress_barr*)r%rLrNrKrOrPr*rM) __class__r!r"r&s zRequirementPreparer.__init__cCsD|jr@t|j|_tjj|jr$dStjdtdt|jdS)NTz!Could not find download directoryz0Could not find or access download directory '%s'F) rNrospathexistsrBcriticalr r)r%r!r!r"_download_should_saves  z)RequirementPreparer._download_should_savec Cs|jr0|jjdkr0t|jj}tjdt|n tjd|t|j|j t j j t j j |jdr|td||jf|j||||jst|j}|rt|rtnt|rt|rt|j r|j rt|j| d}|r| rt}y\|j} d} |jjr|jr|j} |jjr6| r2d} nd} t|j|j| | |||j d WnHt!j"k r} z(tj#d || t$d || |jfWYd d } ~ XnXt%|} |j&j'|| j(||j)Wd QRX|j*r|jj+s|j,|jWd QRX| S) zCPrepare a requirement that would be obtained from req.link filez Processing %sz Collecting %szsetup.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_internetTF)sessionhashesrPz4Could not install requirement %s because of error %szDCould not install requirement %s because of HTTP error %s for URL %sN)-rschemer urlrBinforrensure_has_source_dirrLrRrSrTr8r2r populate_linkAssertionErrorrrrrr original_link is_pinnedr rZrrNrrOrrPr HTTPErrorrUr r#rMtrackr+r*rV is_artifactarchive) r%r rYr)upgrade_allowedrequire_hashesrSrrZrNautodelete_unpackedexc abstract_distr!r!r"prepare_linked_requirementsh        " z.RequirementPreparer.prepare_linked_requirementcCs|jstdtjd|tz|r2td||j|j|j|j t |}|j j ||j ||jWdQRX|j r|j|j|j|WdQRX|S)z(Prepare an editable requirement z-cannot prepare a non-editable req as editablez Obtaining %szoThe editable requirement %s cannot be installed when requiring hashes, because there is no single file to hash.N)rr`rBr]rr r^rKupdate_editablerVr#rMrdr+r*rfrNcheck_if_exists)r%r rh use_user_siter)rkr!r!r"prepare_editable_requirementqs    z0RequirementPreparer.prepare_editable_requirementc Csf|jstd|dk s&td|jftjd|||jjt|rPtjdt|}WdQRX|S)z1Prepare an already-installed requirement z(req should have been satisfied but isn'tNzAdid not get skip reason skipped but req.satisfied_by is set to %rzRequirement %s: %s (%s)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.)rHr`rBr]versionrdebugrG)r%r rh skip_reasonrkr!r!r"prepare_installed_requirements  z1RequirementPreparer.prepare_installed_requirement) r,r-r.r/r&propertyrVrlrprt __classcell__r!r!)rQr"rIs  & ~"rI)3r/loggingrR pip._vendorrrZpip._internal.build_envrZpip._internal.downloadrrrrr Zpip._internal.exceptionsr r r r rZpip._internal.utils.compatrZpip._internal.utils.hashesrZpip._internal.utils.loggingrZpip._internal.utils.miscrrZpip._internal.utils.typingrZtypingrrZpip._internal.req.req_installrZpip._internal.indexrrZpip._internal.req.req_trackerr getLoggerr,rBr#objectr$rrrGrIr!r!r!r"s0          " N