3 Re @s`dZddlmZddlmZddlZddlZddlZddlmZddl Z ddl Z ddl Z ddl Z e j ddkrddZd d Znd dZd d ZGd ddeZGdddeZGdddeZddZddZddZddZdZddZddZd d!Zd/d"d#Zd$d%ZGd&d'd'eZGd(d)d)eZd*d+Z ddd#d%d+hZ!d,d-Z"e#d.kr\e"dS)0agThis 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|WdQRXdS)Nwzutf-8)encoding)openjsondump)objpathkwargsfr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py write_json!src Cs$t|ddd }tj|SQRXdS)Nrzutf-8)r)rr load)r rrrr read_json%src Ks2t|d}tj||fddi|WdQRXdS)Nwbrzutf-8)rr r )r r r rrrrr+s c Cs t|d }tj|SQRXdS)Nrb)rr r)r rrrrr/s c@seZdZdZddZdS)BackendUnavailablez&Raised if we cannot import the backendcCs ||_dS)N) traceback)selfrrrr__init__6szBackendUnavailable.__init__N)__name__ __module__ __qualname____doc__rrrrrr4src@seZdZdZddZdS)BackendInvalidz Raised if the backend is invalidcCs ||_dS)N)message)rr rrrr<szBackendInvalid.__init__N)rrrrrrrrrr:src@seZdZdZdS) HookMissingzARaised if a hook is missing and we are not executing the fallbackN)rrrrrrrrr!@sr!cCs<tjjtjj|}tjjtjj|}tjj||g|kS)z5Test if a file is located within the given directory.)osr normcaseabspath commonprefix)filename directoryrrr contained_inDsr(c stjjd}|r*|jtj}|tjdd<tjd}|jd\}}}y t|Wn t k rpt t j YnX|rt fdd|Dstd|rx|jd D]}t|qWS) zFind and load the build backendPEP517_BACKEND_PATHNrPEP517_BUILD_BACKEND:c3s|]}tj|VqdS)N)r(__file__).0r )r rr \sz!_build_backend..z(Backend was not loaded from backend-path.)r"environgetsplitpathsepsysr partitionr ImportErrorrr format_excanyrgetattr) backend_pathZextra_pathitemsepZmod_path_Zobj_pathZ path_partr)r r_build_backendKs&      r=c Cs2t}y |j}Wntk r$gSX||SdS)zfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)r=get_requires_for_build_wheelAttributeError)config_settingsbackendhookrrrr>gs  r>c CsFt}y |j}Wn&tk r6|s*tt|||SX|||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)r= prepare_metadata_for_build_wheelr?r!_get_wheel_metadata_from_wheel)metadata_directoryr@_allow_fallbackrArBrrrrCus rCZPEP517_ALREADY_BUILT_WHEELcCsDg}x*|jD]}tjd|}|r|j|qW|r8|StddS)z6Identify the .dist-info folder inside a wheel ZipFile.z[^/\\]+-[^/\\]+\.dist-info/z#No .dist-info folder found in wheelN)namelistrematchappend Exception)Zwhl_zipresr mrrr_dist_info_filess rNcCsddlm}|j||}ttjj|tdWdQRXtjj||}||}t|}|j ||dWdQRX|dj 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)ZipFilerN)r members/) zipfilerO build_wheelrr"r rWHEEL_BUILT_MARKERrN extractallr2)rArEr@rOZ whl_basenameZwhl_fileZzipfZ dist_inforrrrDs    rDcCsl|sdStjj|}tjjt|ts*dSttjj|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) r"r dirnameisfilepjoinrTrrprintlen)rEZmetadata_parentZ whl_filesrrr_find_already_built_wheels  r\cCs4t|}|r$tj||tjj|Stj|||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. )r\shutilcopy2r"r basenamer=rS)wheel_directoryr@rEZ prebuilt_whlrrrrSs    rSc Cs2t}y |j}Wntk r$gSX||SdS)zfInvoke the optional get_requires_for_build_wheel hook Returns [] if the hook is not defined. N)r=get_requires_for_build_sdistr?)r@rArBrrrras  rac@seZdZdZdS)_DummyExceptionz(Nothing should ever raise this exceptionN)rrrrrrrrrbsrbc@seZdZdZddZdS)GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationcCs ||_dS)N)r)rrrrrrsz GotUnsupportedOperation.__init__N)rrrrrrrrrrcsrccCs@t}y |j||St|dtk r:ttjYnXdS)z&Invoke the mandatory build_sdist hook.UnsupportedOperationN)r= build_sdistr9rbrcrr7)sdist_directoryr@rArrrres  recCsJttjdkrtjdtjd}tjd}|tkrBtjd|t|}tt|d}ddd}y|f|d |d <Wntk r}zd |d <|j |d <WYdd}~Xnt k r}zd |d<|j |d<WYdd}~XnRt k r}zd |d<|j |d <WYdd}~Xnt k r0d |d<YnXt|t|ddddS)Nrz"Needs args: hook_name, control_dirrVzUnknown hook: %sz input.jsonF) unsupported return_valr riT no_backendrbackend_invalid backend_errorrh hook_missingz output.json)indent)r[r4argvexit HOOK_NAMESglobalsrrYrrrr rcr!r) hook_nameZ control_dirrB hook_inputZjson_outerrrmains.     rv__main__)N)$rr importlibrr r"os.pathrrYrHr]r4r version_inforrrKrrr!r(r=r>rCrTrNrDr\rSrarbrcrerqrvrrrrrsN