U .ep@s0dZddlmZddlmZddlZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z Gddde ZGdd d e ZGd d d e Zd d ZddZddZddZdZddZddZddZd(ddZddZGdd d e ZGd!d"d"e Zd#d$Zddddd$hZd%d&Ze d'kr,edS))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)joinc@seZdZdZddZdS)BackendUnavailablez&Raised if we cannot import the backendcCs ||_dSN tracebackselfrr B/usr/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py__init__szBackendUnavailable.__init__N__name__ __module__ __qualname____doc__r r r r r rsrc@seZdZdZddZdS)BackendInvalidz Raised if the backend is invalidcCs ||_dSr)message)r rr r r r %szBackendInvalid.__init__Nrr r r r r#src@seZdZdZdS) HookMissingzARaised if a hook is missing and we are not executing the fallbackNrrrrr r r r r)srcCs<tjtj|}tjtj|}tj||g|kS)z5Test if a file is located within the given directory.)ospathnormcaseabspath commonprefix)filenameZ directoryr r r contained_in-srcstjd}|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 backendZPEP517_BACKEND_PATHNrZPEP517_BUILD_BACKEND:c3s|]}tj|VqdSr)r__file__).0robjr r Dsz!_build_backend..z(Backend was not loaded from backend-path.)renvirongetsplitpathsepsysr partitionr ImportErrorrr format_excanyrgetattr)Z backend_pathZextra_pathitemsZepZmod_path_Zobj_pathZ path_partr r!r _build_backend4s&      r0cCs6t}z |j}Wntk r(gYSX||SdSzfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)r0get_requires_for_build_wheelAttributeErrorconfig_settingsbackendhookr r r r2Ps   r2cCsJt}z |j}Wn*tk r:|s*tt|||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)r0 prepare_metadata_for_build_wheelr3r_get_wheel_metadata_from_wheel)metadata_directoryr5Z_allow_fallbackr6r7r r r r8^s  r8ZPEP517_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)Znamelistrematchappend Exception)Zwhl_zipresrmr r r _dist_info_filests   rAc Csddlm}|||}ttj|tdW5QRXtj||}||}t|}|j ||dW5QRX|d ddS)zBuild a wheel and extract the metadata from it. Fallback for when the build backend does not define the 'get_wheel_metadata' hook. r)ZipFilewb)rmembers/) ZzipfilerB build_wheelopenrrrWHEEL_BUILT_MARKERrAZ extractallr')r6r:r5rBZ whl_basenameZwhl_fileZzipfZ dist_infor r r r9s    r9cCsl|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) rrdirnameisfilepjoinrHrrprintlen)r:Zmetadata_parentZ whl_filesr r r _find_already_built_wheels  rOcCs4t|}|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. )rOshutilZcopy2rrbasenamer0rF)Zwheel_directoryr5r:Z prebuilt_whlr r r rFs   rFcCs6t}z |j}Wntk r(gYSX||SdSr1)r0get_requires_for_build_sdistr3r4r r r rRs   rRc@seZdZdZdS)_DummyExceptionz(Nothing should ever raise this exceptionNrr r r r rSsrSc@seZdZdZddZdS)GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationcCs ||_dSrrr r r r r sz GotUnsupportedOperation.__init__Nrr r r r rTsrTc CsBt}z|||WSt|dtk r<ttYnXdS)z&Invoke the mandatory build_sdist hook.UnsupportedOperationN)r0 build_sdistr.rSrTrr,)Zsdist_directoryr5r6r r r rVs rVc CsNttjdkrtdtjd}tjd}|tkrBtd|t|}tt|d}ddd}z|f|d |d <Wnt k r}zd |d <|j |d <W5d}~XYnt k r}zd |d<|j |d<W5d}~XYnRt k r}zd |d<|j |d <W5d}~XYntk r2d |d<YnXtj|t|ddddS)Nz"Needs args: hook_name, control_dirrIzUnknown hook: %sz input.jsonF) unsupported return_valkwargsrZTZ no_backendrZbackend_invalidZ backend_errorrYZ hook_missingz output.json)indent)rNr)argvexit HOOK_NAMESglobalscompatZ read_jsonrLrrrrrTrZ write_json)Z hook_nameZ control_dirr7Z hook_inputZjson_outer r r mains.     rc__main__)N)!rr importlibrrZos.pathrrLr;rPr)rrar>rrrrr0r2r8rHrAr9rOrFrRrSrTrVr_rcrr r r r sF