
    wBfb                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ e	r
dd	lmZmZmZ dd
Z ej"                  ddd       ej"                  ddd      dd              ZdddZddZy)zCLI implementation for `conda rename`.

Renames an existing environment by cloning it and then removing the original environment.
    )annotationsN)partial)Path)TYPE_CHECKING   )
deprecated)ArgumentParser	Namespace_SubParsersActionc                (   ddl m} ddlm} d} |d| d      } |d      } | j                  	 d|||d	|} ||       |j                  d
d       |j                  dddd       |j                  ddddd       |j                  d       |S )Nr   )dals   )add_parser_prefixzRename an existing environment.z	
        z

        This command renames a conda environment via its name (-n/--name) or
        its prefix (-p/--prefix).

        The base environment and the currently-active environment cannot be renamed.
        z
        Examples::

            conda rename -n test123 test321

            conda rename --name test123 test321

            conda rename -p path/to/test123 test321

            conda rename --prefix path/to/test123 test321

        )helpdescriptionepilogdestinationz#New name for the conda environment.)r   z--forcezForce rename of an environment.
store_trueF)r   actiondefaultz-dz	--dry-runzZOnly display what would have been done by the current command, arguments, and other flags.zconda.cli.main_rename.execute)func)rename)
auxlib.ishr   helpersr   
add_parseradd_argumentset_defaults)sub_parserskwargsr   r   summaryr   r   ps           5lib/python3.12/site-packages/conda/cli/main_rename.pyconfigure_parserr#      s    !*/G			 			K 	F 				
 	A aNN='LNMNN.	   NN   NN7N8H    z24.3z24.9nameprefixc                 0   ddl m}  ddlm} t	        | j
                        }|j                         s |d      |j                  | j                        r |d      | j                  r#|j                  | j                        r |d      | j
                  S )z
    Validate that we are receiving at least one valid value for --name or
    --prefix and ensure that the "base" environment is not being renamed
    r   contextCondaEnvExceptionz8The environment you are trying to rename does not exist.z(The 'base' environment cannot be renamedz$Cannot rename the active environment)
base.contextr)   
exceptionsr+   r   target_prefixexistssamefileroot_prefixactive_prefix)r)   r+   r&   s      r"   validate_srcr3   R   s     '.'''(F==?F
 	
 w**+ JKK1F1F!G FGG   r$   c                L   ddl m}m} ddlm} ddlm} t        j                  | v r	 ||       } n || |d      } |sgt        j                  j                  |       rHt        j                  j                  t        j                  j                  |             } |d| d      | S )	z*Ensure that our destination does not existr   )r)   validate_prefix_name)expandr*   F)ctx
allow_basezThe environment 'z(' already exists. Override with --force.)r,   r)   r5   common.pathr6   r-   r+   osseppathr/   basenamenormpath)destforcer)   r5   r6   r+   env_names          r"   validate_destinationrB   i   s    <$.	vv~d|#Dg%HRWW^^D)77##BGG$4$4T$:;z)QR
 	
 Kr$   c                D   	 ddl m ddlm ddlm ddlm ddlm	} t               	t         j                   j                        d 	fd} j                  r% | j                  	      5   |        d
d
d
       y |        y# 1 sw Y   yxY w)z:Executes the command for renaming an existing environment.r   )DRY_RUN_PREFIXr(   )install)rm_rf)rename_context)r@   c            
     0   t        j                  j                  j                        t              f} | D ]V  }j                  rAt         d|j                  j                   ddj                  |j                                P |        X y )N)quietjson ,)
r   clonerI   rJ   dry_runprintr   __name__joinargs)	actionsr   rD   rR   r)   r   rE   rF   sources	     r"   clone_and_removez!execute.<locals>.clone_and_remove   s    mm\\ E6"	(
  	D||($))*<*<)=Qsxx		?R>STU		r$   )rN   Nr   )returnNone)base.constantsrD   r,   r)   clirE   gateways.disk.deleterF   gateways.disk.updaterG   r3   rB   r   r@   rN   )
rR   parserrG   rU   rD   r)   r   rE   rF   rT   s
   `   @@@@@@r"   executer]   |   s{    /&,5^F&t'7'7tzzJK & zzK> 		  			 s   =BB)r   r   rV   r	   )rV   str)F)r?   r^   r@   boolrV   r^   )rR   r
   r\   r	   rV   int)__doc__
__future__r   r:   	functoolsr   pathlibr   typingr   deprecationsr   argparser	   r
   r   r#   argumentr3   rB   r]    r$   r"   <module>rj      su   
 # 	     %EE:z VVV,VVX.! / -!*&#r$   