
    Pi                         d dl Z d dlZd dlZd dlmZ d dlZd dlmZ d dlm	Z	  eej
                  j        j        Z G d de          ZdS )    N)Path)
Subcommand)get_all_recipesc                   @     e Zd ZdZ fdZddZdej        fdZ xZ	S )	Copyz1Holds all the logic for the `tune cp` subcommand.c           
      *   t                                                       |                    dddddt          j        d          t
          j                  | _        |                                  | j        	                    | j
                   d S )Ncpztune cpz-tune cp <recipe|config> destination [OPTIONS]z1Copy a built-in recipe or config to a local path.a              examples:
                $ tune cp lora_finetune_distributed .
                Copied file to ./lora_finetune_distributed.py

                $ tune cp llama2/7B_full ./new_dir/my_custom_lora.yaml --make-parents
                Copyied file to ./new_dir/my_custom_lora.yaml

            Need to see all possible recipes/configs to copy? Try running `tune ls`.
            )progusagehelpdescriptionepilogformatter_class)func)super__init__
add_parsertextwrapdedentargparseRawTextHelpFormatter_parser_add_argumentsset_defaults_cp_cmd)self
subparsers	__class__s     e/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/_cli/cp.pyr   zCopy.__init__   s    !,,ADK?	  %9% - 
 
( 	!!t|!44444    returnNc                    | j                             dt          d           | j                             dt          d           | j                             dddd	d
           | j                             dddd
           dS )zAdd arguments to the parser.filezHRecipe/config to copy. For a list of all possible options, run `tune ls`)typer   destinationzLocation to copy the file toz-nz--no-clobber
store_truez1Do not overwrite destination if it already existsF)actionr   defaultz--make-parentszCreate parent directories for destination if they do not exist. If not set to True, will error if parent directories do not existN)r   add_argumentstrr   )r   s    r   r   zCopy._add_arguments.   s    !![ 	" 	
 	
 	

 	!!/ 	" 	
 	
 	

 	!!D 	" 	
 	
 	
 	!!P 	" 	
 	
 	
 	
 	
r    argsc                    |j         }d}t                      D ][}|j        |j        k    rt          dz  |j        z  }d} n4|j        D ]+}|j        |j        k    rt          dz  dz  |j        z  }d} n,\|#| j                            d|j         d           |j        dk    r |j	        |k    r|
                    |          }	 |j        r;|                                r't          d	|                                 d
           dS |j        r|j                            dd           t%          j        ||          }t          d|            dS # t(          $ r" | j                            d| d           Y dS w xY w)z*Copy a recipe or config to a new location.Nrecipesz.pyconfigsz.yamlzInvalid file name: z3. Try `tune ls` to see all available files to copy. zFile already exists at z, not overwriting.T)parentsexist_okzCopied file to zCannot create regular file: 'z'. No such file or directory. If the specified destination's parent directory does not exist and you would like to create it on-the-fly, use the --make-parents flag.)r%   r   namer#   ROOT	file_pathr.   r   errorsuffixwith_suffix
no_clobberexistsprintabsolutemake_parentsparentmkdirshutilcopyFileNotFoundError)r   r+   r%   srcrecipeproper_suffixconfigoutputs           r   r   zCopy._cp_cmdI   s    , &'' 		 		F{di''Y&)99 % .  ;$)++*Y69IIC$+ME , ;Lddiddd  
 r!!k&8M&I&I%11-@@K	 2;#5#5#7#7 2Xk.B.B.D.DXXX     $ J&,,TD,IIIS+6600011111  	 	 	LM M M M     	s   A E A
E (E?>E?)r!   N)
__name__
__module____qualname____doc__r   r   r   	Namespacer   __classcell__)r   s   @r   r   r      sp        ;;5 5 5 5 52
 
 
 
6+H. + + + + + + + +r    r   )r   r?   r   pathlibr   	torchtunetorchtune._cli.subcommandr   torchtune._recipe_registryr   __file__r=   r3   r    r    r   <module>rS      s                 0 0 0 0 0 0 6 6 6 6 6 6tI&-b b b b b: b b b b br    