:orphan:

:mod:`cloup.constraints._support`
=================================

.. py:module:: cloup.constraints._support





                              
Classes
-------

.. autosummary::

   ~cloup.constraints._support.BoundConstraintSpec
   ~cloup.constraints._support.BoundConstraint
   ~cloup.constraints._support.ConstraintMixin

Functions
---------

.. autosummary::

   ~cloup.constraints._support.constraint
   ~cloup.constraints._support.constrained_params
   ~cloup.constraints._support.ensure_constraints_support


                                           
Contents
--------
.. py:class:: BoundConstraintSpec

   Bases: :py:obj:`NamedTuple`

   A NamedTuple storing a ``Constraint`` and the **names of the parameters**
   it has to check.

   .. py:attribute:: constraint
      :annotation: :cloup.constraints._core.Constraint

      

   .. py:attribute:: param_names
      :annotation: :Union[Sequence[str]]

      

   .. py:method:: resolve_params(cmd)



.. py:function:: constraint(constr, params)

   Register a constraint on a list of parameters specified by (destination) name
   (e.g. the default name of ``--input-file`` is ``input_file``).


.. py:function:: constrained_params(constr, *param_adders)

   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.


.. py:class:: BoundConstraint

   Bases: :py:obj:`NamedTuple`

   Internal utility ``NamedTuple`` that represents a ``Constraint``
   bound to a collection of ``click.Parameter`` instances.
   Note: this is not a subclass of Constraint.

   .. py:attribute:: constraint
      :annotation: :cloup.constraints._core.Constraint

      

   .. py:attribute:: params
      :annotation: :Sequence[click.Parameter]

      

   .. py:method:: check_consistency()


   .. py:method:: check_values(ctx)


   .. py:method:: get_help_record(ctx)



.. py:class:: ConstraintMixin(*args, constraints = (), show_constraints = None, **kwargs)

   Provides support for constraints.

   :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

   .. py:attribute:: optgroup_constraints
      

      Constraints applied to ``OptionGroup`` instances.


   .. py:attribute:: param_constraints
      :annotation: :Tuple[BoundConstraint, Ellipsis]

      Constraints registered using ``@constraint`` (or equivalent method).


   .. py:attribute:: all_constraints
      

      All constraints applied to parameter/option groups of this command.


   .. py:method:: parse_args(ctx, args)


   .. py:method:: get_param_by_name(name)


   .. py:method:: get_params_by_name(names)


   .. py:method:: format_constraints(ctx, formatter)


   .. py:method:: must_show_constraints(ctx)



.. py:function:: ensure_constraints_support(command)



                                         