
    ZiI                       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Zd dlmZmZmZ d dlmZ d dlmZmZm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"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z( ddlm)Z) ddddddddZ*e+,                    e*d          Z- ej.        de*          Z/d_dZ0d`dadZ1	 	 dbdcd)Z2ddd+Z3ded-Z4dfdgd0Z5dhd3Z6ej7        	 didjdB            Z8dkdDZ9ej7        dldF            Z:dmdHZ;	 	 	 	 dndodOZ<	 	 	 	 dndodPZ=	 	 	 	 dndodQZ>dpdSZ?dqdVZ@didrdYZAd_dZZBeCd[k    r eAe
jD        dd         d\           d]d^gZEdS )s    )annotationsN)IteratorMappingSequence)partial)AnyNoReturnTextIO   )ProjectBuilder_ctx)env)BuildBackendExceptionBuildExceptionFailedProcessError)ConfigSettingsDistributionStrPathSubprocessRunner)DefaultIsolatedEnvz[91mz[92mz[93mz[1mz[2mz[4mz[0m)redgreenyellowbolddim	underlinereset _styles)defaultreturnNonec                 D   dt           j        v rDdt           j        v rt          j        dd           t                              t                     n.dt           j        v st          j        	                                rd S t                              t                     d S )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     I/root/projects/butler/venv/lib/python3.11/site-packages/build/__main__.py_init_colorsr4   1   s    RZBJ&&MhuvwwwwJ	"*	$	$
(9(9(;(;	$KK
r2   fmtstrmsgfileTextIO | Nonec                p    t           | j        |fi t                                          |d           d S )NT)r8   flush)printformatr   get)r5   r7   r8   s      r3   _cprintr?   ;   s9    	*#*S
*
*GKKMM
*
*TBBBBBBr2   messageWarning | strcategorytype[Warning]filenamelinenointline
str | Nonec                B    t          dt          |           |           d S )Nz{yellow}WARNING{reset} {})r?   r6   )r@   rB   rD   rE   r8   rG   s         r3   _showwarningrJ   ?   s#     'Wt<<<<<r2   _ctx.Loggerc                     t          j                    j        dz
  } | dk    rd} t          t          j        d|           d ddfd}|S )Nr&   r   N     )subsequent_indentwidth)originr@   r6   rQ   tuple[str, ...] | Noner!   r"   c                  t           j        dk    r|j|                                 ^}}t          d |d          t          j                   |D ](}t           |d          t          j                   )d S |d         dk    rP|d	         d
k    rdnd}|                                 D ]-}t          d ||          t          j                   *d S d S d S )Nz{bold}{}{reset}z* )initial_indentr8   rN   r   
subprocessr   cmdz> z< z{dim}{}{reset})r   	verbosity
splitlinesr?   r.   stderrr<   )r@   rQ   firstrestrG   rU   fills         r3   logz_make_logger.<locals>.logQ   s$   >R~!(!3!3!5!5)44d+K+K+KRUR\]]]]  L LD$$tD999
KKKKKL L l**)/e););#..00 j jD,dd4.W.W.W^a^hiiiii   +*j jr2   )r@   r6   rQ   rR   r!   r"   )shutilget_terminal_sizecolumnsr   textwrapr^   )max_terminal_widthr_   r^   s     @r3   _make_loggerre   J   s|    133;a?Q8=D@RSSSD>B j j j j j j j j Jr2   rY   c                Z   t           t          _        t          j                    dk    r*	 dd l}|                                 n# t          $ r Y nw xY wt                       t          j
                            t                                 t          j                            |            d S )NWindowsr   )rJ   r*   showwarningplatformsystemcoloramainitModuleNotFoundErrorr4   r   LOGGERr,   re   	VERBOSITY)rY   rk   s     r3   
_setup_clirp   a   s    'HI%%	OOOMMOOOO" 	 	 	D	 NNNKOOLNN###Ny!!!!!s   A 
AAcoder	   c                X    t          d| t          j                   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} {}rV   )r?   r.   r[   
SystemExit)r7   rq   s     r3   _errorrt   r   s*     "Ccj9999
T

r2   	dep_chainSequence[str]c                @    d                     d | D                       S )Nz -> c              3  p   K   | ]1}|                     d           d                                         V  2dS );r   N)	partitionstrip).0deps     r3   	<genexpr>z$_format_dep_chain.<locals>.<genexpr>~   s?      JJs}}S))!,2244JJJJJJr2   )join)ru   s    r3   _format_dep_chainr   }   s#    ;;JJ	JJJJJJr2   	isolationboolsrcdirr   distributionr   config_settingsConfigSettings | Noneskip_dependency_check	installer_env.InstallerrunnerSubprocessRunner | NoneIterator[ProjectBuilder]c              #    K   | rt          |          5 }t          t          j        ||          }|rt          ||          } |            }	|                    |	j                   |                    |	                    ||                     |	V  d d d            d S # 1 swxY w Y   d S t          t          |          }|rt          ||          } |            }	|sW|	                    ||          }
|
r?d                    d |
D                       }t                       t          d|            |	V  d S )N)r   r   r   c              3  h   K   | ]-}|d          t          |dd                   fD ]}|d|z   V  .dS )r   r   Nz
	)r   )r|   depsr}   s      r3   r~   z'_bootstrap_build_env.<locals>.<genexpr>   ss       ' '%)aJ[\`abacac\dJeJe@f' '9<jm'SL' ' ' ' ' ' 'r2   zMissing dependencies:)r   r   r   from_isolated_envinstallbuild_system_requiresget_requires_for_buildcheck_dependenciesr   r?   rt   )r   r   r   r   r   r   r   r   make_builderbuildermissingdependenciess               r3   _bootstrap_build_envr      s       )444 	">#CS&QQL D&|FCCC"lnnG KK5666KK66|_UUVVVMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ~v66 	@"<???L,..$ 	?00OOG ?!ww ' '-4' ' '     			=|==>>>s   B B""B&)B&outdirc           
         t          | |||||t          j        dk     rt          j        nd           5 }|                    |||          cd d d            S # 1 swxY w Y   d S )Nr   )r   r   rY   pyproject_hooksquiet_subprocess_runnerbuild)r   r   r   r   r   r   r   r   s           r3   _buildr      s     
37>A3E3E//4
 
 	D 
}}\6?CC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   AAAIterator[None]c               #  ^  K   	 d V  d S # t           t          f$ r'} t          t          |                      Y d } ~ d S d } ~ wt          $ r} t          | j        t          j                  r*t                       t          t          |                      | j
        rOt          j        | j
        d         | j
        d         | j
        d         d          }d                    |          }nt          j        d          }t          d|                    d                     t          t          |                      Y d } ~ d S d } ~ wt           $ r]} t          j                                        d          }t          d|           t          t          |                      Y d } ~ d S d } ~ ww xY w)	Nr   r   r&   rT   )limitr   z
{dim}{}{reset}

)r   r   rt   r6   r   
isinstance	exceptionrW   CalledProcessErrorr?   exc_info	tracebackformat_exceptionr   
format_excr{   	Exception)etb_linestbs      r3   _handle_build_errorr      s     ./   s1vv    ak:#@AA 	III3q66NNN: 		* 1
1
1
1	  H ""BB%b))B$bhhtnn555s1vv   !##))$//$b)))s1vvs,   
 F,=F,
C2EF,AF''F,elementsc                    t          |           dk    rd}t          |          t          |           dk    r| d         S d                    d                    | d d                   | d                   S )Nr   zno elementsr   z	{} and {}z, rT   )len
IndexErrorr=   r   )r   r7   s     r3   _natural_language_listr      su    
8}}oo	X!		{!!IIhssm$$RL
 
 	
r2   TFpipdistributionsSequence[Distribution]	list[str]c           
         g }|D ]I}t          || |||||          }	|                    t          j                            |	                     J|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)
r   r   r   r   r   r   r   builtr   outs
             r3   build_packager      s]    & E% , ,YoOdfoppRW%%c**++++Lr2   c                $   ddl m} d|v rd}t          |          t          || |d|||          }	t          j                            |	          }
t          j        d          }g }|r#|j	        
                    |	          5 }|                    |           	 t          j        dt          |           d           t          j                            ||
d	t!          d
                              } |D ]I}t          || |||||          }|                    t          j                            |                     J	 t%          j        |d           n# t%          j        |d           w xY w	 d	d	d	           n# 1 swxY w Y   |
g|S )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   r_   r   r   r   r   r`   rmtree)r   r   r   r   r   r   r   r   r7   r   
sdist_name	sdist_outr   tr   r   s                   r3   build_package_via_sdistr     s   & !     -Moo9ffgH]_hiiE!!%((J (:;;;IE =_!!%(( 		=ALL###=W%;M%J%JWWWXXXi<Ms9~~o<M1NOO$1 8 8L FFL/[pr{||CLL!1!1#!6!677778 it<<<<<it<<<<<<		= 		= 		= 		= 		= 		= 		= 		= 		= 		= 		= 		= 		= 		= 		= s+   FB'EFE22FF	Fc           	     "   dd l }ddd
}t          || d||||          5 }	t          j                    5 }
t	          t
          j                            |	                    |
          d          d          5 }|j	        
                    |                                          \  }}d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          t          j        |dd                     g S )Nr   rX   Sequence[StrPath]cwdrH   extra_environMapping[str, str] | Noner!   r"   c                    t           j                                        }|r|                    |           t	          j        | ||           d S N)r(   r)   copyupdater   run_subprocess)rX   r   r   r   s       r3   r   z'_build_metadata.<locals>.run_subprocess<  sH    joo 	&JJ}%%%Cc*****r2   wheelr   METADATArbFr&   )ensure_asciiindentNN)rX   r   r   rH   r   r   r!   r"   )packaging.metadatar   r   TemporaryDirectoryr   r(   r   r   metadata_pathmetadataparse_emailreadr<   jsondumps)r   r   r   r   r   r   r   	packagingr   r   tempdirmetadata_filevalid_metadata_s                 r3   _build_metadatar   1  s    + + + + + 	vw9NPYbp	
 	
 	

Q #%%	
Q *1GLL..w77DD	
 	

Q %.::=;M;M;O;OPP
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 
Q 

>a@@@   IsY   C AC	60B2&C	2B66C	9B6:C	=C 	C	C C	C  C$'C$argparse.ArgumentParserc                     G d dt           j                  } t           j        }t          t           j        dd                                |          }t          j        dk    rt          |d          } |            }|                    d	t          d
t          j                    d           |                    d          }|                    dddt           j        d           |                    ddddt          j         dd                    t          j                   d           |                                }|                    ddd| dd            |                    d!d"dd#dd$            |                    d%          }|                    d&d't          d(t          j         d)d*+           |                    d,d-d.d/d0d12           |                    d3d4d.d/d5d62           |                    d7d8d9:           |                                }|                    d;d<d=d>d?d@A           |                    dBdCdDdEF           |                    dG          }|                                }	|	                    dHt(          j        dIJ           |	                    dKdLd8dM:           |                    dNdOd8dP:           |S )Qz$
    Construct the main parser.
    c                  2     e Zd Z	 	 dd fdZ	 dddZ xZS )(main_parser.<locals>.NegativeCountActionNoption_stringsrv   destr6   r    r   helprH   r!   r"   c                T    t                                          ||d||           d S )Nr   )r   r   nargsr    r   )super__init__)selfr   r   r    r   	__class__s        r3   r   z1main_parser.<locals>.NegativeCountAction.__init__Z  s?     GG-      r2   parserr   	namespaceobjectvaluesstr | Sequence[Any] | Noneoption_stringc           	     `    t          || j        t          || j        d          dz
             d S )Nr   r   )setattrr   getattr)r   r   r   r   r  s        r3   __call__z1main_parser.<locals>.NegativeCountAction.__call__i  s1     Ity')TY*J*JQ*NOOOOOr2   r   )
r   rv   r   r6   r    r   r   rH   r!   r"   r   )
r   r   r   r   r   r  r  rH   r!   r"   )__name__
__module____qualname__r   r  __classcell__)r   s   @r3   NegativeCountActionr   Y  sq        
  #	 	 	 	 	 	 	( )-	P 	P 	P 	P 	P 	P 	P 	P 	Pr2   r  Fa:      A simple, correct Python build frontend.

    By default, a source distribution (sdist) is built from the project root
    and a binary distribution (wheel) is built from the sdist.
    If this is undesirable, you can pass `--sdist` and/or `--wheel`
    to build distributions independently of each other.
    )add_helpdescriptionformatter_class)      T)suggest_on_errorr   ?z<source directory (defaults to the current working directory))typer   r    r   zglobal optionsz-hz--helpr   zshow this help message and exit)actionr    r   z	--versionz-Vversionzbuild z (,))r  r  z--quietz-qrY   r   zreduce verbosity)r   r  r    r   z	--verbosez-vcountzincrease verbosityzbuild optionsz--outdirz-oz&output directory (defaults to {srcdir}z3dist).  Cannot be used together with ``--metadata``PATH)r  r   metavarz--sdistz-sr   append_constr   z;build a source distribution (disables the default behavior))r   r  constr   z--wheelz-wr   z-build a wheel (disables the default behavior)z
--metadata
store_truezjprint out a wheel's metadata in JSON format. Cannot be used in conjunction with ``--sdist`` or ``--wheel``)r  r   z--config-settingz-Cr   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; use ``--config-setting=--my-setting -C--my-other-setting`` insteadzKEY[=VALUE])r   r  r   r  z--config-jsonconfig_jsonzsettings to pass to the backend as a JSON object. This is an alternative to ``--config-setting`` that allows complex nested structures. Cannot be used together with ``--config-setting``JSON_STRING)r   r   r  zinstallation optionsz--installerz1Python package installer to use (defaults to pip))choicesr   z--no-isolationz-nzdisable building the project in an isolated virtual environment. Build dependencies must be installed separately when this option is usedz--skip-dependency-checkz-xz2do not check that build dependencies are installed)argparseActionRawDescriptionHelpFormatterr   ArgumentParserrstripr.   version_infoadd_argumentr6   r(   getcwdadd_argument_groupSUPPRESSr   __version__r   __path__add_mutually_exclusive_groupsep_env
INSTALLERS)
r  r  make_parserr   global_groupverbosity_exclusive_groupbuild_groupconfig_exclusive_groupinstall_groupenv_exclusive_groups
             r3   main_parserr8  T  s   
P P P P Pho P P P2 :O 	 (  K 7""kDAAA[]]F
	K     ,,-=>>L!.     I*IIchhu~.F.FIII	     !- I I K K**" +    **! +    ++O<<Kssss     J     <     y    
 )EEGG''Y  ( 	 	 	 ''<  (    --.DEEM'DDFF$$@ %   
 $$S	 %    !A	     Mr2   raw_config_settingsdict[str, Any]c                   t          t          t          f                     }| D ]g}|                    d          \  }}}||vr|||<   %t	          ||         t
                    s||         g||<   ||                             |           h|S )N=)dictr6   r   rz   r   listr   )r9  r   argsettingr   values         r3   _parse_config_settingsrB    s    38n&&O" 3 3MM#..E/))',OG$$og6== F,;G,D+E(G$++E2222r2   cli_argsprogc           	     V   t                      }|r||_        |                    |           }t          |j                   t          t          t          f                     }|j        rm	 t          j
        |j                  }t          |t
                    st          d           nI# t          j        $ r}t          d|            Y d}~n#d}~ww xY w|j        rt          |j                  }|j        %t"          j                            |j        d          n|j        }|j        r|j        r|                    d           nY|j        rt1          t2          dg          }n:|j        rt1          t4          |j                  }nt1          t6          dg          }t9                      5   ||j        |||j         |j        |j        	          }t@          j        d
k    r+|r)tC          d |D                       }	tE          d|	           ddd           dS # 1 swxY w Y   dS )z
    Parse the CLI arguments and invoke the build process.

    :param cli_args: CLI arguments
    :param prog: Program name to show in help text
    )rY   zN--config-json must contain a JSON object (dict), not a list or primitive valuezInvalid JSON in --config-json: Ndistz/--metadata: not allowed with --sdist or --wheelr   )r   )r   r   r   r   rT   c                X    g | ]'} d j         |fi t                                          (S )z!{underline}{}{reset}{bold}{green})r=   r   r>   )r|   artifacts     r3   
<listcomp>zmain.<locals>.<listcomp><  s8    mmm[c;4;HVVVVmmmr2   z){bold}{green}Successfully built {}{reset})#r8  rD  
parse_argsrp   rY   r=  r6   r   r  r   loadsr   rt   JSONDecodeErrorr   rB  r   r(   r   r   r   r   r   errorr   r   r   r   r   no_isolationr   r   r   r   r?   )
rC  rD  r   argsr   r   r   r   r   artifact_lists
             r3   mainrQ    s    ]]F X&&D((((38n&&O  
G	:"j)9::Oot44 ighhh# 	: 	: 	:8Q8899999999	: 
	 G01EFF 37+2ERW\\$+v...4;F} J+ JFGGGG	 JyAAA		 JT5GHHH/yIII			 P PK+++"&"<n
 
 
 >RE2mmglmmm M ?OOOP P P P P P P P P P P P P P P P P Ps+   *=B( (C7CC/A"HH"%H"c                 H    t          t          j        dd                     d S )Nr   )rQ  r.   argvr1   r2   r3   
entrypointrT  A  s     !""r2   __main__zpython -m buildrQ  r8  )r!   r"   )r   r   N)r5   r6   r7   r6   r8   r9   r!   r"   r   )r@   rA   rB   rC   rD   r6   rE   rF   r8   r9   rG   rH   r!   r"   )r!   rK   )rY   rF   r!   r"   )r   )r7   r6   rq   rF   r!   r	   )ru   rv   r!   r6   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r6   )r!   r   )r   rv   r!   r6   )NTFr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   )r!   r   )r9  r   r!   r:  )rC  rv   rD  rH   r!   r"   )F
__future__r   r!  
contextlibcontextvarsr   r(   ri   r`   rW   r.   r   rc   r   r*   collections.abcr   r   r   	functoolsr   typingr   r	   r
   r   r   r   r   r   r   r/  _exceptionsr   r   r   _typesr   r   r   r   r   _COLORSr=  fromkeysr-   
ContextVarr   r4   r?   rJ   re   rp   rt   r   contextmanagerr   r   r   r   r   r   r   r8  rB  rQ  rT  r  rS  __all__r1   r2   r3   <module>rc     s   # " " " " "           				       



        7 7 7 7 7 7 7 7 7 7       ( ( ( ( ( ( ( ( ( (      " " " " " " " "       R R R R R R R R R R K K K K K K K K K K K K # # # # # #   ]]7B''
 !+
 G
<
<
<   C C C C C = = = = =   ." " " ""    K K K K  '+& & & & &RD D D D*    8

 

 

 

" .2"' %    < .2"' %*  *  *  *  * b .2"' %         Fa a a aH    6P 6P 6P 6P 6Pr    zD!""())) r2   