
    d\1                       d Z 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mZmZ ddlmZ ddlZ	 ddlZn# e$ r dZY nw xY w ej        e          Z G d dej                  Z ej        d	          dd            ZddZ G d d          Z G d de          ZddZ  ej        d	          dd            Z!ddZ"d dZ#ddgZ$dS )!z2
Creates and manages isolated build environments.
    )annotationsN)Callable
Collection)TracebackTypec                      e Zd ZdZeej        dd                        Zeej        dd                        Zej        dd	            Z	d
S )IsolatedEnvzOAbstract base of isolated build environments, as required by the build project.returnstrc                    t           )z1The executable of the isolated build environment.NotImplementedErrorselfs    M/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/build/env.py
executablezIsolatedEnv.executable%   
     "!    c                    t           )z8The scripts directory of the isolated build environment.r   r   s    r   scripts_dirzIsolatedEnv.scripts_dir+   r   r   requirementsCollection[str]Nonec                    t           )z
        Install packages from PEP 508 requirements in the isolated build environment.

        :param requirements: PEP 508 requirements
        r   )r   r   s     r   installzIsolatedEnv.install1   s
     "!r   Nr	   r
   r   r   r	   r   )
__name__
__module____qualname____doc__propertyabcabstractmethodr   r   r    r   r   r   r   "   s        YY" " "  X" " " "  X" 	" " " " " "r   r   )	metaclass)maxsizer	   boolc                 z     dd l  t          d uo-t           fdt          j        d          D                        S )Nr   c              3     K   | ]@}t          |          d k    j                            |d                    j        dk    V  AdS )   
virtualenvN)lenr   Requirementname).0d	packagings     r   	<genexpr>z)_should_use_virtualenv.<locals>.<genexpr>B   sX       . .q66A:: 	**1Q4005E:::. .r   zbuild[virtualenv])packaging.requirementsr+   anybuildcheck_dependency)r1   s   @r   _should_use_virtualenvr7   ;   sf    !!!!
 T! # . . . .'(;<<. . . + + ' r   cmd	list[str]r   c                    	 t          j        | dt           j        t           j                   dS # t           j        $ r:}t          |j                                        dt          j	                   |d}~ww xY w)z;Invoke subprocess and output stdout and stderr if it fails.T)checkstdoutstderr )endfileN)

subprocessrunPIPESTDOUTCalledProcessErrorprintoutputdecodesysr=   )r8   es     r   _subprocessrK   I   su    s$zzGXYYYYYY(   ahooRcj9999s   ,0 A95A44A9c                  B    e Zd ZdZddZddZddZedd            ZdS )IsolatedEnvBuilderz)Builder object for isolated environments.r	   r   c                    d | _         d S N_pathr   s    r   __init__zIsolatedEnvBuilder.__init__U   s    !%


r   r   c                   t           j                            t          j        d                    | _        	 t                      r-|                     d           t          | j                  \  }}n,|                     d           t          | j                  \  }}t          | j        ||| j                  S # t          $ r  | j        t          j                       w xY w)zh
        Create an isolated build environment.

        :return: The isolated build environment
        z
build-env-prefixz+Creating virtualenv isolated environment...z%Creating venv isolated environment...)pathpython_executabler   log)osrV   realpathtempfilemkdtemprQ   r7   rX   _create_isolated_env_virtualenv_create_isolated_env_venv_IsolatedEnvVenvPip	Exception__exit__rI   exc_info)r   r   r   s      r   	__enter__zIsolatedEnvBuilder.__enter__X   s     W%%h&6l&K&K&KLL
	%'' PFGGG*I$**U*U'
KK@AAA*CDJ*O*O'
K&Z",'H	     	 	 	DM3<>>**	s   BB= ='C$exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Nonec                    | j         ?t          j                            | j                   rt	          j        | j                    dS dS dS )a  
        Delete the created isolated build environment.

        :param exc_type: The type of exception raised (if any)
        :param exc_val: The value of exception raised (if any)
        :param exc_tb: The traceback of exception raised (if any)
        N)rQ   rY   rV   existsshutilrmtree)r   rd   rf   rh   s       r   ra   zIsolatedEnvBuilder.__exit__v   sG     :!bgnnTZ&@&@!M$*%%%%% "!!!r   messager
   c                    t           j        dk    r)t                              t          j        | d           dS t                              t          j        |            dS )z
        Prints message

        The default implementation uses the logging module but this function can be
        overwritten by users to have a different implementation.

        :param msg: Message to output
                 )
stacklevelN)rI   version_info_loggerrX   loggingINFO)rn   s    r   rX   zIsolatedEnvBuilder.log   sN     v%%KKg!K<<<<<KKg.....r   N)r	   r   )r	   r   )rd   re   rf   rg   rh   ri   r	   r   )rn   r
   r	   r   )	r   r   r   r    rR   rc   ra   staticmethodrX   r$   r   r   rM   rM   R   sv        33& & & &   <& & & & / / / \/ / /r   rM   c                  j    e Zd ZdZdd
Zedd            Zedd            Zedd            ZddZ	dS )r_   z
    Isolated build environment context manager

    Non-standard paths injected directly to sys.path will still be passed to the environment.
    rV   r
   rW   r   rX   Callable[[str], None]r	   r   c                >    || _         || _        || _        || _        dS )z
        :param path: The path where the environment exists
        :param python_executable: The python executable within the environment
        :param log: Log function
        N)rQ   _python_executable_scripts_dir_log)r   rV   rW   r   rX   s        r   rR   z_IsolatedEnvVenvPip.__init__   s&     
"3'			r   c                    | j         S )z/The location of the isolated build environment.rP   r   s    r   rV   z_IsolatedEnvVenvPip.path   s     zr   c                    | j         S )z8The python executable of the isolated build environment.)r}   r   s    r   r   z_IsolatedEnvVenvPip.executable   s     &&r   c                    | j         S rO   )r~   r   s    r   r   z_IsolatedEnvVenvPip.scripts_dir   s      r   r   r   c           
     R   |sdS |                      d                    d                    t          |                                         t	          j        dddd          5 }|                    t          j                            |                     ddd           n# 1 swxY w Y   	 | j	        d	d
ddddt          j
                            |j                  g}t          |           t          j        |j                   dS # t          j        |j                   w xY w)at  
        Install packages from PEP 508 requirements in the isolated build environment.

        :param requirements: PEP 508 requirement specification to install

        :note: Passing non-PEP 508 strings will result in undefined behavior, you *should not* rely on it. It is
               merely an implementation detail, it may change any time without warning.
        Nz3Installing packages in isolated environment... ({})z, zw+zbuild-reqs-z.txtF)rU   suffixdeletez-Impipr   z--use-pep517z--no-warn-script-locationz-r)r   formatjoinsortedr[   NamedTemporaryFilewriterY   linesepr   rV   abspathr.   rK   unlink)r   r   req_filer8   s       r   r   z_IsolatedEnvVenvPip.install   sN     	F		GNNtyyY_`lYmYmOnOnooppp (mF[`aaa 	:emNN2:??<88999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:	%+..	C Ihm$$$$$BIhm$$$$s   %3B$$B(+B(0A D D&N)
rV   r
   rW   r
   r   r
   rX   r{   r	   r   r   r   )
r   r   r   r    rR   r!   rV   r   r   r   r$   r   r   r_   r_      s            "    X ' ' ' X' ! ! ! X!% % % % % %r   r_   rV   r
   tuple[str, str]c                    t          |           ddddg}t          j        |d          }t          |j        j                  }t          |j        j                  }||fS )z
    We optionally can use the virtualenv package to provision a virtual environment.

    :param path: The path where to create the isolated build environment
    :return: The Python executable and script folder
    z--no-setuptoolsz
--no-wheelz--activatorsr>   F)setup_logging)r
   r+   cli_runcreatorexe
script_dir)rV   r8   resultr   r   s        r   r]   r]      s_     t99'~r
JC5999FV^'((JV^.//Jz!!r   c                 `   t           j                            d          sdS t          j        d          5 } |  d}	 t          j        | j        |           t          j        |           	 ddd           dS # t          t          t          f$ r Y ddd           dS w xY w# 1 swxY w Y   dS )z%Return True if symlinks are supportedwinTzbuild-symlink-rT   z-bNF)rI   platform
startswithr[   r   rY   symlinkr.   r   OSErrorr   AttributeError)tmp_filedests     r   _fs_supports_symlinkr      s    <""5)) t 
	$,<	=	=	= 	Jx}d+++IdOOO        ,n= 	 	 	       	         s.   B#.A::B B#B  B##B'*B'c                *   ddl }ddl}t          j        dk     rddl}nddlm} t                      }	 t          j	                    5  t          j        dd         dk    rt          j
        ddt                     |                    d	|
                              |            ddd           n# 1 swxY w Y   n-# t          j        $ r}t!          j        |d          dd}~ww xY wt%          |           \  }}}t'          t)          |                    d|g                              }	|j                            |	j                  }
t1          j                    dk    rat5          t1          j                    d                             d          d                   dk    rt1          j                    dk    }|rdnd}nd}|
|j                            |          k     rt=          |dddd| g           t=          |dddddg           ||fS )z
    On Python 3 we use the venv package from the standard library.

    :param path: The path where to create the isolated build environment
    :return: The Python executable and script folder
    r   Nrp   )metadatarq   )rq      r   ignorez.check_home argument is deprecated and ignored.T)with_pipsymlinksz7Failed to create venv. Maybe try installing virtualenv.r   )r.   rV   Darwin.r   x86_64z21.0.1z20.3.0z19.1.0z-mr   zpip>=	uninstall
setuptoolsz-y)venvpackaging.versionrI   ru   importlib_metadata	importlibr   r   warningscatch_warningsfilterwarningsDeprecationWarning
EnvBuildercreaterA   rE   r5   FailedProcessError_find_executable_and_scriptsnextiterdistributionsversionVersionr   systemintmac_versplitmachinerK   )rV   r   r1   r   r   excr   r   purelibpip_distributioncurrent_pip_versionis_apple_silicon_pythonminimum_pip_versions                r   r^   r^      s    KKK
&  -----&&&&&&#%%Hq$&& 	K 	K#z11'2bdvwwwOOTHO==DDTJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K ( q q q&s,efflppq 'C4&H&H#J
G D!7!7U'!7!S!STTUU#+334D4LMMH$$X-=-?-?-B-H-H-M-Ma-P)Q)QUW)W)W #+"2"4"4"@*AOhhx 'Y.667JKKKKZui9VAT9V9VWXXX T5+|TJKKKz!!s<   B< AB0$B< 0B44B< 7B48B< <C&C!!C&tuple[str, str, str]c                \   t          j                                                    }| |d<   t          j                    }d|v rt          j        d|          }nKd|v rt          j        d|          }n0d|v rt          j        d|          }nt          j        |          }t
          j                            |d         t          j	        
                    d	          rd
nd          }t
          j                            |          st          d| d          ||d         |d         fS )z
    Detect the Python executable and script folder of a virtual environment.

    :param path: The location of the virtual environment
    :return: The Python executable, script folder, and purelib folder
    baser   )schemevarsposix_localposix_prefixosx_framework_library)r   scriptsr   z
python.exepythonz0Virtual environment creation failed, executable z missingr   )	sysconfigget_config_varscopyget_scheme_names	get_pathsrY   rV   r   rI   r   r   rk   RuntimeError)rV   config_varsscheme_namespathsr   s        r   r   r   +  s2    +--2244KK-//L #6DDD	,	&	& #>LLL	 L	0	0 #>LLL#555eI.@W@WX]@^@^0ldlmmJ7>>*%% dbjbbbcccuY'y)999r   )r	   r'   )r8   r9   r	   r   )rV   r
   r	   r   )rV   r
   r	   r   )%r    
__future__r   r"   	functoolsrw   rY   r   rl   rA   rI   r   r[   r   collections.abcr   r   typesr   r5   r+   ModuleNotFoundError	getLoggerr   rv   ABCMetar   	lru_cacher7   rK   rM   r_   r]   r   r^   r   __all__r$   r   r   <module>r      sb    # " " " " " 



      				       



       0 0 0 0 0 0 0 0          JJJ '
H
%
%" " " " "CK " " " "2 T"""
 
 
 #"
   >/ >/ >/ >/ >/ >/ >/ >/BE% E% E% E% E%+ E% E% E%P" " " " T"""   #""-" -" -" -"`&: &: &: &:T s   A AA