
    kjz                     r   d dl mZmZmZmZmZmZmZmZm	Z	m
Z
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mZ e	rd d	lmZmZ  G d
 de          Zdedeedf         ddfdZdedee         deegef         fdZdededeegef         fdZ G d de          Z G d d          Zdej        defdZ dS )    )AnyCallableDictIterableList
NamedTupleOptionalSequenceTYPE_CHECKINGTupleUnionN   )
Constraint)join_param_labels   )
first_bool)	DecoratorF)HelpFormatterOptionGroupc                   H    e Zd ZU dZeed<   eee                  ed<   d
dZ	d	S )BoundConstraintSpecz^A NamedTuple storing a ``Constraint`` and the **names of the parameters**
    it has to check.
constraintparam_namescmdConstraintMixinreturnBoundConstraintc                 \    t          | j        |                    | j                            S N)r   r   get_params_by_namer   )selfr   s     U/home/agentuser/manim-venv/lib/python3.11/site-packages/cloup/constraints/_support.pyresolve_paramsz"BoundConstraintSpec.resolve_params   s-    O""4#344
 
 	
    N)r   r   r   r   )
__name__
__module____qualname____doc__r   __annotations__r   r
   strr$    r%   r#   r   r      sU          x}%%%%
 
 
 
 
 
r%   r   fconstrr   r   c                 h    t          | d          sg | _        | j                            |           d S )N__cloup_constraints__)hasattrr0   append)r-   r.   s     r#   _constraint_memor3      s<     1-.. %"$""6*****r%   paramsc                 j    t          | t          |                    dt          dt          ffd}|S )zRegister a constraint on a list of parameters specified by (destination) name
    (e.g. the default name of ``--input-file`` is ``input_file``).r-   r   c                 (    t          |            | S r    )r3   )r-   specs    r#   	decoratorzconstraint.<locals>.decorator+   s    D!!!r%   )r   tupler   )r.   r4   r8   r7   s      @r#   r   r   &   sN     vuV}}55DQ 1       r%   param_addersc                 4     dt           dt           f fd}|S )a  
    Return a decorator that adds the given parameters and applies a constraint
    to them. Equivalent to::

        @param_adders[0]
        ...
        @param_adders[-1]
        @constraint(constr, <param names>)

    This decorator saves you to manually (re)type the parameter names.
    It can also be used inside ``@option_group``.

    Instead of using this decorator, you can also call the constraint itself::

        @constr(*param_adders)

    but remember that:

    - Python 3.9 is the first that allows arbitrary expressions on the right of ``@``;
    - using a long conditional/composite constraint as decorator may be less
      readable.

    In these cases, you may consider using ``@constrained_params``.

    .. versionadded:: 0.9.0

    :param constr: an instance of :class:`Constraint`
    :param param_adders:
        function decorators, each attaching a single parameter to the decorated
        function.
    r-   r   c           	          g }t                    D ]/} ||            | j        d         }|                    |           0t          t	          |d d d                             }t          | |           | S )N)reversed__click_params__r2   r   r9   r3   )r-   reversed_params	add_paramparambound_constrr.   r:   s        r#   r8   z%constrained_params.<locals>.decoratorV   s    !,// 	* 	*IIaLLL&r*E""5))))&vu_TTrT5J/K/KLLL)))r%   )r   )r.   r:   r8   s   `` r#   constrained_paramsrD   2   s>    HQ 1        r%   c                       e Zd ZU dZeed<   eej                 ed<   d
dZ	dej
        ddfdZdej
        deeeef                  fd	ZdS )r   zInternal utility ``NamedTuple`` that represents a ``Constraint``
    bound to a collection of ``click.Parameter`` instances.
    Note: this is not a subclass of Constraint.r   r4   r   Nc                 D    | j                             | j                   d S r    )r   check_consistencyr4   )r"   s    r#   rG   z!BoundConstraint.check_consistencyk   s     ))$+66666r%   ctxc                 F    | j                             | j        |           d S r    )r   check_valuesr4   r"   rH   s     r#   rJ   zBoundConstraint.check_valuesn   s"    $$T[#66666r%   c                 t    | j                             |          }|sd S dt          | j                  z  }||fS )Nz{%s})r   helpr   r4   )r"   rH   constr_help
param_lists       r#   get_help_recordzBoundConstraint.get_help_recordq   sD    o**3// 	4/<<<
;&&r%   )r   N)r&   r'   r(   r)   r   r*   r
   click	ParameterrG   ContextrJ   r	   r   r+   rP   r,   r%   r#   r   r   c   s         3 3 U_%%%%7 7 7 77 7$ 7 7 7 7'5= 'XeCHo5N ' ' ' ' ' 'r%   c            	       "    e Zd ZdZddddedeeeef                  de	e
         def fd	Zd
ej        dee         dee         f fdZdedej        fdZdee         deej                 fdZd
ej        ddddfdZd
ej        de
fdZ xZS )r   z!Provides support for constraints.r,   N)constraintsshow_constraintsargsrU   rV   kwargsc                X     t                      j        |i | | _        d  j        D              _        t           dt                                }t          d |D                        _        	 t           fd|D                        _        	  j         j        z    _	        dS )a  
        :param constraints:
            sequence of constraints bound to specific groups of parameters.
            Note that constraints applied to option groups are collected from
            the option groups themselves, so they don't need to be included in
            this argument.
        :param show_constraints:
            whether to include a "Constraint" section in the command help. This
            is also available as a context setting having a lower priority than
            this attribute.
        :param args:
            positional arguments forwarded to the next class in the MRO
        :param kwargs:
            keyword arguments forwarded to the next class in the MRO
        c                     i | ]
}|j         |S r,   )name).0rB   s     r#   
<dictcomp>z,ConstraintMixin.__init__.<locals>.<dictcomp>   s)     <
 <
 <
"'EJ<
 <
 <
r%   option_groupsc              3   X   K   | ]%}|j         	t          |j         |j                  V  &d S r    )r   r   options)r\   grps     r#   	<genexpr>z+ConstraintMixin.__init__.<locals>.<genexpr>   sD       *
 *
~) CNCK88))))*
 *
r%   c              3   p   K   | ]0}t          |t                    r|n|                              V  1d S r    )
isinstancer   r$   )r\   r.   r"   s     r#   rb   z+ConstraintMixin.__init__.<locals>.<genexpr>   se       D
 D

  %V_== 1**400D
 D
 D
 D
 D
 D
r%   N)
super__init__rV   r4   _params_by_namegetattrr9   optgroup_constraintsparam_constraintsall_constraints)r"   rU   rV   rW   rX   r^   	__class__s   `     r#   rf   zConstraintMixin.__init__|   s    * 	$)&))) 0<
 <
+/;<
 <
 <
 29PUPWPW1X1X$) *
 *
$*
 *
 *
 %
 %
!
 	@ ?D D
 D
 D
 D

 &D
 D
 D
 ?
 ?
 	S#84;QQQQr%   rH   r   c                    |j         s2t          j        |          r| j        D ]}|                                 t                                          |          t          |j        t          j
                  ot          fd|j        D                       }|j         s|rS | j        D ]}|                    |           S )Nc              3       K   | ]}|v V  	d S r    r,   )r\   	help_flagrW   s     r#   rb   z-ConstraintMixin.parse_args.<locals>.<genexpr>   sA       S
 S
"+IS
 S
 S
 S
 S
 S
r%   )resilient_parsingr   must_check_consistencyrk   rG   re   
parse_argsrd   commandrQ   Groupanyhelp_option_namesrJ   )r"   rH   rW   r.   should_show_subcommand_helprl   s     `  r#   rr   zConstraintMixin.parse_args   s   $ 	+)J3)O)O 	+. + +((****ww!!#t,, '1ek&J&J '
s S
 S
 S
 S
/2/DS
 S
 S
 P
 P
#   	$? 	K * 	% 	%F$$$$r%   r[   c                 `    	 | j         |         S # t          $ r t          d| d          w xY w)Nz there's no CLI parameter named '')rg   KeyError)r"   r[   s     r#   get_param_by_namez!ConstraintMixin.get_param_by_name   sO    	G'-- 	G 	G 	GEdEEEFFF	Gs    -namesc                 :     t           fd|D                       S )Nc              3   B   K   | ]}                     |          V  d S r    )r{   )r\   r[   r"   s     r#   rb   z5ConstraintMixin.get_params_by_name.<locals>.<genexpr>   s1      DDdT++D11DDDDDDr%   )r9   )r"   r|   s   ` r#   r!   z"ConstraintMixin.get_params_by_name   s&    DDDDeDDDDDDr%   	formatterr   c                     fd| j         D             }d |D             }|rE|                    d          5  |                    |           d d d            d S # 1 swxY w Y   d S d S )Nc              3   B   K   | ]}|                               V  d S r    )rP   )r\   r.   rH   s     r#   rb   z5ConstraintMixin.format_constraints.<locals>.<genexpr>   s1      XXvv--c22XXXXXXr%   c                     g | ]}||S r    r,   )r\   recs     r#   
<listcomp>z6ConstraintMixin.format_constraints.<locals>.<listcomp>   s    AAA33r%   Constraints)rj   sectionwrite_dl)r"   rH   r   records_genrecordss    `   r#   format_constraintsz"ConstraintMixin.format_constraints   s    XXXXAWXXXAA+AAA 	,""=11 , ,""7+++, , , , , , , , , , , , , , , , , ,	, 	,s   AA"Ac                 L    t          | j        t          |dd           d          S )NrV   F)r   rV   rh   rK   s     r#   must_show_constraintsz%ConstraintMixin.must_show_constraints   s-    !C+T22
 
 	
r%   )r&   r'   r(   r)   r   r
   r   r   r   r	   boolrf   rQ   rS   r   r+   rr   rR   r{   r   r!   r   r   __classcell__)rl   s   @r#   r   r   y   s       ++ NP+/3R 3R 3R3Re$7$HIJ3R #4.3R 	3R 3R 3R 3R 3R 3Rjem 49 c      *Gc Geo G G G GE E(5?:S E E E E,em , ,TX , , , ,
 
4 
 
 
 
 
 
 
 
r%   r   rs   c                 N    t          | t                    r| S t          d          )NzCa Command must inherits from ConstraintMixin to support constraints)rd   r   	TypeError)rs   s    r#   ensure_constraints_supportr      s1    '?++ 
MO O Or%   )!typingr   r   r   r   r   r   r	   r
   r   r   r   rQ   _corer   commonr   _utilr   r   r   cloupr   r   r   r3   r+   r   rD   r   r   Commandr   r,   r%   r#   <module>r      se                           
        % % % % % %       ! ! ! ! ! ! ! ! 100000000

 

 

 

 

* 

 

 

+
+-/@@A+	+ + + +	z 	8C= 	Xqc1f=M 	 	 	 	... qc1f. . . .b' ' ' ' 'j ' ' ',c
 c
 c
 c
 c
 c
 c
 c
LO O/ O O O O O Or%   