
    +h                    (   U d dl mZ d dl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 d
dlmZ d
dlmZ dZi Zded<   ddZ	 	 	 	 	 	 	 	 ddZddZddZ ed      	 d	 	 	 	 	 	 	 dd       Z ed      ddd       Zy)    )annotationsN)Any)Callable)Dict)List)Mapping)Optional)Union   )util)compatREVISION_SCRIPT_FILENAMEdict	_registryc                      fd}|S )zA function decorator that will register that function as a write hook.

    See the documentation linked below for an example.

    .. seealso::

        :ref:`post_write_hooks_custom`


    c                    | t         <   | S )N)r   )fnnames    M/var/www/html/venv/lib/python3.12/site-packages/alembic/script/write_hooks.pydecoratezregister.<locals>.decorate&   s    	$	     )r   r   s   ` r   registerr      s     Or   c                ~    	 t         |    } |||      S # t        $ r}t        j                  d|  d      |d}~ww xY w)a7  Invokes the formatter registered for the given name.

    :param name: The name of a formatter in the registry
    :param revision: A :class:`.MigrationRevision` instance
    :param options: A dict containing kwargs passed to the
        specified formatter.
    :raises: :class:`alembic.util.CommandError`
    zNo formatter with name 'z' registeredN)r   KeyErrorr   CommandError)r   revisionoptionshookkes        r   _invoker!   -   sS    ' Hg&&  &tfL9
	s   	 	<7<c                   ddl m} |j                  |j                  dd            }|D ]v  }|s|D ci c]+  }|j	                  |dz         r|t        |      dz   d ||   - }}||d<   	 |d   }t        j                  d	|d
      5  t        || |       ddd       x yc c}w # 1 sw Y   xY w# t        $ r!}t        j                  d| d|      |d}~ww xY w)z&Invoke hooks for a generated revision.   )_split_on_space_commahooks .N
_hook_nametypezRunning post write hook T)newlineKey z&.type is required for post write hook )baser$   splitget
startswithlenr   statusr!   r   r   )	pathhook_configr$   namesr   keyoptstype_r    s	            r   
_run_hooksr8   B   s    ,!''(DEE + #
~~dSj) D	A +c"22
 

 "\
	+LE *4(3T + tT*+ +!+
+ +  	##tfB4(K	s)   0B$,B5B))B2	5	C>CCc                    t         | vrt         dz   | z   } t        j                  | t        j                        }|D cg c]  }|j                  t         |       }}|S c c}w )zParse options from a string into a list.

    Also substitutes the revision script token with the actual filename of
    the revision script.

    If the revision script token doesn't occur in the options string, it is
    automatically prepended.
     )posix)REVISION_SCRIPT_TOKENshlexr-   r   is_posixreplace)cmdline_options_strr2   cmdline_options_listoptions       r   _parse_cmdline_optionsrC   _   so     $773c9<OO ;;6??
 + 	,d3   	s   Aconsole_scriptsc                @   	 |d   }t        j                  d      D ]  }|j
                  |k(  s|} n t        j                  d|       |j                  dd       }|j                  dd	      }t        ||       }	i }
|rt        j                  x|
d
<   |
d<   t        j                  t        j                  dd|j                   d|j                   d|j                   dg|	z   fd|i|
 y # t         $ r'}t        j                  d|d    d|d         |d }~ww xY w)N
entrypointr+   r(   z,.entrypoint is required for post write hook rD   z*Could not find entrypoint console_scripts.cwdr   r&   stdoutstderrz-czimport z; r'   z())r   r   r   r   importlib_metadata_getr   r.   rC   
subprocessDEVNULLrunsys
executablemoduleattr)r2   r   ignore_outputentrypoint_namer    entryimplrG   r@   rA   kws              r   rD   rD   t   s\   !,/ ../@A 
::(D

 88IJ
 	
 !UD1C!++i412EtLB&0&8&888r(|NNNNdkk]"T[[M499+R@	

 		 	 	+  7<() *!,/24
 	s   C- -	D6"DDexecc                D   	 |d   }|j                  dd       }|j                  dd      }t	        ||       }i }|rt
        j                  x|d<   |d	<   t        j                  |g|fd|i| y # t         $ r'}t        j                  d|d    d|d         |d }~ww xY w)
NrO   r+   r(   z,.executable is required for post write hook rG   r   r&   rH   rI   )r   r   r   r.   rC   rK   rL   rM   )	r2   r   rR   rO   r    rG   r@   rA   rV   s	            r   exec_rY      s    \*
 !UD1C!++i412EtLB&0&8&888r(|NN	
!	

    7<() *!,/24
 	s   A/ /	B8"BB)r   strreturnr   )r   rZ   r   rZ   r   zMapping[str, Union[str, int]]r[   r   )r2   rZ   r3   zMapping[str, str]r[   None)r@   rZ   r2   rZ   r[   z	List[str])F)r2   rZ   r   r   rR   boolr[   r\   )
__future__r   r=   rK   rN   typingr   r   r   r   r   r	   r
   r&   r   r   r<   r   __annotations__r   r!   r8   rC   rD   rY   r   r   r   <module>ra      s    #   
          3 	4 &'
'''D''*+: * 

49#
##-1#	# #L 
& r   