
    Oj                    ^   U d dl mZ d dlZd dl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 erdd
lmZ dZi Zded<   d/dZd0dZd1dZd2d Zd3d!Zd4d%Z ed&          	 	 d5d6d*            Z ed+          d7d8d,            Z ed-          d7d8d.            ZdS )9    )annotationsN)Any)Callable)TYPE_CHECKING   )util)compat)_preserving_path_as_str)PostWriteHookConfigREVISION_SCRIPT_FILENAMEdict	_registrynamestrreturnr   c                      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   )fnr   s    n/lsinfo/ai/hellotax_ai/training_center/backend/venv/lib/python3.11/site-packages/alembic/script/write_hooks.pydecoratezregister.<locals>.decorate'   s    	$	     )r   r   s   ` r   registerr      s#         Or   revision_pathstr | os.PathLike[str]optionsr   r   c                    t          |          }	 t          |          } |||          S # t          $ r}t          j        d|  d          |d}~ww xY w)a1  Invokes the formatter registered for the given name.

    :param name: The name of a formatter in the registry
    :param revision: string path to the revision file
    :param options: A dict containing kwargs passed to the
        specified formatter.
    :raises: :class:`alembic.util.CommandError`
    zNo formatter with name 'z' registeredN)r
   r   KeyErrorr   CommandError)r   r   r   hookkes        r   _invoker"   .   sz     ,M::M, tM7+++    9t999
 
	s   * 
AAApathhookslist[PostWriteHookConfig]Nonec                   |D ]}|d         }	 |d         }t          j        d|d          5  t          || |           ddd           n# 1 swxY w Y   V# t          $ r }t          j        d| d|          |d}~ww xY wdS )	z&Invoke hooks for a generated revision.
_hook_nametypezRunning post write hook T)newlineNzKey 'z;.type' (or 'type' in toml) is required for post write hook )r   statusr"   r   r   )r#   r$   r    r   type_r!   s         r   
_run_hooksr-   F   s   
  + +L!	+LE 3433T   + + tT***+ + + + + + + + + + + + + + +  	 	 	#0 0 0'+0 0  		+ +s(   AAA	A	
B#A>>Bcmdline_options_str	list[str]c                    t           | vrt           dz   | z   } t          j        | t          j                  }fd|D             }|S )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.
     )posixc                F    g | ]}|                     t                    S r   )replaceREVISION_SCRIPT_TOKEN).0optionr#   s     r   
<listcomp>z*_parse_cmdline_options.<locals>.<listcomp>i   s8        	,d33  r   )r5   shlexsplitr	   is_posix)r.   r#   cmdline_options_lists    ` r   _parse_cmdline_optionsr=   [   sq     $7773c9<OO ;6?     *    r   c           
         	 | |         S # t           $ r/}t          j        d| d          d| d| d                   |d }~ww xY w)NzKey r(   .z! is required for post write hook )r   r   r   )r   r   r!   s      r   _get_required_optionr@   p   s~    t}   47<( 4 44 4 4!,/4 4
 
 	s   
 
A*>Aignore_outputboolcommandc                    |                     dd           }|                     dd          }t          ||           }i }|rt          j        x|d<   |d<   t          j        g ||fd|i| d S )Ncwdr    stdoutstderr)getr=   
subprocessDEVNULLrun)r#   r   rA   rC   rE   r.   r<   kws           r   	_run_hookrN   z   s     kk%..C!++i4412EtLLB 9&0&888r(|N4W434DD#DDDDDDr   console_scriptsFverify_versiontuple[int, ...] | Nonec                   t          |d          }t          j        d          D ]}|j        |k    r|} nt	          j        d|           |r2d|j         d|j         d| d| d|j         d	|j         d
|j         d}nd|j         d|j         d
|j         d}t          j	        d|g}t          | |||           d S )N
entrypointrO   z*Could not find entrypoint console_scripts.zimport z; assert tuple(int(x) for x in z.__version__.split('.')) >= z, 'need exactly version z of z'; r?   z()z; z-c)r@   r	   importlib_metadata_getr   r   r   moduleattrsys
executablerN   )	r#   r   rA   rP   entrypoint_nameentryimplpyscriptrC   s	            r   rO   rO      sA    +7LAAO./@AA 
 
:((DE ) JJJ
 
 	
  H+dk + +,0K+ +Uc+ +%3+ +9=+ + {+ + "Y+ + + 	 HT[GGDKGG$)GGG~tX.GdG]G44444r   execc                N    t          |d          }t          | |||g           d S )NrX   )rC   )r@   rN   )r#   r   rA   rX   s       r   exec_r_      s0    %g|<<JdG]ZLAAAAAAr   rU   c                    t          |d          }t          j                            |          t          j        d|           t
          j        d|g}t          | |||           d S )NrU   zCould not find module z-m)r@   	importlibr   	find_specr   rW   rX   rN   )r#   r   rA   module_namerC   s        r   rU   rU      si    &w99K~,,4 F F FGGG~t[1GdG]G44444r   )r   r   r   r   )r   r   r   r   r   r   r   r   )r#   r   r$   r%   r   r&   )r.   r   r#   r   r   r/   )r   r   r   r   r   r   )
r#   r   r   r   rA   rB   rC   r/   r   r&   )FN)
r#   r   r   r   rA   rB   rP   rQ   r   r&   )F)r#   r   r   r   rA   rB   r   r&   )
__future__r   importlib.utilra   osr9   rJ   rW   typingr   r   r   rF   r   r	   util.pyfilesr
   configr   r5   r   __annotations__r   r"   r-   r=   r@   rN   rO   r_   rU   r   r   r   <module>rk      s   # " " " " " "     				      



                                     2 2 2 2 2 2 -,,,,,,2 	       &, , , ,0+ + + +*       *   E E E E 

  -1	5 5 5 5 5< 
&B B B B B
 
(5 5 5 5 5 5 5r   