o
    hi<                     @  sT  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 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'(e&dZ)ej*de&dZ+dmddZ,dndod d!Z-		dpdqd+d,Z.e/ j0d- Z1e1d krd.Z1eej2d/e1d0Z3dd1drd4d5Z4dsd7d8Z5dtdud;d<Z6dvd?d@Z7dwdJdKZ8	LdxdydOdPZ9dzdRdSZ:ej;d{dUdVZ<d|dXdYZ=		Z	L	[d}d~d^d_Z>		Z	L	[d}d~d`daZ?ddcddZ@dddgdhZAdmdidjZBeCdkkr$eAe
jDdd dl dhddgZEdS )    )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)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_COLORZ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+   I/home/app/PyTorch/.pytorch/lib/python3.10/site-packages/build/__main__.py_init_colors/   s   

r-   fmtstrmsgfileTextIO | Nonec                 C  s$   t | j|fi t |dd d S )NT)r1   flush)printformatr   get)r.   r0   r1   r+   r+   r,   _cprint9   s   $r7   messageWarning | strcategorytype[Warning]filenamelinenointline
str | Nonec                 C  s   t dt|  d S )Nz{yellow}WARNING{reset} {})r7   r/   )r8   r:   r<   r=   r1   r?   r+   r+   r,   _showwarning=   s   rA   r    N     )subsequent_indentwidth)originrF   tuple[str, ...] | Nonec                C  s   |d u r"|   ^}}tdt|dd |D ]
}tt|dd qd S |d dkrO|d dkr0d	nd
}|d dkr;tjnd }|   D ]}tdt||d|d qAd S d S )Nz{bold}{}{reset}z* )initial_indentrC   r   
subprocessr   cmdz> z< stderrz{dim}{}{reset})r1   )
splitlinesr7   _fillr4   r(   rK   )r8   rF   firstrestr?   rH   r1   r+   r+   r,   _logP   s   rP   	verbosityc                 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   )rA   r$   showwarningplatformsystemcoloramainitModuleNotFoundErrorr-   r
   LOGGERr&   rP   Z	VERBOSITY)rQ   rV   r+   r+   r,   
_setup_cli^   s   rZ   coder   c                 C  s   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} {})r7   
SystemExit)r0   r[   r+   r+   r,   _erroro   s   
r]   	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+   r,   	<genexpr>{   s     z$_format_dep_chain.<locals>.<genexpr>)join)r^   r+   r+   r,   _format_dep_chainz   s   rg   srcdirr   outdirdistributionr   config_settingsConfigSettings | None	installer_env.Installerc                 C  sn   t |d(}t|| }||j ||||pi  ||||p$i W  d    S 1 s0w   Y  d S )N)rm   )r   r	   Zfrom_isolated_envinstallZbuild_system_requiresZget_requires_for_buildbuild)rh   ri   rj   rk   rm   r   builderr+   r+   r,   _build_in_isolated_env~   s   $rr   Fskip_dependency_checkboolc                 C  sZ   t | }|s$|||pi }|r$ddd |D }t  td|  ||||p+i S )Nr   c                 s  s:    | ]}|d  t |dd fD ]	}|rd| V  qqdS )r   r   Nz
	)rg   )rc   depsrd   r+   r+   r,   re      s   8 z(_build_in_current_env.<locals>.<genexpr>zMissing dependencies:)r	   Zcheck_dependenciesrf   r7   r]   rp   )rh   ri   rj   rk   rs   rq   missingdependenciesr+   r+   r,   _build_in_current_env   s   rx   	isolationc                 C  s$   | r
t |||||S t|||||S N)rr   rx   )ry   rh   ri   rj   rk   rs   rm   r+   r+   r,   _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    )limitr   z
{dim}{}{reset}

)r   r   r]   r/   r   
isinstance	exceptionrI   CalledProcessErrorr7   exc_info	tracebackformat_exceptionrf   
format_excrb   	Exception)eZtb_linestbr+   r+   r,   _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, r}   )len
IndexErrorr5   rf   )r   r0   r+   r+   r,   _natural_language_list   s   r   TpipdistributionsSequence[Distribution]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)
rh   ri   r   rk   ry   rs   rm   builtrj   outr+   r+   r,   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)Z_compatr   
ValueErrorr{   r"   r   r   tempfilemkdtempTarFileopen
extractallr
   logr   rf   r   r   shutilrmtree)rh   ri   r   rk   ry   rs   rm   r   r0   r   Z
sdist_nameZ	sdist_outr   trj   r   r+   r+   r,   build_package_via_sdist   s*   
"

r   argparse.ArgumentParserc               
   C  s~  t tjttdd} tjdkrt | dd} t tjt	t
d d| d}tjdkr2t |ddd	}| }|jd
tdt dd |jddddtj ddtj dd |jddddddd |jdddd d!d"d# |jd$d%dd d&d'd# |jd(d)td*tj d+d,d- |jd.d/d0d1d2 | }|jd3d4d0d5d2 |jd6tjd7d8 | }|jd9d:d;d<d=d>d? |jd@dAdBdCdD |S )Ez$
    Construct the main parser.
       )rE   )      T)colora  
                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    )descriptionformatter_class)Zsuggest_on_errorr   rh   ?z0source directory (defaults to current directory))typenargsr   helpz	--versionz-Vversionzbuild z (,))actionr   z	--verbosez-vrQ   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-Crk   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   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-settingZJSON_STRING)r   r   r   )r   argparseRawDescriptionHelpFormattermin_max_terminal_widthr(   version_infoArgumentParsertextwrapindentdedentrb   add_argumentr/   r"   getcwdrp   __version__rf   __path__sepadd_mutually_exclusive_group_envZ
INSTALLERS)r   Zmake_parserparserZ	env_groupZconfig_groupr+   r+   r,   main_parser!  s   


	r   cli_argsprogc              
   C  s  t  }|r||_|| }t|jd i }|jrDzt|j}t|t	s(t
d W nI tjyC } zt
d|  W Y d}~n4d}~ww |jrs|jD ](}|d\}}}	||vr]|	||< qJt|| tsk|| g||< || |	 qJ|jdu rtj|jdn|j}
|j}|rt}nt}dg}t & ||j|
|||j |j|j}tdd	 |D }td
| 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
    )rQ   zN--config-json must contain a JSON object (dict), not a list or primitive valuezInvalid JSON in --config-json: N=distr   c                 S  s"   g | ]}d j |fi t qS )z!{underline}{}{reset}{bold}{green})r5   r   r6   )rc   artifactr+   r+   r,   
<listcomp>  s   " zmain.<locals>.<listcomp>z){bold}{green}Successfully built {}{reset})r   r   
parse_argsrZ   rQ   r   jsonloadsr   dictr]   JSONDecodeErrorrk   ra   listr   ri   r"   r   rf   rh   r   r   r   r   Zno_isolationrs   rm   r   r7   )r   r   r   argsrk   r   argZsetting_valueri   r   Z
build_callr   Zartifact_listr+   r+   r,   main  sZ   



 	"r   c                   C  s   t tjdd   d S )Nr   )r   r(   argvr+   r+   r+   r,   
entrypoint  s   r   __main__zpython -m build)r   r   )r   r   N)r.   r/   r0   r/   r1   r2   r   r   )NN)r8   r9   r:   r;   r<   r/   r=   r>   r1   r2   r?   r@   r   r   )r8   r/   rF   rG   r   r   )rQ   r>   r   r   )r   )r0   r/   r[   r>   r   r   )r^   r_   r   r/   )rh   r   ri   r   rj   r   rk   rl   rm   rn   r   r/   )F)rh   r   ri   r   rj   r   rk   rl   rs   rt   r   r/   )ry   rt   rh   r   ri   r   rj   r   rk   rl   rs   rt   rm   rn   r   r/   )r   r|   )r   r_   r   r/   )NTFr   )rh   r   ri   r   r   r   rk   rl   ry   rt   rs   rt   rm   rn   r   r_   )r   r   rz   )r   r_   r   r@   r   r   )F
__future__r   r   
contextlibcontextvarsr   r"   rT   r   rI   r(   r   r   r   r$   collections.abcr   r   	functoolsr   typingr   r   rp   r   r	   r
   r   r   _exceptionsr   r   r   _typesr   r   r   r   Z_COLORSr   fromkeysr'   
ContextVarr   r-   r7   rA   get_terminal_sizecolumnsr   fillrM   rP   rZ   r]   rg   rr   rx   r{   contextmanagerr   r   r   r   r   r   r   __name__r   __all__r+   r+   r+   r,   <module>   s   	

	





-{
?
