
    lj)              	          U 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	m
Z
 ddlZddl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mZ dZded<   g dZded<   g dZd?dZ	 d@dAdZ dBdZ!dCd!Z" ej#        ed"d"ed#$          ej$        dDd(                        Z%e%&                    ed")           ej'        d*d+ ej(        d,d-gd.          d-d/0           ej'        d1d2d3d"4          dEdFd7                                    Z)e%&                    e8          dGd9            Z*e%&                    e8           ej'        d:d; ej+                    <          ej$        dHd>                                    Z,dS )IzManim's cfg subcommand.

Manim's cfg subcommand is accessed in the command-line interface via ``manim
cfg``. Here you can specify options, subcommands, and subgroups for the cfg
group.

    )annotationsN)literal_eval)Path)Anycast)StyleSyntaxError)Style)cli_ctx_settingsconsole)config_file_pathsmake_config_parser)EPILOG)guarantee_existence	open_filez
[red]The default colour is used by the input statement.
If left empty, the default colour will be used.[/red]
[magenta] For a full list of styles, visit[/magenta] [green]https://rich.readthedocs.io/en/latest/style.html[/green]
strRICH_COLOUR_INSTRUCTIONS)z	log.widthz
log.heightzlog.timestampsz	list[str]RICH_NON_STYLE_ENTRIES)value_from_stringr   is_valid_stylereplace_keyscfgwriteshowexportvaluereturnstr | int | boolc                    t          j        t          t                    5  t	          |           } ddd           n# 1 swxY w Y   | S )a  Extract the literal of proper datatype from a ``value`` string.

    Parameters
    ----------
    value
        The value to check get the literal from.

    Returns
    -------
    :class:`str` | :class:`int` | :class:`bool`
        The literal of appropriate datatype.
    N)
contextlibsuppressSyntaxError
ValueErrorr   )r   s    N/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/cli/cfg/group.pyr   r   ,   s~     
	[*	5	5 $ $U##$ $ $ $ $ $ $ $ $ $ $ $ $ $ $Ls   <A A Fexpectedvalidate_styleboolc                    t          |           }t          t          |                    }t          ||          o'|r$t          |t                    ot	          |          ndS )a  Check whether the literal from ``value`` is the same datatype as the
    literal from ``expected``. If ``validate_style`` is ``True``, also check if
    the style given by ``value`` is valid, according to ``rich``.

    Parameters
    ----------
    value
        The string of the value to check, obtained from reading the user input.
    expected
        The string of the literal datatype which must be matched by ``value``.
        This is obtained from reading the ``cfg`` file.
    validate_style
        Whether or not to confirm if ``value`` is a valid style, according to
        ``rich``. Default is ``False``.

    Returns
    -------
    :class:`bool`
        Whether or not the literal from ``value`` matches the datatype of the
        literal from ``expected``.
    T)r   type
isinstancer   r   )r   r$   r%   value_literalExpectedLiteralTypes        r#   _is_expected_datatyper,   >   se    0 &e,,M0::;;m%899 	M3	'	'	IN=,I,I    stylec                R    	 t          j        |            dS # t          $ r Y dS w xY w)a  Checks whether the entered color style is valid, according to ``rich``.

    Parameters
    ----------
    style
        The style to check whether it is valid.

    Returns
    -------
    :class:`bool`
        Whether the color style is valid or not, according to ``rich``.
    TF)r	   parser   r.   s    r#   r   r   `   s>    Et   uus    
&&defaultdict[str, Any]c                    | D ]S}d|v r'| |         }| |= |                     dd          }|| |<   -| |         }| |= |                     dd          }|| |<   T| S )aP  Replace ``_`` with ``.`` and vice versa in a dictionary's keys for
    ``rich``.

    Parameters
    ----------
    default
        The dictionary whose keys will be checked and replaced.

    Returns
    -------
    :class:`dict`
        The dictionary whose keys are modified by replacing ``_`` with ``.``
        and vice versa.
    _.replace)r2   keytemps      r#   r   r   t   s}      
  
 #::3<D++c3''CGCLL3<D++c3''CGCLLNr-   Tz"Manages Manim configuration files.)context_settingsinvoke_without_commandno_args_is_helpepiloghelpctxcloup.ContextNonec                    dS )z#Responsible for the cfg subcommand.N )r@   s    r#   r   r      s	     	Dr-   )r;   r=   z-lz--levelusercwd)case_sensitivez<Specify if this config is for user or the working directory.)r(   r2   r?   z-oz--openopenfile)is_flaglevel
str | Nonec           	     n   t                      }t          j        dd           d|d          d}d|d          d}t                      }|sKd	}|D ]D}t          j        | d
           t	          t
          t          t          f         ||                   }|dk    r(t          j        t                     t          |          }|D ]}	|dk    r|	t          vrd}
||	         }nd}
d }t          j        d|
 d|	 d|d           |dk    s	|	t          v r_t          t          ||	                   t                    rt          ||	                   n||	         }t          j        d| dd           	 t                      }n# t          $ r t!          d          d w xY w|r|rt#          |||	         t%          |                    sjt          j        d|
 d           t          j        d|
 d|	 d|d           t                      }|r$t#          |||	         t%          |                    j|                    dd          ||	<   |dk    rt          |          n|}d t          |                                          D             ||<   Fnd}| *t          j        d| d d!d           t                      }nd}|                                d"k    s| d#k    r=|d         }t-          |d         j        d$                    t          j        |           n<|d         }t-          |d         j        d$                    t          j        |           |                    d%          5 }|                    |           d d d            n# 1 swxY w Y   |rt5          |           d S d S )&Nz:[yellow bold]Manim Configuration File Writer[/yellow bold]center)justifyz A configuration file at [yellow]   z[/yellow] has been created with your required changes.
This will be used when running the manim command. If you want to override this config,
you will have to create a manim.cfg in the local directory, where you want those changes to be overridden.   z[/yellow] has been created.
To save your config please save that file and place it in your current working directory, from where you run the manim command.zsave this asbold green underliner1   loggerr.   r   z
Enter the z for   r.   endz(defaults to z) :rV   zNot enough values in input.
You may have added a new entry to default.cfg, in which case you will have to
modify write_cfg_subcmd_input to account for it.z[red bold]Invalid z. Try again.[/red bold]:%%%c                B    i | ]\  }}||                     d d          S )rY   rZ   r7   ).0ivs      r#   
<dictcomp>zwrite.<locals>.<dictcomp>   s9          ,0Aq199S$''     r-   openzDo you want to z, the default config for this User?(y/n)[[n]]z
dim purpleyrE   r   w)r   r   printr   r   dictr   r   r   r   r   r)   r   reprinputEOFError	Exceptionr,   r&   r8   itemslowerr   parentsr`   r   r   )rJ   rH   config_pathsUSER_CONFIG_MSGCWD_CONFIG_MSGparseractioncategoryr2   r9   descr.   
defaultvalr:   action_to_userpathcfg_file_pathfps                    r#   r   r      s    %&&LMD   
n<? n n nOC,q/ C C CN  !!F < 7	 7	HMX-/EFFFF4S>6(+;<<G8##6777&w// *; *; x''C7M,M,M"D#CLEE"D E<4<<c<<<ErRRRRx''32H+H+H &&7&E&EsKK*WS\***$S\ 
 M"A*"A"A"ArJJJJ  77DD      #4   	    ; ''<U( ( '
  NNNN    :::C:::"' "   
  %ww  ''<U( ( ' $(<<T#:#:GCL/78/C/Cl7+++G   48MM4G4G4I4I     F8k7	t }RfRRR	
 	
 	
 	

 #WW!!S((EVOO$QLO3A6777o&&&&$QLO3A6777n%%%			C	 	  BR               !-     ! !s   7FF!5NNN)r;   c                 t   t          j        dd           t                      D ]+} |                                 rt          j        |             ,t          j                     t	                      }d t
          D             }|D ]}t          j        | d           ||         D ]|}|dk    rO||vrKt          j        | dd           t          j        d	||         |          ||         |                    Wt          j        | d
||         |                     }t          j        d           d S )NzCONFIG FILES READrQ   r1   c                :    g | ]}|                     d d          S )r6   r5   r7   )r\   as     r#   
<listcomp>zshow.<locals>.<listcomp>  s&    RRRaaiiS11RRRr-   rR   z :rT   rW   rS   z : 
)r   rc   r   existsr   r   )pathro   rich_non_style_entriesrq   entrys        r#   r   r     st   M%-CDDDD!## % %;;== 	%MT)$$$MOOO!!FRR;QRRR  m+ABBBBH% 	F 	FE8##5K(K(Klll33331x(/11 *51    
 DD6(+;E+BDDEEEEd r-   z-dz--directory)r2   	directoryc                @   t          |          }|j        t          j                    j        k    r<t          j        ddd           t                                                      dk    }nd}|r|                                s1t          j        d| dd	           |                    dd
           | 	                    t                     t          j                    dz  }|dz  }t          j        d| d| d           d S t          j        dd	           d S )NzYou are reading the config from the same directory you are exporting to.
This means that the exported config will overwrite the config for this directory.
Are you sure you want to continue? (y/n)zred boldrT   rU   ra   TzCreating folder: r6   r1   )rk   exist_okz	manim.cfgzExported final Config at z to z
Aborted...)r   absoluterF   r   rc   rf   rj   is_dirmkdirinvoker   )r@   r   directory_pathproceed	from_pathto_paths         r#   r   r   $  s2    )__N$(**"555, 	
 	
 	
 	
 ''--//S( 6$$&& 	>M:i:::*MMMM   ===

5HJJ,	 ;.K)KKKKKLLLLLl*555555r-   )r   r   r   r   )F)r   r   r$   r   r%   r&   r   r&   )r.   r   r   r&   )r2   r3   r   r3   )r@   rA   r   rB   )NF)rJ   rK   rH   r&   r   rB   )r   rB   )r@   rA   r   r   r   rB   )-__doc__
__future__r   r   astr   pathlibr   typingr   r   clouprich.errorsr   
rich.styler	   manim._configr
   r   manim._config.utilsr   r   manim.constantsr   manim.utils.file_opsr   r   r   __annotations__r   __all__r   r,   r   r   grouppass_contextr   commandoptionChoicer   r   rF   r   rD   r-   r#   <module>r      s1     # " " " " "                          ( ( ( ( ( (       3 3 3 3 3 3 3 3 E E E E E E E E " " " " " " ? ? ? ? ? ? ? ?!     
 %R$Q$Q  Q Q Q Q	 	 	   & 7<    D   (   : %	-   	 	 	  	
 .EE	vuoe	<	<	<	G   dHj$777b! b! b! b! 87  FEb!J .//   0/. .//dM848::6666 6 6  76 0/6 6 6r-   