o
    ˷eL                     @   s   d 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	 dd Z
dd Zh d	Zh d
Zh dZddhZeG dd deZdS )z5Implementation of packaging-related magic functions.
    N)Path)Magicsmagics_class
line_magicc                   C   s   t tjdd S )z>Return True if the current Python executable is in a conda env
conda-metahistory)r   sysprefixexists r   r   T/var/www/ideatree/venv/lib/python3.10/site-packages/IPython/core/magics/packaging.py_is_conda_environment   s   r   c                  C   s\   t tjjd } |  rt| S t tjddjdd}tj	d|tj
d}|r,| d S dS )	z%Find the path to the conda executablecondar   r   zutf-8)encodingz2^#\s*cmd:\s*(?P<command>.*conda)\s[create|install])flagscommand)r   r   
executableparentis_filestrr	   	read_textresearch	MULTILINE	groupdict)r   r   matchr   r   r   _get_conda_executable   s   r   >   listremoveupdateinstallupgrade	uninstall>   r   r   r    r!   r"   >   -n-p--name--prefixz-yz--yc                   @   s(   e Zd ZdZedd Zedd ZdS )PackagingMagicsz*Magics related to packaging & installationc                 C   sN   t j}t jdkrd| d }nt|}| jd|dd|g td dS )zmRun the pip package manager within the current kernel.

        Usage:
          %pip install [pkgs]
        win32" z-mpipzANote: you may need to restart the kernel to use updated packages.N)	r   r   platformshlexquoteshellsystemjoinprint)selflinepythonr   r   r   r+   >   s   

zPackagingMagics.pipc                 C   s   t  stdt }t|}t|dkr|d nd}t|dkr'|dd ndg}g }t| jdddu}|tv }t	|
t}|rK|rK|sK|d |tv }	t	|
t}
|	rb|
sb|dtjg | jd	||g| |  td
 dS )zqRun the conda package manager within the current kernel.

        Usage:
          %conda install [pkgs]
        zbThe python kernel does not appear to be a conda environment.  Please use ``%pip install`` instead.r       Nkernelz--yesr&   r*   zB
Note: you may need to restart the kernel to use updated packages.)r   
ValueErrorr   r-   splitlengetattrr/   CONDA_COMMANDS_REQUIRING_YESsetintersectionCONDA_YES_FLAGSappendCONDA_COMMANDS_REQUIRING_PREFIXCONDA_ENV_FLAGSextendr   r	   r0   r1   r2   )r3   r4   r   argsr   
extra_argsstdin_disabled	needs_yeshas_yesneeds_prefix
has_prefixr   r   r   r   O   s$   

zPackagingMagics.condaN)__name__
__module____qualname____doc__r   r+   r   r   r   r   r   r'   :   s    
r'   )rO   r   r-   r   pathlibr   IPython.core.magicr   r   r   r   r   rB   r=   rC   r@   r'   r   r   r   r   <module>   s    
