a Re+@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-8encodingopenjsondumpobjpathkwargsfr/builddir/build/BUILDROOT/alt-python39-pip-21.3.1-2.el8.x86_64/opt/alt/python39/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)filename directoryrrr contained_inGsr7cstjd}|r*|tj}|tjdd<tjd}|d\}}}z t|Wnt ynt t Yn0|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   rScCs4t}z |j}Wnty&gYS0||SdSzfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)rMget_requires_for_build_wheelAttributeErrorconfig_settingsrQhookrrrrUws    rUcCs4t}z |j}Wnty&gYS0||SdS)ziInvoke the optional get_requires_for_build_editable hook Returns [] if the hook is not defined. N)rMget_requires_for_build_editablerVrWrrrrZs    rZcCsTt}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)rM prepare_metadata_for_build_wheelrVr+ build_wheel_get_wheel_metadata_from_wheel)metadata_directoryrX_allow_fallbackrQrY whl_basenamerrrr[s    r[c 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. 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   rhcCsddlm}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/) 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}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) rMrNrVr+rurvrwr1rrx)ryrXr^rQrYrzrrrrN s     rNcCs4t}z |j}Wnty&gYS0||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 Cs@t}z|||WSt|dty:ttYn0dS)z&Invoke the mandatory build_sdist hook.UnsupportedOperationN)rM build_sdistrIr|r}r rG)sdist_directoryrXrQrrrr6s r> rZrNrarrUr{rSr\r[c 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_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%rrrrsN