a [f+@s|dZddlmZddlmZddlZddlZddlZddlmZddl Z ddl Z ddl Z ddl Z e j ddkrddZd d Znd dZd d ZGd ddeZGdddeZGdddeZddZddZddZddZddZddZdd Zd!Zd"d#Zd$d%Zd&d'Zd8d(d)Zd9d*d+Z d,d-Z!Gd.d/d/eZ"Gd0d1d1eZ#d2d3Z$hd4Z%d5d6Z&e'd7krxe&dS):agThis is invoked in a subprocess to call the build backend hooks. It expects: - Command line args: hook_name, control_dir - Environment variables: PEP517_BUILD_BACKEND=entry.point:spec PEP517_BACKEND_PATH=paths (separated with os.pathsep) - control_dir/input.json: - {"kwargs": {...}} Results: - control_dir/output.json - {"return_val": ...} )glob) import_moduleN)joincKsFt|ddd$}tj||fi|Wdn1s80YdS)Nwutf-8encodingopenjsondumpobjpathkwargsfrM/usr/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py write_json!srcCs<t|ddd}t|WdS1s.0YdS)Nrrrr r loadrrrrr read_json%srcKsFt|d(}tj||fddi|Wdn1s80YdS)Nwbr rr rrrrr+s cCs8t|d}t|WdS1s*0YdS)Nrbrrrrrr/s c@seZdZdZddZdS)BackendUnavailablez&Raised if we cannot import the backendcCs ||_dSN tracebackselfr rrr__init__6szBackendUnavailable.__init__N__name__ __module__ __qualname____doc__r#rrrrr4src@seZdZdZddZdS)BackendInvalidz Raised if the backend is invalidcCs ||_dSr)message)r"r*rrrr#<szBackendInvalid.__init__Nr$rrrrr):sr)cs"eZdZdZdfdd ZZS) HookMissingzARaised if a hook is missing and we are not executing the fallbackNcstt||||_dSr)superr+r# hook_name)r"r- __class__rrr#BszHookMissing.__init__)N)r%r&r'r(r# __classcell__rrr.rr+@sr+cCs<tjtj|}tjtj|}tj||g|kS)z5Test if a file is located within the given directory.)osrnormcaseabspath commonprefix)filenameZ directoryrrr contained_inGsr6cstjd}|r*|tj}|tjdd<tjd}|d\}}}z t|Wnt ynt t Yn0|rt fdd|Dstd|r|d D]}t|qS) zFind and load the build backendZPEP517_BACKEND_PATHNrZPEP517_BUILD_BACKEND:c3s|]}tj|VqdSr)r6__file__).0rrrr ^sz!_build_backend..z(Backend was not loaded from backend-path.)r1environgetsplitpathsepsysr partitionr ImportErrorrr format_excanyr)getattr)Z backend_pathZextra_pathitemsZepZmod_path_Zobj_pathZ path_partrr:r_build_backendNs&       rHcCs"t}g}t|dr|d|S)zReturn the list of options features supported by the backend. Returns a list of strings. The only possible value is 'build_editable'. build_editable)rHhasattrappend)backendZfeaturesrrr_supported_featuresjs   rMcCs4t}z |j}Wnty&gYS0||SdSzfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)rHget_requires_for_build_wheelAttributeErrorconfig_settingsrLhookrrrrOws    rOcCs4t}z |j}Wnty&gYS0||SdS)ziInvoke the optional get_requires_for_build_editable hook Returns [] if the hook is not defined. N)rHget_requires_for_build_editablerPrQrrrrTs    rTcCsTt}z |j}Wn4tyD|s(t|||}t|||YS0|||SdS)zInvoke optional prepare_metadata_for_build_wheel Implements a fallback by building a wheel if the hook isn't defined, unless _allow_fallback is False in which case HookMissing is raised. N)rH prepare_metadata_for_build_wheelrPr+ build_wheel_get_wheel_metadata_from_wheel)metadata_directoryrR_allow_fallbackrLrS whl_basenamerrrrUs    rUc Cs~t}z |j}Wn^tyn|s(tz |j}WntyNtddYn0|||}t|||YSYn 0|||SdS)zInvoke optional prepare_metadata_for_build_editable Implements a fallback by building an editable wheel if the hook isn't defined, unless _allow_fallback is False in which case HookMissing is raised. rI)r-N)rH#prepare_metadata_for_build_editablerPr+rIrW)rXrRrYrLrSZ build_hookrZrrrr[s      r[ZPEP517_ALREADY_BUILT_WHEELcCs@g}|D]}td|}|r ||q |r4|StddS)z6Identify the .dist-info folder inside a wheel ZipFile.z[^/\\]+-[^/\\]+\.dist-info/z#No .dist-info folder found in wheelN)ZnamelistrematchrK Exception)Zwhl_zipresrmrrr_dist_info_filess   racCsddlm}ttj|tdWdn1s60Ytj||}||&}t|}|j||dWdn1s0Y|d ddS)zExtract the metadata from a wheel. Fallback for when the build backend does not define the 'get_wheel_metadata' hook. r)ZipFilerN)rmembers/) zipfilerbr r1rrWHEEL_BUILT_MARKERra extractallr?)rZrXrRrbZwhl_fileZzipfZ dist_inforrrrWs  ,rWcCsl|sdStj|}tjt|ts*dSttj|d}|sLtddSt |dkrdtddS|dS)zHCheck for a wheel already built during the get_wheel_metadata hook. Nz*.whlz+Found wheel built marker, but no .whl fileszHFound multiple .whl files; unspecified behaviour. Will call build_wheel.r) r1rdirnameisfilepjoinrfrrprintlen)rXZmetadata_parentZ whl_filesrrr_find_already_built_wheels  rncCs4t|}|r$t||tj|St|||S)zInvoke the mandatory build_wheel hook. If a wheel was already built in the prepare_metadata_for_build_wheel fallback, this will copy it rather than rebuilding the wheel. )rnshutilcopy2r1rbasenamerHrV)wheel_directoryrRrX prebuilt_whlrrrrVs   rVcCs^t}z |j}Wnty(tYn20t|}|rNt||tj |S||||SdS)zInvoke the optional build_editable hook. If a wheel was already built in the prepare_metadata_for_build_editable fallback, this will copy it rather than rebuilding the wheel. N) rHrIrPr+rnrorpr1rrq)rrrRrXrLrSrsrrrrI s     rIcCs4t}z |j}Wnty&gYS0||SdSrN)rHget_requires_for_build_sdistrPrQrrrrts    rtc@seZdZdZdS)_DummyExceptionz(Nothing should ever raise this exceptionN)r%r&r'r(rrrrru,sruc@seZdZdZddZdS)GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationcCs ||_dSrrr!rrrr#2sz GotUnsupportedOperation.__init__Nr$rrrrrv0srvc Cs@t}z|||WSt|dty:ttYn0dS)z&Invoke the mandatory build_sdist hook.UnsupportedOperationN)rH build_sdistrFrurvr rD)Zsdist_directoryrRrLrrrrx6s rx> rVrIrtrxrUrOr[rMrTc Cstttjdkrtdtjd}tjd}|tvrBtd|t|}tt|d}ddd}z|fi|d |d <Wnty}zd |d <|j |d <WYd}~nd}~0t y}zd |d<|j |d<WYd}~n|d}~0t y}zd |d<|j |d <WYd}~nFd}~0t yZ}z$d |d<|jp@||d<WYd}~n d}~00t|t|ddddS)Nrz"Needs args: hook_name, control_dirrhzUnknown hook: %sz input.jsonF) unsupported return_valrr{TZ no_backendr Zbackend_invalidZ backend_errorrzZ hook_missingZmissing_hook_namez output.json)indent)rmrAargvexit HOOK_NAMESglobalsrrkrr r)r*rvr+r-r)r-Z control_dirrSZ hook_inputZjson_outerrrmainLs0     &r__main__)N)N)(r(r importlibrr r1Zos.pathrrkr\rorAr version_inforrr^rr)r+r6rHrMrOrTrUr[rfrarWrnrVrIrtrurvrxrrr%rrrrsN