
    ZiK                        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        y)    )annotations)metadataN)
ModuleType)Callable)Pattern)TYPE_CHECKING   )util)DispatchPriority)PriorityDispatcher)PriorityDispatchResultc                      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y)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

    c                    || _         t        j                  d|       |t        v rt	        d| d      | t        |<   t               | _        y )Nzsetup plugin %szA plugin named z is already registered)nameloginfo_all_plugins
ValueErrorr   autogenerate_comparators)selfr   s     S/home/portmadness/app/.venv/lib/python3.12/site-packages/alembic/runtime/plugins.py__init__zPlugin.__init__#   sJ    	"D)<tf4JKLL!T(:(<%    c                &    t         | j                  = y)zremove this pluginN)r   r   )r   s    r   removezPlugin.remove+   s     #r   Ndefault)	qualifierpriorityc               N     | j                   j                  ||||      |       y)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   fncompare_targetcompare_elementr   r   s         r   add_autogenerate_comparatorz"Plugin.add_autogenerate_comparator0   s6    D	
%%22$	 	3 	

 	r   c                  
 t               }i }t               }|D ]?  }|j                  d      r|j                  t        |dd              2t        |      ||<   A t        j                         D ]  
t        
fd|D              r|D cg c]#  }||   j                  
j                        s"|% }}|sI|j                  |       t        j                  d
j                         |j                  
j                          t        |      j                  |      }	|	r't        j                   ddj#                  |	             yc c}w )z_Populate all current autogenerate comparison functions into
        a given PriorityDispatcher.~   Nc              3  T   K   | ]  }|j                  j                         ! y wN)matchr   ).0exclplugins     r   	<genexpr>zAPlugin.populate_autogenerate_priority_dispatch.<locals>.<genexpr>l   s     ?t4::fkk*?s   %(z!setting up autogenerate plugin %szDid not locate plugins: z, )set
startswithadd_make_rer   valuesanyr,   r   updater   r   populate_withr   
differencer
   CommandErrorjoin)clscomparatorsinclude_pluginsexcludeincludematched_expressionsr   inclinclude_matchesnever_matchedr/   s             @r   'populate_autogenerate_priority_dispatchz.Plugin.populate_autogenerate_priority_dispatchY   s>    &)U+-(+# 	/Ds#HT!"X./ (		/ #))+ 	GF?w?? ")GDM,?,?,LO  ##**?;HH8&++F%%f&E&EF	G G//0CD##*499]+C*DE  s   #E0Ec                8    |j                  t        |             y)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   )r<   moduler   s      r   setup_plugin_from_modulezPlugin.setup_plugin_from_module   s    2 	VD\"r   )r   strreturnNoner+   )r#   z%Callable[..., PriorityDispatchResult]r$   rJ   r%   z
str | Noner   rJ   r   r   rL   rM   )r=   r   r>   z	list[str]rL   rM   )rH   r   r   rJ   rL   rM   )__name__
__module____qualname____doc__r   r   r   MEDIUMr&   classmethodrE   rI    r   r   r   r      s    =$ '+	' #%5%<%<'1' ' $	' ' #' 
'R $,$?H$	$ $L # #r   r   c                    | j                  d      }d}|D ]3  }|dk(  r|dz  }|j                         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   r4   r4      s    ZZ_F
C DC<8OC!55= C9$BCCD ::#ab'!n%%r   c                     t        j                  d      D ]7  } | j                         D ]"  }t        j	                  || j
                         $ 9 y )Nzalembic.plugins)group)r   entry_pointsloadr   rI   r   )
entrypointmods     r   _setuprh      sK    ++2CD B
??$ 	BC++CA	BBr   )r   rJ   rL   zPattern[str]rK   )
__future__r   	importlibr   loggingr]   typesr   typingr   r   r   rW   r
   r   r   r   r   	getLoggerrN   r   r   r4   rh   rT   r   r   <module>ro      sd    "   	       # %- g!A# A#H& B r   