
    g7                       d dl m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	Z	d dl
Z
d dlZd dlZd dlZd dlmZmZ d dlmZ d dlmZmZ d dlZddlmZmZ ddlmZ dd	lmZmZmZ dd
l m!Z!m"Z"m#Z# ddlm$Z$ ddddddddZ%e%D  ci c]  } | d c} Z& ejN                  de%      Z(d1dZ)d2d3dZ*	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ+ ejX                         jZ                  dz
  Z.e.d k  rdZ. eej^                  de.      Z0ddd6dZ1d7d Z2d8d9d!Z3d:d"Z4	 	 	 	 	 	 	 	 	 	 	 	 d;d#Z5	 d<	 	 	 	 	 	 	 	 	 	 	 d=d$Z6	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d%Z7ejp                  d?d&       Z9d@d'Z:	 	 	 	 dA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd(Z;	 	 	 	 dA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd)Z<dCd*Z=dDdEd+Z>d1d,Z?e@d-k(  r e>e	j                  dd d.       d/d0gZByc c} w )F    )annotationsN)IteratorSequence)partial)NoReturnTextIO   )ProjectBuilder_ctx)env)BuildBackendExceptionBuildExceptionFailedProcessError)ConfigSettingsDistributionStrPath)DefaultIsolatedEnvz[91mz[92mz[93mz[1mz[2mz[4mz[0m)redgreenyellowbolddim	underlinereset _styles)defaultc                 B   dt         j                  v rCdt         j                  v rt        j                  dd       t        j                  t               n1dt         j                  v st        j                  j                         ry t        j                  t               y )NNO_COLORFORCE_COLORzLBoth NO_COLOR and FORCE_COLOR environment variables are set, disabling color   )
stacklevel)
osenvironwarningswarnr   set
_NO_COLORSsysstdoutisatty     C/var/www/openai/venv/lib/python3.12/site-packages/build/__main__.py_init_colorsr/   .   s`    RZZBJJ&MMhuvwJ	"**	$

(9(9(;KK
r-   c                f    t         | j                  |fi t        j                         |d       y )NT)fileflush)printformatr   get)fmtmsgr1   s      r.   _cprintr8   8   s$    	*#**S
*GKKM
*TBr-   c                .    t        dt        |              y )Nz{yellow}WARNING{reset} {})r8   str)messagecategoryfilenamelinenor1   lines         r.   _showwarningr@   <   s     'W6r-   r!   N     )subsequent_indentwidth)originc               P   |G| j                         ^}}t        dt        |d             |D ]  }t        t        |d              y |d   dk(  rU|d   dk(  rd	nd
}|d   dk(  rt        j
                  nd }| j                         D ]  }t        dt        ||      |        y y )Nz{bold}{}{reset}z* )initial_indentrB   r   
subprocessr	   cmdz> z< stderrz{dim}{}{reset})r1   )
splitlinesr8   _fillr3   r)   rJ   )r;   rE   firstrestr?   rG   r1   s          r.   _logrO   O   s    ~ ++-!5t#DED%T23  
l	"!'e!3#AY(2szz&&(D$eD&PW[\ ) 
#r-   c                0   t         t        _        t        j                         dk(  r	 dd l}|j                          t                t        j                  j                  t               t        j                  j                  |        y # t        $ r Y Xw xY w)NWindowsr   )r@   r%   showwarningplatformsystemcoloramainitModuleNotFoundErrorr/   r   LOGGERr'   rO   	VERBOSITY)	verbosityrU   s     r.   
_setup_clir[   ]   sg    'HI%	MMO NKKOODNNy! # 		s   B	 		BBc                0    t        d|        t        |      )z
    Print an error message and exit. Will color the output when writing to a TTY.

    :param msg: Error message
    :param code: Error code
    z{red}ERROR{reset} {})r8   
SystemExit)r7   codes     r.   _errorr_   n   s     "C(
T
r-   c                2    dj                  d | D              S )Nz -> c              3  `   K   | ]&  }|j                  d       d   j                          ( yw);r   N)	partitionstrip).0deps     r.   	<genexpr>z$_format_dep_chain.<locals>.<genexpr>z   s(     J	s}}S)!,224	s   ,.)join)	dep_chains    r.   _format_dep_chainrj   y   s    ;;J	JJJr-   c                    t        |      5 }t        j                  ||       }|j                  |j                         |j                  |j                  ||xs i              |j                  |||xs i       cd d d        S # 1 sw Y   y xY w)N)	installer)r   r
   from_isolated_envinstallbuild_system_requiresget_requires_for_buildbuild)srcdiroutdirdistributionconfig_settingsrl   r   builders          r.   _build_in_isolated_envrw   }   sr     
i	0C 223?G112G22<AVTVWX}}\6?3HbI 
1	0	0s   A-BBc                    t        |       }|sH|j                  ||xs i       }|r0dj                  d |D              }t                t	        d|        |j                  |||xs i       S )Nr   c              3  \   K   | ]$  }|d    t        |dd       fD ]  }|sd|z     & yw)r   r	   Nz
	)rj   )re   depsrf   s      r.   rg   z(_build_in_current_env.<locals>.<genexpr>   s=     "}GDPTUVPWYjkopqprksYtOuy|6C<Ou<Gs   ,,zMissing dependencies:)r
   check_dependenciesrh   r8   r_   rq   )rr   rs   rt   ru   skip_dependency_checkrv   missingdependenciess           r.   _build_in_current_envr      sl     V$G ,,\?;PbQ77"}G"}}LI*<.9:==v/D"EEr-   c                B    | rt        |||||      S t        |||||      S N)rw   r   )	isolationrr   rs   rt   ru   r|   rl   s          r.   _buildr      s/     %fflOU^__$VV\?Tijjr-   c               #    K   	 d  y # t         t        f$ r} t        t        |              Y d } ~ y d } ~ wt        $ r} t        | j                  t        j                        rt                t        t        |              | j                  rRt        j                  | j                  d   | j                  d   | j                  d   d      }dj                  |      }nt        j                  d      }t        d|j                  d             t        t        |              Y d } ~ y d } ~ wt         $ rM} t        j                         j                  d      }t        d|       t        t        |              Y d } ~ y d } ~ ww xY ww)	Nr   r	   r!   )limitr   z
{dim}{}{reset}

)r   r   r_   r:   r   
isinstance	exceptionrH   CalledProcessErrorr8   exc_info	tracebackformat_exceptionrh   
format_excrd   	Exception)etb_linestbs      r.   _handle_build_errorr      s    ./ s1v  akk:#@#@AI3q6N:: 11

1

1

1	H "B%%b)B$bhhtn5s1v !!#))$/$b)s1vsL   F	 FE?1FE?C$D&!F&E?2AE:5F:E??Fc                    t        |       dk(  rd}t        |      t        |       dk(  r| d   S dj                  dj                  | d d       | d         S )Nr   zno elementsr	   z	{} and {}z, r   )len
IndexErrorr4   rh   )elementsr7   s     r.   _natural_language_listr      s_    
8}o	X!	{!!IIhsm$RL
 	
r-   c           
         g }|D ]A  }t        || |||||      }	|j                  t        j                  j	                  |	             C |S )a  
    Run the build process.

    :param srcdir: Source directory
    :param outdir: Output directory
    :param distribution: Distribution to build (sdist or wheel)
    :param config_settings: Configuration settings to be passed to the backend
    :param isolation: Isolate the build in a separate environment
    :param skip_dependency_check: Do not perform the dependency check
    )r   appendr#   pathbasename)
rr   rs   distributionsru   r   r|   rl   builtrt   outs
             r.   build_packager      sM    & E%YoOdfopRWW%%c*+ & Lr-   c                   ddl m} d|v rd}t        |      t        || |d|||      }	t        j
                  j                  |	      }
t        j                  d      }g }|r|j                  j                  |	      5 }|j                  |       	 t        j                  dt        |       d       t        j
                  j                  ||
d	t!        d
              } |D ]A  }t        || |||||      }|j#                  t        j
                  j                  |             C 	 t%        j&                  |d       	 d	d	d	       |
g|S # t%        j&                  |d       w xY w# 1 sw Y   *xY w)a  
    Build a sdist and then the specified distributions from it.

    :param srcdir: Source directory
    :param outdir: Output directory
    :param distribution: Distribution to build (only wheel)
    :param config_settings: Configuration settings to be passed to the backend
    :param isolation: Isolate the build in a separate environment
    :param skip_dependency_check: Do not perform the dependency check
    r	   )tarfilesdistz=Only binary distributions are allowed but sdist was specifiedzbuild-via-sdist-)prefixz	Building z from sdistNz.tar.gzT)ignore_errors)_compatr   
ValueErrorr   r#   r   r   tempfilemkdtempTarFileopen
extractallr   logr   rh   r   r   shutilrmtree)rr   rs   r   ru   r   r|   rl   r   r7   r   
sdist_name	sdist_outr   trt   r   s                   r.   build_package_via_sdistr      sC   & !-Mo9ffgH]_hiE!!%(J  (:;IE__!!%(ALL#=9%;M%J$K;WXi<Ms9~o1NO$1L FFL/[pr{|CLL!1!1#!67 %2 it< )  it< )(s%   =E'BE&E'E$$E''E0c                    t        j                  t        j                  t        j                  d      j                         d      t        t         j                  t        t        d                  } | j                  dt        dt        j                         d	       | j                  d
dddt        j                   ddj!                  t        j"                         d       | j                  dddddd       | j                  dddddd       | j                  d d!ddd"d#       | j                  d$d%t        d&t        j$                   d'd()       | j                  d*d+d,d-.       | j'                         }|j                  d/d0d,d1.       |j                  d2t(        j*                  d34       | j                  d5d6d7d8d9d:;       | S )<z$
    Construct the main parser.
    a  
                A simple, correct Python build frontend.

                By default, a source distribution (sdist) is built from {srcdir}
                and a binary distribution (wheel) is built from the sdist.
                This is recommended as it will ensure the sdist can be used
                to build wheels.

                Pass -s/--sdist and/or -w/--wheel to build a specific distribution.
                If you do this, the default behavior will be disabled, and all
                artifacts will be built from {srcdir} (even if you combine
                -w/--wheel with -s/--sdist, the wheel will be built from {srcdir}).
                z       )rD   )descriptionformatter_classrr   ?z0source directory (defaults to current directory))typenargsr   helpz	--versionz-Vversionzbuild z (,))actionr   z	--verbosez-vrZ   countr   zincrease verbosity)destr   r   r   z--sdistz-sr   append_constr   z;build a source distribution (disables the default behavior))r   r   constr   z--wheelz-wwheelz-build a wheel (disables the default behavior)z--outdirz-oz&output directory (defaults to {srcdir}zdist)PATH)r   r   metavarz--skip-dependency-checkz-x
store_truez2do not check that build dependencies are installed)r   r   z--no-isolationz-nzdisable building the project in an isolated virtual environment. Build dependencies must be installed separately when this option is usedz--installerz1Python package installer to use (defaults to pip))choicesr   z--config-settingz-Cru   r   zsettings to pass to the backend.  Multiple settings can be provided. Settings beginning with a hyphen will erroneously be interpreted as options to build if separated by a space character; use ``--config-setting=--my-setting -C--my-other-setting``zKEY[=VALUE])r   r   r   r   )argparseArgumentParsertextwrapindentdedentrd   r   RawDescriptionHelpFormattermin_max_terminal_widthadd_argumentr:   r#   getcwdrq   __version__rh   __path__sepadd_mutually_exclusive_group_env
INSTALLERS)parser	env_groups     r.   main_parserr      s    $$OOOO eg!
(   D DCPcehLij+F. 		?   **+2chhu~~.F-GqI	   !   J   <   7xuE   !A	   335IS	   @  
 [   	 Mr-   c                Z   t               }|r||_        |j                  |       }t        |j                         i }|j
                  r`|j
                  D ]Q  }|j                  d      \  }}}||vr|||<   "t        ||   t              s	||   g||<   ||   j                  |       S |j                  *t        j                  j                  |j                  d      n|j                  }	|j                  }
|
rt         }n	t"        }dg}
t%               5   ||j                  |	|
||j&                   |j(                  |j*                        }t-        |D cg c]'  } dj.                  |fi t0        j3                         ) c}      }t5        d|       ddd       yc c}w # 1 sw Y   yxY w)z
    Parse the CLI arguments and invoke the build process.

    :param cli_args: CLI arguments
    :param prog: Program name to show in help text
    )rZ   =Ndistr   z!{underline}{}{reset}{bold}{green}z){bold}{green}Successfully built {}{reset})r   prog
parse_argsr[   rZ   ru   rc   r   listr   rs   r#   r   rh   rr   r   r   r   r   no_isolationr|   rl   r   r4   r   r5   r8   )cli_argsr   r   argsru   argsetting_valuers   r   
build_callr   artifactartifact_lists                  r.   mainr     s    ]FX&D(O''C #c 2GQo-+0(!/'":DA0?0H/IOG,(//6 ( 37++2ERWW\\$++v.4;;F(,(:(:M"
,
 			KK!!!&&NN
 /chichW_7077RGKKMRchi
 	;]K 
	 j 
	s   AF!,F
 F!F!!F*c                 <    t        t        j                  dd         y )Nr	   )r   r)   argvr,   r-   r.   
entrypointr     s    !"r-   __main__zpython -m buildr   r   )returnNone)r   r   N)r6   r:   r7   r:   r1   TextIO | Noner   r   )NN)r;   zWarning | strr<   ztype[Warning]r=   r:   r>   intr1   r   r?   
str | Noner   r   )r;   r:   rE   ztuple[str, ...] | Noner   r   )rZ   r   r   r   )r	   )r7   r:   r^   r   r   r   )ri   Sequence[str]r   r:   )rr   r   rs   r   rt   r   ru   ConfigSettings | Nonerl   _env.Installerr   r:   )F)rr   r   rs   r   rt   r   ru   r   r|   boolr   r:   )r   r   rr   r   rs   r   rt   r   ru   r   r|   r   rl   r   r   r:   )r   zIterator[None])r   r   r   r:   )NTFpip)rr   r   rs   r   r   zSequence[Distribution]ru   r   r   r   r|   r   rl   r   r   r   )r   zargparse.ArgumentParserr   )r   r   r   r   r   r   )C
__future__r   r   
contextlibcontextvarsr#   rS   r   rH   r)   r   r   r   r%   collections.abcr   r   	functoolsr   typingr   r   rq   r   r
   r   r   r   _exceptionsr   r   r   _typesr   r   r   r   _COLORSr(   
ContextVarr   r/   r8   r@   get_terminal_sizecolumnsr   fillrL   rO   r[   r_   rj   rw   r   r   contextmanagerr   r   r   r   r   r   r   __name__r   __all__)colors   0r.   <module>r     s`   #    	    
     .  #  "  R R 9 9 #  &--WEeRiW-
 !+
 
 G
<C 777 7 	7
 7 7 
7 /f..0881< ! 	=PQ <@ ]""KJJJ J +	J
 J 	J* #(FFF F +	F
  F 	F&kkk k 	k
 +k  k k 	k  8

" .2"' % * +	
     < .2"' %* * *  **  +	* 
 *   *  *  * ZdN2Lj z!"() y .s   
F<