
    Oh*                     b   d Z ddlZddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ d Zd Z G d d	e      Z G d
 de      Z G d de      Zd Zd Zd Zd Zd Zd Zd ZdZd Zd Zd Zd$dZd$dZd Z  G d de      Z! G d de      Z"d  Z#h d!Z$d" Z%e&d#k(  r e%        yy)%ag  This 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": ...}
    N)glob)import_module)joinc                 x    t        |dd      5 }t        j                  | |fi | d d d        y # 1 sw Y   y xY w)Nwutf-8encoding)openjsondump)objpathkwargsfs       /mnt/c/Users/Administrator/Desktop/help_/test_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py
write_jsonr      s8    	dC'	* $a		#q#F#$ $ $s   09c                 r    t        | d      5 }t        j                  |      cd d d        S # 1 sw Y   y xY w)Nr   r	   )r   r   load)r   r   s     r   	read_jsonr   #   s.    	dW	% yy|  s   -6c                       e Zd ZdZd Zy)BackendUnavailablez&Raised if we cannot import the backendc                     || _         y N	tracebackselfr   s     r   __init__zBackendUnavailable.__init__*   	    "    N__name__
__module____qualname____doc__r    r!   r   r   r   (   s
    0#r!   r   c                       e Zd ZdZd Zy)BackendInvalidz Raised if the backend is invalidc                     || _         y r   )message)r   r+   s     r   r   zBackendInvalid.__init__0   s	    r!   Nr"   r'   r!   r   r)   r)   .   s
    *r!   r)   c                   $     e Zd ZdZd fd	Z xZS )HookMissingzARaised if a hook is missing and we are not executing the fallbackc                 2    t         |   |       || _        y r   )superr   	hook_name)r   r0   	__class__s     r   r   zHookMissing.__init__6   s    #"r!   r   )r#   r$   r%   r&   r   __classcell__)r1   s   @r   r-   r-   4   s    K# #r!   r-   c                 :   t         j                  j                  t         j                  j                  |             } t         j                  j                  t         j                  j                  |            }t         j                  j	                  | |g      |k(  S )z5Test if a file is located within the given directory.)osr   normcaseabspathcommonprefix)filename	directorys     r   contained_inr:   ;   sc    ww 9:H  !;<I779 56)CCr!   c                     t         j                  j                  d      } | r2| j                  t         j                        }|t
        j                  dd t         j                  d   }|j                  d      \  }}}	 t        |      | rt        fdD              st        d      |r"|j                  d      D ]  }t        |       S # t        $ r t        t        j                               w xY w)	zFind and load the build backendPEP517_BACKEND_PATHNr   PEP517_BUILD_BACKEND:c              3   J   K   | ]  }t        j                  |        y wr   )r:   __file__).0r   r   s     r   	<genexpr>z!_build_backend.<locals>.<genexpr>R   s$      
 t,
s    #z(Backend was not loaded from backend-path.)r4   environgetsplitpathsepsysr   	partitionr   ImportErrorr   r   
format_excanyr)   getattr)backend_pathextra_pathitemsepmod_path_obj_path	path_partr   s          @r   _build_backendrU   B   s     ::>>"78L&,,RZZ8&!	*	+BLL-Ha9H%  
'
 
 !!KLL!, 	*I#y)C	*J  9 !5!5!7889s   >C 'C7c                  X    t               } g }t        | d      r|j                  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)rU   hasattrappend)backendfeaturess     r   _supported_featuresr\   ^   s.     GHw()()Or!   c                 b    t               }	 |j                  } ||       S # t        $ r g cY S w xY wzfInvoke the optional get_requires_for_build_wheel hook

    Returns [] if the hook is not defined.
    )rU   get_requires_for_build_wheelAttributeErrorconfig_settingsrZ   hooks      r   r_   r_   k   ?    
 G%33 O$$  	     ..c                 b    t               }	 |j                  } ||       S # t        $ r g cY S w xY w)ziInvoke the optional get_requires_for_build_editable hook

    Returns [] if the hook is not defined.
    )rU   get_requires_for_build_editabler`   ra   s      r   rg   rg   y   s?    
 G%66 O$$  	re   c                     t               }	 |j                  } || |      S # t        $ r |s
t               Y nw xY w|j	                  | |      }t        || |      S )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.
    )rU    prepare_metadata_for_build_wheelr`   r-   build_wheel_get_wheel_metadata_from_wheel)metadata_directoryrb   _allow_fallbackrZ   rc   whl_basenames         r   ri   ri      sw     G977
 &88	   -   &&'9?KL),8J*9; ;s   ! 99c                     t               }	 |j                  } || |      S # t        $ rK |s
t               	 |j                  } || |      }t        || |      cY S # t        $ r t        d      w xY ww xY w)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.
    rW   )r0   )rU   #prepare_metadata_for_build_editabler`   r-   rW   rk   )rl   rb   rm   rZ   rc   
build_hookrn   s          r   rp   rp      s     G9:: &88  C-	C //J &&8/JL1,2D2AC C	  	:(899	:Cs    ! A5AA5A11A5PEP517_ALREADY_BUILT_WHEELc                     g }| j                         D ],  }t        j                  d|      }|s|j                  |       . |r|S t	        d      )z6Identify the .dist-info folder inside a wheel ZipFile.z[^/\\]+-[^/\\]+\.dist-info/z#No .dist-info folder found in wheel)namelistrematchrY   	Exception)whl_zipresr   ms       r   _dist_info_filesr{      sU    
C  " HH3T:JJt 

9
::r!   c                 z   ddl m} t        t        j                  j                  |t              d      5  	 ddd       t        j                  j                  ||       } ||      5 }t        |      }|j                  ||       ddd       d   j                  d      d   S # 1 sw Y   oxY w# 1 sw Y   ,xY w)zExtract the metadata from a wheel.

    Fallback for when the build backend does not
    define the 'get_wheel_metadata' hook.
    r   )ZipFilewbN)r   members/)
zipfiler}   r   r4   r   r   WHEEL_BUILT_MARKERr{   
extractallrF   )rn   rl   rb   r}   whl_filezipf	dist_infos          r   rk   rk      s      	bggll-/ABD	I  ww||.=H		 Dd$T*	/CD Q<c"1%% D Ds   B%'B1%B.1B:c                 N   | syt         j                  j                  |       }t         j                  j                  t	        |t
                    syt        t         j                  j                  |d            }|st        d       yt        |      dkD  rt        d       y|d   S )zHCheck for a wheel already built during the get_wheel_metadata hook.
    Nz*.whlz+Found wheel built marker, but no .whl files   zHFound multiple .whl files; unspecified behaviour. Will call build_wheel.r   )
r4   r   dirnameisfilepjoinr   r   r   printlen)rl   metadata_parent	whl_filess      r   _find_already_built_wheelr      s     ggoo&89O77>>%1CDERWW\\/7;<I;<
9~ ' 	( Q<r!   c                     t        |      }|r5t        j                  ||        t        j                  j                  |      S t               j                  | ||      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   shutilcopy2r4   r   basenamerU   rj   )wheel_directoryrb   rl   prebuilt_whls       r   rj   rj      sR     --?@L\?3ww--''(:< <r!   c                     t               }	 |j                  }t        |      }|r5t        j                  ||        t
        j                  j                  |      S  || ||      S # t        $ r t               w xY w)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.
    )
rU   rW   r   r   r   r4   r   r   r`   r-   )r   rb   rl   rZ   rc   r   s         r   rW   rW      sy     G
J%% 11CDLL777##L11O_6HII  ms   A$ $A8c                 b    t               }	 |j                  } ||       S # t        $ r g cY S w xY wr^   )rU   get_requires_for_build_sdistr`   ra   s      r   r   r     rd   re   c                       e Zd ZdZy)_DummyExceptionz(Nothing should ever raise this exceptionN)r#   r$   r%   r&   r'   r!   r   r   r   "  s    2r!   r   c                       e Zd ZdZd Zy)GotUnsupportedOperationz9For internal use when backend raises UnsupportedOperationc                     || _         y r   r   r   s     r   r   z GotUnsupportedOperation.__init__(  r    r!   Nr"   r'   r!   r   r   r   &  s
    C#r!   r   c                     t               }	 |j                  | |      S # t        |dt              $ r t	        t        j                               w xY w)z&Invoke the mandatory build_sdist hook.UnsupportedOperation)rU   build_sdistrM   r   r   r   rK   )sdist_directoryrb   rZ   s      r   r   r   ,  sO    G>""?ODD72OD >%i&:&:&<==>s	    2A>	   r   rj   rW   r\   r   r_   rg   ri   rp   c                     t        t        j                        dk  rt        j                  d       t        j                  d   } t        j                  d   }| t        vrt        j                  d| z         t               |    }t        t        |d            }dd d}	  |di |d	   |d
<   t        |t        |d      d       y # t        $ r}d|d<   |j                  |d<   Y d }~;d }~wt        $ r}d|d<   |j                  |d<   Y d }~`d }~wt        $ r}d|d<   |j                  |d<   Y d }~d }~wt        $ r"}d|d<   |j                  xs | |d<   Y d }~d }~ww xY w)N   z"Needs args: hook_name, control_dirr      zUnknown hook: %sz
input.jsonF)unsupported
return_valr   r   T
no_backendr   backend_invalidbackend_errorr   hook_missingmissing_hook_namezoutput.json)indentr'   )r   rH   argvexit
HOOK_NAMESglobalsr   r   r   r   r)   r+   r   r-   r0   r   )r0   control_dirrc   
hook_inputjson_outes         r   mainr   B  sB   
388}q56I((1+K
"#i/09YD5l;<J$D9HA!%!=
8(<!= x{M:1E  ,!% ! .&*"#$%II!" ,"& ! A#' ()(@y$%As<    C 	E!C))E!5DE!D33E!?EE!__main__r   )'r&   r   r4   os.pathru   r   rH   r   r   	importlibr   r   r   r   r   rw   r   r)   r-   r:   rU   r\   r_   rg   ri   rp   r   r{   rk   r   rj   rW   r   r   r   r   r   r   r#   r'   r!   r   <module>r      s     	  	  
   # !$

# #Y #) #D8
%%;,96 2 	;&$,< J*%3i 3#i #>

F< zF r!   