
    OjK                        d dl mZ d dlmZ d dl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 i Z ej        e          Z G d d          ZddZddZ e             dS )    )annotations)metadataN)
ModuleType)Callable)Pattern)TYPE_CHECKING   )util)DispatchPriority)PriorityDispatcher)PriorityDispatchResultc                  p    e Zd ZdZddZddZ	 dd	ej        d
ddZe	d d            Z
e	d!d            ZdS )"Plugina  Describe a series of functions that are pulled in as a plugin.

    This is initially to provide for portable lists of autogenerate
    comparison functions, however the setup for a plugin can run any
    other kinds of global registration as well.

    .. versionadded:: 1.18.0

    namestrc                    || _         t                              d|           |t          v rt	          d| d          | t          |<   t                      | _        d S )Nzsetup plugin %szA plugin named z is already registered)r   loginfo_all_plugins
ValueErrorr   autogenerate_comparators)selfr   s     k/lsinfo/ai/hellotax_ai/training_center/backend/venv/lib/python3.11/site-packages/alembic/runtime/plugins.py__init__zPlugin.__init__#   sa    	"D)))<KtKKKLLL!T(:(<(<%%%    returnNonec                     t           | j        = dS )zremove this pluginN)r   r   )r   s    r   removezPlugin.remove+   s     ###r   Ndefault)	qualifierpriorityfn%Callable[..., PriorityDispatchResult]compare_targetcompare_element
str | Noner!   r"   r   c               T     | j                             ||||          |           dS )aU  Register an autogenerate comparison function.

        See the section :ref:`plugins_registering_autogenerate` for detailed
        examples on how to use this method.

        :param fn: The comparison function to register. The function receives
         arguments specific to the type of comparison being performed and
         should return a :class:`.PriorityDispatchResult` value.

        :param compare_target: The type of comparison being performed
         (e.g., ``"table"``, ``"column"``, ``"type"``).

        :param compare_element: Optional sub-element being compared within
         the target type.

        :param qualifier: Database dialect qualifier. Use ``"default"`` for
         all dialects, or specify a dialect name like ``"postgresql"`` to
         register a dialect-specific handler. Defaults to ``"default"``.

        :param priority: Execution priority for this comparison function.
         Functions are executed in priority order from
         :attr:`.DispatchPriority.FIRST` to :attr:`.DispatchPriority.LAST`.
         Defaults to :attr:`.DispatchPriority.MEDIUM`.

        )subgroupr"   r!   N)r   dispatch_for)r   r#   r%   r&   r!   r"   s         r   add_autogenerate_comparatorz"Plugin.add_autogenerate_comparator0   sL    D	
%22$	 	3 	
 	

 	 	 	 	 	r   comparatorsr   include_plugins	list[str]c                  	 t                      }i t                      }|D ]T}|                    d          r+|                    t          |dd                              Bt          |          |<   Ut                                          D ]	t          	fd|D                       r	fdD             }|s0|                    |           t          	                    d	j
                   |                    	j                   t                                        |          }|r*t          j        dd                    |                     dS )	z_Populate all current autogenerate comparison functions into
        a given PriorityDispatcher.~   Nc              3  L   K   | ]}|                     j                  V  d S Nmatchr   ).0exclplugins     r   	<genexpr>zAPlugin.populate_autogenerate_priority_dispatch.<locals>.<genexpr>l   s1      ??t4::fk**??????r   c                T    g | ]$}|                              j                  "|%S  r4   )r6   inclincluder8   s     r   
<listcomp>zBPlugin.populate_autogenerate_priority_dispatch.<locals>.<listcomp>o   sB       GDM,?,?,L,L  r   z!setting up autogenerate plugin %szDid not locate plugins: z, )set
startswithadd_make_rer   valuesanyupdater   r   r   populate_withr   
differencer
   CommandErrorjoin)
clsr,   r-   excludematched_expressionsr   include_matchesnever_matchedr=   r8   s
           @@r   'populate_autogenerate_priority_dispatchz.Plugin.populate_autogenerate_priority_dispatchY   s    &)UU+-(+# 	/ 	/Ds## /HT!""X..//// ("))++ 	G 	GF????w?????     !(  O # <#**?;;;HH8&+FFF%%f&EFFFFG//0CDD 	#E499]+C+CEE  	 	r   moduler   c                J    |                     t          |                     dS )a<  Call the ``setup()`` function of a plugin module, identified by
        passing the module object itself.

        E.g.::

            from alembic.runtime.plugins import Plugin
            import myproject.alembic_plugin

            # Register the plugin manually
            Plugin.setup_plugin_from_module(
                myproject.alembic_plugin,
                "myproject.custom_operations"
            )

        This will generate a new :class:`.Plugin` object with the given
        name, which will register itself in the global list of plugins.
        Then the module's ``setup()`` function is invoked, passing that
        :class:`.Plugin` object.

        This exact process is invoked automatically at import time for any
        plugin module that is published via the ``alembic.plugins`` entrypoint.

        N)setupr   )rJ   rP   r   s      r   setup_plugin_from_modulezPlugin.setup_plugin_from_module   s"    2 	VD\\"""""r   )r   r   r   r   r3   )r#   r$   r%   r   r&   r'   r!   r   r"   r   r   r   )r,   r   r-   r.   r   r   )rP   r   r   r   r   r   )__name__
__module____qualname____doc__r   r   r   MEDIUMr+   classmethodrO   rS   r;   r   r   r   r      s         = = = =$ $ $ $ '+	' #%5%<' ' ' ' ' 'R $ $ $ [$L # # # [# # #r   r   r   r   r   Pattern[str]c                    |                      d          }d}|D ]<}|dk    r|dz  }|                                r	|d|z   z  }+t          d|           t          j        d|dd           d	          S )
N. *z\..+?z\.zInvalid plugin expression ^r	   $)splitisidentifierr   recompile)r   tokensregtokens       r   rB   rB      s    ZZ__F
C D DC<<8OCC!! 	D55= CCB$BBCCC :n#abb'nnn%%%r   r   c                     t          j        d          D ]9} |                                 D ]"}t                              || j                   #:d S )Nzalembic.plugins)group)r   entry_pointsloadr   rS   r   )
entrypointmods     r   _setupro      sj    +2CDDD B B
??$$ 	B 	BC++CAAAA	BB Br   )r   r   r   r[   rT   )
__future__r   	importlibr   loggingrd   typesr   typingr   r   r   r^   r
   r   r   r   r   	getLoggerrU   r   r   rB   ro   r;   r   r   <module>rv      sZ   " " " " " "        				                                     # # # # # # % % % % % % .------ g!!A# A# A# A# A# A# A# A#H& & & & B B B B r   