U
    bk	                     @  s   d dl mZ d dlmZ d dlZddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddddddZdddddddZdd ZdS )    )annotations)partialN   )contextlocate_prefix_by_namevalidate_prefix_name)DRY_RUN_PREFIX)commoninstall)expandpaths_equal)CondaEnvException)rm_rf)rename_contextz
str | Nonestr)nameprefixreturnc                 C  s8   t tjtjrtd| p|}t|r0tdt|S )z
    Validate that we are receiving at least one value for --name or --prefix
    and ensure that the "base" environment is not being renamed
    z(The 'base' environment cannot be renamedz$Cannot rename the active environment)r   r   Ztarget_prefixZroot_prefixr   r	   Zis_active_prefixr   )r   r    r   4lib/python3.8/site-packages/conda/cli/main_rename.pyvalidate_src   s    
r   Fbool)destforcer   c                 C  sZ   t j| krt| } nt| tdd} |sVt j| rVt jt j| }t	d| d| S )z*Ensure that our destination does not existF)ZctxZ
allow_basezThe environment 'z(' already exists. Override with --force.)
ossepr   r   r   pathexistsbasenamenormpathr   )r   r   Zenv_namer   r   r   validate_destination"   s    


r    c              	     s`   t  j jt j jd fdd} jrVt jd |  W 5 Q R X n|  dS )zC
    Executes the command for renaming an existing environment
    )r   c               	     sb   t tjtjtjdt tf} | D ]6} jrVtt	 d|j
j dd|j  q&|  q&d S )N)quietjson ,)r   r
   Zcloner   r!   r"   r   dry_runprintr   func__name__joinargs)Zactionsr'   r*   destinationsourcer   r   clone_and_remove8   s    &z!execute.<locals>.clone_and_remove)r%   N)r   r   r   r    r,   r   r   r%   )r*   _r.   r   r+   r   execute1   s    r0   )F)Z
__future__r   	functoolsr   r   Zbase.contextr   r   r   Zbase.constantsr   Zclir	   r
   Zcommon.pathr   r   
exceptionsr   Zgateways.disk.deleter   Zgateways.disk.updater   r   r    r0   r   r   r   r   <module>   s   