
    $TXg                        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 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dddZddZ eddd      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)_StoreTrueAction)partial)Path)TYPE_CHECKING)
deprecatedCondaEnvException)is_conda_environment)ArgumentParser	Namespace_SubParsersActionc                J   ddl m} ddlm}m} d} |d| d      } |d      } | j
                  	 d|||d	|} ||       |j                  d
d       |j                  ddddt        j                  ddt        d      d        ||       |j                  d       |S )N   )dals   )add_output_and_prompt_options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-fz--forceyeszForce rename of an environment.z24.925.3zUse `--yes` instead.addendumF)destr   actiondefaultzconda.cli.main_rename.execute)func)rename)
auxlib.ishr   helpersr   r   
add_parseradd_argumentr   r   r   set_defaults)	sub_parserskwargsr   r   r   summaryr   r   ps	            5lib/python3.12/site-packages/conda/cli/main_rename.pyconfigure_parserr,      s    !I/G			 			K 	F 				
 	A aNN='LNMNN.  +	
    "!$NN7N8H    c                `    t        t        |       j                        rt        d|  d|      y)zBEnsure that the new prefix does not contain protected directories.zThe specified prefix 'aB  ' appears to be a top level directory within an existing conda environment (i.e., {history_file} exists). Creating an environment in this location has the potential to irreversibly corrupt your conda installation and/or other conda environments, please choose a different location for your new conda environment. Aborting.N)r   r   parentr
   )prefixjsons     r+   check_protected_dirsr2   V   s>     DL//0$VH -/ / 
 	
 1r-   c                 0   ddl m}  ddlm} t	        | j
                        } ||       |j                  | j                        rt        d      | j                  r&|j                  | j                        rt        d      t        |       t        |      S )z
    Ensure that we are receiving at least one valid value for the environment
    to be renamed and that the "base" environment is not being renamed
    r   contextr   )validate_prefix_existsz(The 'base' environment cannot be renamedz$Cannot rename the active environment)base.contextr5   installr6   r   target_prefixsamefileroot_prefixr
   active_prefixr2   str)r5   r6   r0   s      r+   validate_srcr>   e   sx    
 '/'''(F6"w**+ JKK1F1F!G FGGV$v;r-   r   z25.9z4Use `conda.cli.install.validate_new_prefix` instead.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   )r5   validate_prefix_name)expandr	   F)ctx
allow_basezThe environment 'z&' already exists. Override with --yes.)r7   r5   r@   common.pathrA   
exceptionsr
   osseppathexistsbasenamenormpath)r   forcer5   r@   rA   r
   env_names          r+   validate_destinationrN   z   s     =$.	vv~d|#Dg%HRWW^^D)77##BGG$4$4T$:;z)OP
 	
 Kr-   c                J   	
 ddl m ddlm ddlm ddlm	 ddlm	} ddlm
} 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_PREFIXr4   )r8   )rm_rf)rename_contextr   )validate_new_prefix)rL   c            
     0   t        j                  j                  j                        t              f} | D ]V  }j                  rAt         d|j                  j                   ddj                  |j                                P |        X y )N)quietr1    ,)
r   clonerU   r1   dry_runprintr    __name__joinargs)	actionsr    rP   r]   r5   r   r8   rQ   sources	     r+   clone_and_removez!execute.<locals>.clone_and_remove   s    mm\\ E6"	(
 D||($))*<*<)=Qsxx		?R>STU	 r-   )rY   Nr   )returnNone)base.constantsrP   r7   r5   clir8   gateways.disk.deleterQ   gateways.disk.updaterR   rS   r>   r   r   rY   )r]   parserrR   rS   r`   rP   r5   r   r8   rQ   r_   s   `    @@@@@@r+   executerh      sy    /&,5,^F%d&6&6dhhGK & xxK> ?  		 ? s    BB")r'   r   ra   r   )F)r0   z
str | Pathr1   boolra   rb   )ra   r=   )r   r=   rL   ri   ra   r=   )r]   r   rg   r   ra   int)__doc__
__future__r   rF   argparser   	functoolsr   pathlibr   typingr   conda.deprecationsr   conda.exceptionsr
   conda.gateways.disk.testr   r   r   r   r,   r2   r>   rN   rh    r-   r+   <module>ru      sg   
 # 	 %     ) . 9EE;|
* 

C

$$r-   