U ʗRe+ @sdZddlmZddlmZddlZddlZddlZddlmZddl Z ddl Z ddl Z ddl Z e j ddkrddZd d Znd dZd d ZGd ddeZGdddeZGdddeZddZddZddZddZddZddZdd Zd!Zd"d#Zd$d%Zd&d'Zd7d(d)Zd8d*d+Z d,d-Z!Gd.d/d/eZ"Gd0d1d1eZ#d2d3Z$ddd)dd d+d-d3dh Z%d4d5Z&e'd6kre&dS)9agThis 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)joinc Ks.t|ddd}tj||f|W5QRXdS)Nwutf-8encodingopenjsondumpobjpathkwargsfr/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py write_json!src Cs0t|ddd}t|W5QRSQRXdS)Nrrrr r loadrrrrr read_json%src Ks2t|d}tj||fddi|W5QRXdS)Nwbr rr rrrrr+s c Cs,t|d}t|W5QRSQRXdS)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)filename directoryrrr contained_inGsr7cstjd}|r*|tj}|tjdd<tjd}|d\}}}z t|Wn t k rpt t YnX|rt fdd|Dstd|r|d D]}t|qS) zFind and load the build backendPEP517_BACKEND_PATHNrPEP517_BUILD_BACKEND:c3s|]}tj|VqdSr)r7__file__).0rrrr ^sz!_build_backend..z(Backend was not loaded from backend-path.)r1environgetsplitpathsepsysr partitionr ImportErrorrr format_excanyr)getattr) backend_pathZextra_pathitemsepZmod_path_Zobj_pathZ path_partrr=r_build_backendNs&      rMcCs"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)rMhasattrappend)backendfeaturesrrr_supported_featuresjs   rScCs6t}z |j}Wntk r(gYSX||SdSzfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)rMget_requires_for_build_wheelAttributeErrorconfig_settingsrQhookrrrrUws   rUcCs6t}z |j}Wntk r(gYSX||SdS)ziInvoke the optional get_requires_for_build_editable hook Returns [] if the hook is not defined. N)rMget_requires_for_build_editablerVrWrrrrZs   rZcCsVt}z |j}Wn6tk rF|s*t|||}t|||YSX|||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)rM prepare_metadata_for_build_wheelrVr+ build_wheel_get_wheel_metadata_from_wheel)metadata_directoryrX_allow_fallbackrQrY whl_basenamerrrr[s   r[c Cst}z |j}Wnbtk rr|s*tz |j}Wntk rRtddYnX|||}t|||YSYn X|||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. rN)r-N)rM#prepare_metadata_for_build_editablerVr+rNr])r^rXr_rQrYZ build_hookr`rrrras    raZPEP517_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)namelistrematchrP Exception)Zwhl_zipresrmrrr_dist_info_filess   rhc Csvddlm}ttj|tdW5QRXtj||}||}t|}|j||dW5QRX|d ddS)zExtract the metadata from a wheel. Fallback for when the build backend does not define the 'get_wheel_metadata' hook. r)ZipFiler)rmembers/) zipfilerir r1rrWHEEL_BUILT_MARKERrh extractallrB)r`r^rXriZwhl_fileZzipfZ dist_inforrrr]s   r]cCsl|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) r1rdirnameisfilepjoinrmrrprintlen)r^Zmetadata_parentZ whl_filesrrr_find_already_built_wheels  rucCs4t|}|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. )rushutilcopy2r1rbasenamerMr\)wheel_directoryrXr^ prebuilt_whlrrrr\s   r\cCs`t}z |j}Wntk r*tYn2Xt|}|rPt||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) rMrNrVr+rurvrwr1rrx)ryrXr^rQrYrzrrrrN s    rNcCs6t}z |j}Wntk r(gYSX||SdSrT)rMget_requires_for_build_sdistrVrWrrrr{s   r{c@seZdZdZdS)_DummyExceptionz(Nothing should ever raise this exceptionN)r%r&r'r(rrrrr|,sr|c@seZdZdZddZdS)GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationcCs ||_dSrrr!rrrr#2sz GotUnsupportedOperation.__init__Nr$rrrrr}0sr}c CsBt}z|||WSt|dtk r<ttYnXdS)z&Invoke the mandatory build_sdist hook.UnsupportedOperationN)rM build_sdistrIr|r}r rG)sdist_directoryrXrQrrrr6s rc Cshttjdkrtdtjd}tjd}|tkrBtd|t|}tt|d}ddd}z|f|d |d <Wntk r}zd |d <|j |d <W5d}~XYnt k r}zd |d<|j |d<W5d}~XYnpt k r}zd |d<|j |d <W5d}~XYn<t k rN}zd |d<|jp8||d<W5d}~XYnXt|t|ddddS)Nrz"Needs args: hook_name, control_dirrozUnknown hook: %sz input.jsonF) unsupported return_valrrT no_backendr backend_invalid backend_errorr hook_missingmissing_hook_namez output.json)indent)rtrDargvexit HOOK_NAMESglobalsrrrrr r)r*r}r+r-r)r-Z control_dirrY hook_inputZjson_outerrrmainLs0     "r__main__)N)N)(r(r importlibrr r1os.pathrrrrcrvrDr version_inforrrerr)r+r7rMrSrUrZr[rarmrhr]rur\rNr{r|r}rrrr%rrrrs`