o
    viI                     @  sR  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*dZ/doddZ0dpdqd d!Z1		drdsd+d,Z2dtd.d/Z3dud1d2Z4dvdwd5d6Z5dxd9d:Z6ej7	dydzdIdJZ8d{dLdMZ9ej7d|dOdPZ:d}dRdSZ;		T	U	Vd~ddZd[Z<		T	U	Vd~dd\d]Z=		T	U	Vd~dd^d_Z>ddadbZ?ddedfZ@dyddidjZAdodkdlZBeCdmkr#eAe
jDdd dn djdbgZEd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                   C  sT   dt jv rdt jv rtjd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 r/   r/   M/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/build/__main__.py_init_colors1   s   

r1   fmtstrmsgfileTextIO | Nonec                 C  s$   t | j|fi t |dd d S )NT)r5   flush)printformatr   get)r2   r4   r5   r/   r/   r0   _cprint;   s   $r;   messageWarning | strcategorytype[Warning]filenamelinenointline
str | Nonec                 C  s   t dt| | d S )Nz{yellow}WARNING{reset} {})r;   r3   )r<   r>   r@   rA   r5   rC   r/   r/   r0   _showwarning?   s   rE   _ctx.Loggerc                    sB   t  jd } | dkrd} ttjd| d d dd fdd}|S )Nr$   r   N     )subsequent_indentwidth)originr<   r3   rK   tuple[str, ...] | Noner    r!   c                  s   t jdkrP|d u r-|  ^}}td |ddtjd |D ]}t |ddtjd qd S |d dkrR|d	 d
kr;dnd}|  D ]}td ||dtjd qAd S d S d S )Nz{bold}{}{reset}z* )initial_indentr5   rH   r   
subprocessr
   cmdz> z< z{dim}{}{reset})r   	verbosity
splitlinesr;   r,   stderrr8   )r<   rK   firstrestrC   rN   fillr/   r0   logQ   s   
z_make_logger.<locals>.log)r<   r3   rK   rL   r    r!   )shutilget_terminal_sizecolumnsr   textwraprX   )max_terminal_widthrY   r/   rW   r0   _make_loggerJ   s   r_   rR   c                 C  s^   t t_t dkrz
dd l}|  W n	 ty   Y nw t  t	j
t  t	j|  d S )NWindowsr   )rE   r(   showwarningplatformsystemcoloramainitModuleNotFoundErrorr1   r   LOGGERr*   r_   	VERBOSITY)rR   rd   r/   r/   r0   
_setup_clia   s   ri   coder   c                 C  s   t d| tj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} {}rO   )r;   r,   rT   
SystemExit)r4   rj   r/   r/   r0   _errorr   s   rl   	dep_chainSequence[str]c                 C  s   d dd | D S )Nz -> c                 s  s"    | ]}| d d  V  qdS );r   N)	partitionstrip).0depr/   r/   r0   	<genexpr>~   s     z$_format_dep_chain.<locals>.<genexpr>)join)rm   r/   r/   r0   _format_dep_chain}   s   rv   	isolationboolsrcdirr   distributionr   config_settingsConfigSettings | Noneskip_dependency_check	installer_env.InstallerrunnerSubprocessRunner | NoneIterator[ProjectBuilder]c                 c  s    | r?t |d-}ttj||}|rt||d}| }	||	j ||	|| |	V  W d    d S 1 s8w   Y  d S tt|}|rLt||d}| }	|sm|	||}
|
rmddd |
D }t	  t
d|  |	V  d S )N)r~   r   r   c                 s  s:    | ]}|d  t |dd fD ]	}|rd| V  qqdS )r   r
   Nz
	)rv   )rr   depsrs   r/   r/   r0   rt      s    z'_bootstrap_build_env.<locals>.<genexpr>zMissing dependencies:)r   r   r   from_isolated_envinstallbuild_system_requiresget_requires_for_buildcheck_dependenciesru   r;   rl   )rw   ry   rz   r{   r}   r~   r   r   make_builderbuildermissingdependenciesr/   r/   r0   _bootstrap_build_env   s0   
"


r   outdirc              	   C  sV   t | |||||tjdk rtjnd }||||W  d    S 1 s$w   Y  d S )Nr   )r   r   rR   pyproject_hooksquiet_subprocess_runnerbuild)rw   ry   r   rz   r{   r}   r~   r   r/   r/   r0   _build   s   	$r   Iterator[None]c               
   c  s.   zd V  W d S  t tfy" }  ztt|  W Y d } ~ d S d } ~ w tyr }  zEt| jtjr9t	  tt|  | j
rTtj| j
d | j
d | j
d dd}d|}ntd}t	d|d tt|  W Y d } ~ d S d } ~ w ty }  zt d}t	d| tt|  W Y d } ~ d S d } ~ ww )	Nr   r
   r$   rM   )limitr   z
{dim}{}{reset}

)r   r   rl   r3   r   
isinstance	exceptionrP   CalledProcessErrorr;   exc_info	tracebackformat_exceptionru   
format_excrq   	Exception)etb_linestbr/   r/   r0   _handle_build_error   s8   

r   elementsc                 C  sJ   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, rM   )len
IndexErrorr9   ru   )r   r4   r/   r/   r0   _natural_language_list   s   r   TFpipdistributionsSequence[Distribution]	list[str]c           
   	   C  s8   g }|D ]}t || |||||}	|tj|	 q|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)
ry   r   r   r{   rw   r}   r~   builtrz   outr/   r/   r0   build_package   s
   r   c                 C  s  ddl m} d|v rd}t|t|| |d|||}	tj|	}
tjdd}g }|r|j	
|	P}|| z:tdt| d tj||
d	td
  } |D ]}t|| |||||}|tj| qRW tj|dd ntj|dd w W d	   n1 sw   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   rY   r   ru   r   r   rZ   rmtree)ry   r   r   r{   rw   r}   r~   r   r4   r   
sdist_name	sdist_outr   trz   r   r/   r/   r0   build_package_via_sdist  s*   
"

r   c              
   C  s   dd l }ddd
d}t|| d||||dC}	t /}
ttj|	|
dd}|j	
| \}}W d    n1 s=w   Y  W d    n1 sLw   Y  W d    n1 s[w   Y  ttj|ddd g S )Nr   rQ   Sequence[StrPath]cwdrD   extra_environMapping[str, str] | Noner    r!   c                 S  s*   t j }|r|| t| || d S N)r&   r'   copyupdater   run_subprocess)rQ   r   r   r   r/   r/   r0   r   <  s   

z'_build_metadata.<locals>.run_subprocesswheelr   METADATArbFr$   )ensure_asciiindentNN)rQ   r   r   rD   r   r   r    r!   )packaging.metadatar   r   TemporaryDirectoryr   r&   r   ru   metadata_pathmetadataparse_emailreadr8   jsondumps)ry   r   r   r{   rw   r}   r~   	packagingr   r   tempdirmetadata_filevalid_metadata_r/   r/   r0   _build_metadata1  s4   	  r   argparse.ArgumentParserc            
   
   C  s  G dd dt j} t j}tt jdd |d}tjdkr"t|dd}| }|jd	t	d
t
 dd |d}|jdddt jdd |jddddtj ddtj dd | }|jddd| ddd  |jd!d"dd#dd$d  |d%}|jd&d't	d(t
j d)d*d+ |jd,d-d.d/d0d1d2 |jd3d4d.d/d5d6d2 |jd7d8d9d: | }|jd;d<d=d>d?d@dA |jdBdCdDdEdF |dG}| }	|	jdHtjdIdJ |	jdKdLd8dMd: |jdNdOd8dPd: |S )Qz$
    Construct the main parser.
    c                      s2   e Zd Z		dd fddZ	ddddZ  ZS )z(main_parser.<locals>.NegativeCountActionNoption_stringsrn   destr3   r   r   helprD   r    r!   c                   s   t  j||d||d d S )Nr   )r   r   nargsr   r   )super__init__)selfr   r   r   r   	__class__r/   r0   r   Z  s   
z1main_parser.<locals>.NegativeCountAction.__init__parserr   	namespaceobjectvaluesstr | Sequence[Any] | Noneoption_stringc                 S  s    t || jt|| jdd  d S )Nr   r
   )setattrr   getattr)r   r   r   r   r   r/   r/   r0   __call__i  s    z1main_parser.<locals>.NegativeCountAction.__call__r   )
r   rn   r   r3   r   r   r   rD   r    r!   r   )
r   r   r   r   r   r   r   rD   r    r!   )__name__
__module____qualname__r   r   __classcell__r/   r/   r   r0   NegativeCountActionY  s    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_errorry   ?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-qrR   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_argumentr3   r&   getcwdadd_argument_groupSUPPRESSr   __version__ru   __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_groupr/   r/   r0   main_parserT  s   


	

	r!  raw_config_settingsdict[str, Any]c                 C  sh   t ttf  }| D ](}|d\}}}||vr|||< q	t|| ts*|| g||< || | q	|S )N=)dictr3   r   rp   r   listr   )r"  r{   argsettingr   valuer/   r/   r0   _parse_config_settings  s   
r*  cli_argsprogc           
   
   C  s  t  }|r||_|| }t|jd tttf  }|jrIzt	
|j}t|ts-td W n" t	jyH } ztd|  W Y d}~nd}~ww |jrQt|j}|jdu r^tj|jdn|j}|jrm|jrm|d n|jrxttdgd}n|jrtt|jd}nttdgd}t = ||j|||j |j|jd	}t jd
kr|rt!dd |D }	t"d|	 W d   dS W d   dS W d   dS 1 sw   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
    )rR   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{   rw   r}   r~   rM   c                 S  s"   g | ]}d j |fi t qS )z!{underline}{}{reset}{bold}{green})r9   r   r:   )rr   artifactr/   r/   r0   
<listcomp><  s   " zmain.<locals>.<listcomp>z){bold}{green}Successfully built {}{reset})#r!  r,  
parse_argsri   rR   r%  r3   r   r  r   loadsr   rl   JSONDecodeErrorr{   r*  r   r&   r   ru   ry   r   r   errorr   r   r   r   r   no_isolationr}   r~   r   r   r;   )
r+  r,  r   argsr{   r   r   r   r   artifact_listr/   r/   r0   main  sZ   


 		"r7  c                   C  s   t tjdd   d S )Nr
   )r7  r,   argvr/   r/   r/   r0   
entrypointA  s   r9  __main__zpython -m build)r    r!   )r   r   N)r2   r3   r4   r3   r5   r6   r    r!   r   )r<   r=   r>   r?   r@   r3   rA   rB   r5   r6   rC   rD   r    r!   )r    rF   )rR   rB   r    r!   )r
   )r4   r3   rj   rB   r    r   )rm   rn   r    r3   r   )rw   rx   ry   r   rz   r   r{   r|   r}   rx   r~   r   r   r   r    r   )rw   rx   ry   r   r   r   rz   r   r{   r|   r}   rx   r~   r   r    r3   )r    r   )r   rn   r    r3   )NTFr   )ry   r   r   r   r   r   r{   r|   rw   rx   r}   rx   r~   r   r    r   )r    r   )r"  r   r    r#  )r+  rn   r,  rD   r    r!   )F
__future__r   r
  
contextlibcontextvarsr   r&   rb   rZ   rP   r,   r   r]   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   r1   r;   rE   r_   ri   rl   rv   contextmanagerr   r   r   r   r   r   r   r!  r*  r7  r9  r   r8  __all__r/   r/   r/   r0   <module>   s   	

	



)
1
# 
%
9
