
    G@dY                         d Z ddlZddlZddlmZ ddlZddlmZm	Z	m
Z
 ddlmZ ej        dk    Zi ad ZddZdd	Zdd
ZddZd Zd Zd ZdS )zConda/anaconda utilities.    N)find_programrun_programrun_shell_command)get_spyder_umamba_pathntc                 H    d| v rd| vrdnd}d                     ||           S )z+Return quotes if needed for spaces on path. " z{quotes}{path}{quotes})quotespath)format)r   r   s     2lib/python3.11/site-packages/spyder/utils/conda.py
add_quotesr      s4    4KKCtOOSSF#**&t*DDD    c                 (   ||                     dd          }| || r|rt          d          |r%| #t          |                               dd          } t          j                            t          j                            | d                    S )z@Check if prefix or python executable are in a conda environment.N\/z-Only `prefix` or `pyexec` should be provided!z
conda-meta)replace
ValueErrorget_conda_env_pathosr   existsjoin)prefixpyexecs     r   is_conda_envr      s    c**6>v>&>HIII ?&.#F++33D#>>7>>"',,v|<<===r   Fc                    | t           j        }nt          |           }|                    dd          }d}|                    |          dk    r|                    |          d         }n|}|rt          |          }|S )z~
    Return conda prefix from pyexec path

    If `quote` is True, then quotes are added if spaces are found in the path.
    Nr   r   z/envs/r   )sysr   r   r   rfindsplitr   )r   quoteconda_env_prefixenv_keyroot_prefixs        r   get_conda_root_prefixr'   *   s     ~:-f55'//c::Gg&&",,&,,W55a8& . --r   c                 n   t                      pt                      }t          j        |                              d          r|}nGt          j        t          j        |                    }t          rd}nd}t          j        ||          }|                    dd          }| rt          |          }|S )z
    Return full path to conda activation script.

    If `quote` is True, then quotes are added if spaces are found in the path.
    
micromambazScripts/activatezbin/activater   r   )
r   
find_condaospbasename
startswithdirnameWINDOWSr   r   r   )r#   exescript_pathconda_exe_rootactivates        r   get_conda_activation_scriptr4   C   s     !
"
"
2jllC
|C##L11 
9 S[%5%566 	&)HH%Hh~x88%%dC00K . --r   c                 ,   |                      dd          } t          j        dk    r t          j                            |           }n<t          j                            t          j                            |                     }|rt          |          }|S )z
    Return the full path to the conda environment from give python executable.

    If `quote` is True, then quotes are added if spaces are found in the path.
    r   r   r   )r   r   namer   r.   r   )r   r#   	conda_envs      r   r   r   `   ss     ^^D#&&F	w$GOOF++		GOOBGOOF$;$;<<	 *y))	r   c                      t           j                            d          pt           j                            d          } | t          rdnd}t	          |          } | S )zFind conda executable.	CONDA_EXE	MAMBA_EXENz	conda.batconda)r   environgetr/   r   )r;   
conda_execs     r   r*   r*   r   sO     JNN;''F2:>>++F+FE}$+8[[
Z((Lr   c                     i } t                      }|| S d                    |dddg          }	 t          |i                                           \  }}|                                }t          j        |          }n# t          $ r dg i}Y nw xY w|d         D ](}|                    t          j
                  d         }t          rt          j        |d	          nt          j        |d
d          }	 t          |dg                                          \  }}|                                }n# t          $ r d}Y nw xY w|                                                    d          s'|                                                    d          rdn|}d                    |          }||                                f| |<   *| a| S )z6Return the list of all conda envs found in the system.Nr	   envlistz--json)r@   envsr   z
python.exebinpythonz	--versionr   anaconda	minicondabasez	conda: {})r*   r   r   communicatedecodejsonloads	Exceptionr"   r+   sepr/   r   lowerr-   r   stripCONDA_ENV_LIST_CACHE)	env_listr;   cmdstrout__r@   r6   r   versions	            r   get_list_conda_envsrV   }   s    HLLE}XXueVX677F#F333??AARjjlljoo   rl 6{ 1 1yy!!"%.5 "sx\***38<" <"	%d[M::FFHHKGRnn&&GG 	 	 	GGG	 **,,11*== ?

''44?:> 	!!$''0#Os$   AA> >BB5:D00D?>D?c                      t           S )z5Return a cache of envs to avoid computing them again.)rP    r   r   get_list_conda_envs_cacherY      s    r   )NN)NF)F)__doc__rJ   r   os.pathr   r+   r    spyder.utils.programsr   r   r   spyder.config.baser   r6   r/   rP   r   r   r'   r4   r   r*   rV   rY   rX   r   r   <module>r^      s       				       



 N N N N N N N N N N 5 5 5 5 5 5
'T/ E E E> > > >   2   :   $  " " "J         r   