
    .Ph@,                        U 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	 d dl
mZmZmZmZmZmZmZ d dlmZmZ d dlmZ d dlmZ  e	e          Zeeej        f         Zdaee         ed<   da ee         ed<   	 	 	 	 d&d
e!de!de!de!deej                 f
dZ"dee         d
e!de!deee                  fdZ#dee         d
e!de!defdZ$g d	fdedddddee         dee         de!dej%        fdZ&dee         dee         fdZ'dee         de(e         fdZ)dedeeef         fdZ*d ee         dedee         fd!Z+defd"Z,defd#Z-d'd$Z.dede!fd%Z/dS )(    N)	getLogger)IODictIteratorListOptionalSequenceUnion)determine_micromamba_versionensureconda)Version)ChannelCONDA_PKGS_DIRSMAMBA_ROOT_PREFIXFmamba
micromambaconda	conda_exereturnc                 X    t          | |||          }|d S t          j        |          S )Nr   r   r   r   )r   pathlibPath)r   r   r   r   
_conda_exes        W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/conda_lock/invoke_conda.py_ensurecondar      sA     	  J t<
###    conda_executablec              #      K   | r@t          j        |                                           r| V  t          j        |           V  t          ||dd          V  d S )NTr   )r   r   existsshutilwhichr   )r   r   r   s      r   _determine_conda_executabler#   .   sv        -<())0022 	#""""l+,,,,,
UzQU
V
V
VVVVVVr   c                     t          | ||          D ]R}|Nt          |          r;t          t          |                    t	          d          k     rt                       |c S St          d          )Nz0.17z/Could not find conda (or compatible) executable)r#   is_micromambar   strr   mamba_root_prefixRuntimeError)r   r   r   	candidates       r   determine_conda_executabler*   9   s     11A5*UU  	 Y'' (/I??'&//QQ%'''	 !
 H
I
IIr   prefixz
str | Nonenamecommand_args	post_args
check_callc                 F   |r|rt          d          g }|r+|                    d           |                    |           n<|r+|                    d           |                    |           nt          d          t          j                            d          }|r'|                    t          j        |                     d | g|||D             }t          	                    dt          j
        |                      t          j        |t          j        t          j        dd	d
          5 g d}	j        r0dfd}
t          j        |
          }	|	                                 j        rt'          j                  }|	r|	
                                 ddd           n# 1 swxY w Y   |rbj        dk    rWt          j        j        t-          |           g|||d
                              d
                    |                    S )a  
    Invoke external conda executable

    Parameters
    ----------
    conda :
        Path to conda, mamba, or micromamba
    prefix :
        Prefix of target env
    name :
        Name of target env
    command_args :
        Arguments to conda executable
    post_args :
        Optional arguments to append to command_args
    check_call :
        If True, raise CalledProcessError if conda returns != 0

    z-Provide either prefix, or name, but not both.z--prefixz--namez"Neither prefix, nor name provided.CONDA_FLAGSc                 ,    g | ]}t          |          S  )r&   ).0args     r   
<listcomp>z!_invoke_conda.<locals>.<listcomp>o   s    
P
P
P3s88
P
P
Pr   zInvoking command:    Tzutf-8)stdoutstderrbufsizeuniversal_newlinesencodingNr   c                      j         J t          j                   D ]+} t          j        |                                |            ,d S N)r8   _process_stdoutlogginginfoappend)linepr8   s    r   read_stdoutz"_invoke_conda.<locals>.read_stdout   sY    x++++AH55 ( (DL&&&MM$''''( (r   )targetr   
)outputr9   r   N)
ValueErrorrB   osenvirongetextendshlexsplitloggerdebugjoin
subprocessPopenPIPEr8   	threadingThreadstartr9   _stderr_to_log
returncodeCalledProcessErrorr&   )r   r+   r,   r-   r.   r/   common_argsconda_flagscmdstdout_threadrE   r9   rD   r8   s               @@r   _invoke_condara   E   s   6  J$ JHIIIK ?:&&&6""""	 ?8$$$4    =>>>*..//K 55;{33444
P
POO{OYO
P
P
PC
LL7ejoo77888		
 
 
 ! 

 8 		"( ( ( ( ( ( ( &,K@@@M!!!8 	.#AH--F 	!   7! ! ! ! ! ! ! ! ! ! ! ! ! ! !:  
ala''+LZZA,AAyA99V$$99V$$	
 
 
 	
 Hs   9A-F22F69F6r8   c              #     K   t                      }d}d}| D ]i}|                                }|rd}|dk    rd}|s|s|r)d|v r8|                                d         }||vr|V  |                    |           e|V  jd S )NFTz#Downloading and Extracting Packages%r   )setrstriprP   add)r8   cacheextracting_packagesleading_emptyloglines        r   r?   r?      s      EEEM  .."" 	"!M;;;"& 	/ 	= 	'>>mmooa(Ge##		'"""MMMM r   r9   c                 F   t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        d}g }t          j                            d          }|rXt          t           |          }| D ]>}t          j
        ||                                           |                    |           ?|S t          t           t          j                            dd                    }|}| D ]q}|dd         }||v r	||         }n|                    d          r|}n|}t          j
        ||                                           |                    |           |}r|S )a;  Process and log stderr output from a subprocess with configurable log levels.

    This function processes stderr output line by line, applying different log levels
    based on the content and context of each line. The log level for non-warning lines
    can be configured via an environment variable.

    Rules for log levels:
    1. If CONDA_LOCK_SUBPROCESS_STDERR_LOG_LEVEL_OVERRIDE is set, all lines are logged
       at that level, regardless of content
    2. Otherwise:
       a. Lines starting with a known log level prefix are logged at that level:
          - mamba style: "debug    ", "info     ", "warning  ", etc.
          - conda style: "DEBUG conda.core", "INFO conda.fetch", etc.
       b. Indented lines (starting with spaces) inherit the previous line's log level
       c. All other lines are logged at the configured default level, which can be set via
          the `CONDA_LOCK_SUBPROCESS_STDERR_DEFAULT_LOG_LEVEL` environment variable
       d. If no default level is configured, non-warning lines are logged at ERROR level

    Example of warning detection and indentation inheritance:
        warning  libmamba [foo-1.2.3] The following files were already present
            - lib/python3.10/site-packages/package/__init__.py
        Some other message  # This resets to the default level
        DEBUG conda.gateways.subprocess:subprocess_call(86): ... # conda-style log

    Args:
        stderr: A file-like object containing the stderr output to process

    Returns:
        A list of the original lines, preserving trailing newlines

    Environment Variables:
        CONDA_LOCK_SUBPROCESS_STDERR_LOG_LEVEL_OVERRIDE: If set, all lines will be logged
            at this level, regardless of content. Must be a valid Python logging level
            name (DEBUG, INFO, WARNING, ERROR, CRITICAL).
        CONDA_LOCK_SUBPROCESS_STDERR_DEFAULT_LOG_LEVEL: The log level to use for
            non-warning lines when no override is set. Must be a valid Python logging
            level name (DEBUG, INFO, WARNING, ERROR, CRITICAL). Defaults to ERROR if
            not set.
    )z	trace    z	debug    z	info     z	warning  z	error    z	critical z	DEBUG conz	INFO condz	WARNING cz	ERROR conz	CRITICAL /CONDA_LOCK_SUBPROCESS_STDERR_LOG_LEVEL_OVERRIDE.CONDA_LOCK_SUBPROCESS_STDERR_DEFAULT_LOG_LEVELERRORN	   z  )r@   DEBUGINFOWARNINGrn   CRITICALrK   rL   rM   getattrlogre   rB   
startswith)	r9   LOG_LEVEL_INDICATORSlinesoverride_level	log_levelrC   default_log_levelprevious_levelpossible_mamba_log_levels	            r   rZ   rZ      s   V ]]\_]%]\_]% " EZ^^$UVVN G^44	 	 	DK	4;;==111LL  

GQQ  'N # ##'8 #';;;,-EFII__T"" 	*&II)I 	It{{}}---T"Lr   platformc                     t          t          j                  }|                    | t	                      ddd           |S )N0False)CONDA_SUBDIRr   %CONDA_UNSATISFIABLE_HINTS_CHECK_DEPTH"CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY)dictrK   rL   updateconda_pkgs_dir)r~   envs     r   conda_env_overrider     sJ    
rz

CJJ$-//5829		
 	
   Jr   channelsc                 p   g }t           j                            d          }|r'|                    t	          j        |                     | r|                    d           | D ]Q}|                    d|                                g           |j        dk    r|dv r|                    ddg           R|S )Nr1   z--override-channelsz	--channeldefaults>   win-32win-64msys2)	rK   rL   rM   rN   rO   rP   rB   env_replaced_urlurl)r   r~   argsr^   channels        r   _get_conda_flagsr     s    D*..//K .EK,,--- +)*** 0 0['":":"<"<=>>>;*$$5I)I)I
 KKg.///Kr   c                      t           :t          j                    } | j        a t	          j        | j                   t           S t           S r>   )r   tempfileTemporaryDirectoryr,   atexitregistercleanuptemp_dirs    r   r   r   ,  s<    .00"-()))r   c                      t           Nt          j                    } | j        a t	          j        | j                   t           t          j        d<   t           S t           S )z%Legacy root prefix used by micromambaNr   )	r   r   r   r,   r   r   r   rK   rL   r   s    r   r'   r'   7  sL      .00$M()))*;
&'    r   c                  ~    da dadt          j        v rt          j        d= dt          j        v rt          j        d= dS dS )zFClear the fake conda packages directory.  This is used only by testingNr   r   )r   r   rK   rL   r3   r   r   reset_conda_pkgs_dirr   D  sM     OBJ&&J()bj((J*+++ )(r   c                     t          |                               d          p3t          |                                                               d          S )Nr   zmicromamba.exe)r&   endswithlower)r   s    r   r%   r%   P  sJ    u::|,, E

0@0@0B0B0K0K1 1 r   )FFFFrI   )0r   r@   rK   r   rO   r!   rT   r   rW   r   typingr   r   r   r   r   r	   r
   ensureconda.apir   r   packaging.versionr   conda_lock.models.channelr   __name__rQ   r&   r   PathLiker   __annotations__r   boolr   r#   r*   rU   ra   r?   listrZ   r   r   r   r'   r   r%   r3   r   r   <module>r      s     				                   F F F F F F F F F F F F F F F F F F E E E E E E E E % % % % % % - - - - - - 
8		gl"#!%# % % %#' 8C= ' ' ' 	$ $$$ $ 	$
 gl$ $ $ $$Wx(W15WCGWhx !W W W W	Jx(	J15	JCG	J	J 	J 	J 	J" %'R RRR R 8$	R
 !R R R R R RjBsG     *Z2c7 ZtCy Z Z Z Zz
 
c3h 
 
 
 
x0 C DI    &    
!3 
! 
! 
! 
!	, 	, 	, 	, d      r   