
    ip                    t   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	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 	 	 ddZ ed      	 d 	 	 	 	 	 	 	 d!d       Z ed      d d!d       Z ed      d d!d       Zy)"    )annotationsN)Any)Callable)TYPE_CHECKING   )util)compat)_preserving_path_as_str)PostWriteHookConfig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    z/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/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        |      }	 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   revision_pathoptionshookkes        r   _invoker   .   s_     ,M:M, M7++  &tfL9
	s   	 	AAAc                    |D ]=  }|d   }	 |d   }t        j                  d|d      5  t        || |       ddd       ? y# 1 sw Y   JxY w# t        $ r!}t        j                  d| d|      |d}~ww xY w)	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   )pathhooksr   r   type_r   s         r   
_run_hooksr(   F   s    
  +L!	+LE *4(3T + tT*+ +++ +  	##v ''+h0 	s"   AAA		A:A55A: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shlexsplitr	   is_posixreplace)cmdline_options_strr%   cmdline_options_listoptions       r   _parse_cmdline_optionsr4   [   so     $773c9<OO ;;6??
 + 	,d3   	s   Ac           
     z    	 | |   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_optionr7   p   sa    t} 7<()4& 1!,/24
 	s    	:%5:c                    |j                  dd       }|j                  dd      }t        ||       }i }|rt        j                  x|d<   |d<   t        j                  g ||fd|i| y )Ncwdr    stdoutstderr)getr4   
subprocessDEVNULLrun)r%   r   ignore_outputcommandr9   r1   r2   kws           r   	_run_hookrD   z   su     kk%.C!++i412EtLB&0&8&888r(|NN4W434D#DDr   console_scriptsc           	     8   t        |d      }t        j                  d      D ]  }|j                  |k(  s|} n t	        j
                  d|       t        j                  dd|j                   d|j                   d|j                   dg}t        | |||       y )	N
entrypointrE   z*Could not find entrypoint console_scripts.z-czimport z; r6   z())r7   r	   importlib_metadata_getr   r   r   sys
executablemoduleattrrD   )r%   r   rA   entrypoint_nameentryimplrB   s          r   rE   rE      s     +7LAO../@A 
::(D

 88IJ
 	

 	
$++bQtyyk<G
 dG]G4r   execc                <    t        |d      }t        | |||g       y )NrJ   )rB   )r7   rD   )r%   r   rA   rJ   s       r   exec_rR      s    %g|<JdG]ZLAr   rK   c                    t        |d      }t        j                  j                  |      t        j                  d|       t
        j                  d|g}t        | |||       y )NrK   zCould not find module z-m)r7   	importlibr   	find_specr   rI   rJ   rD   )r%   r   rA   module_namerB   s        r   rK   rK      sZ    &w9K~~,4"8 FGG~~t[1GdG]G4r   )r   strreturnr   )r   rW   r   str | os.PathLike[str]r   r   rX   r   )r%   rY   r&   zlist[PostWriteHookConfig]rX   None)r1   rW   r%   rW   rX   	list[str])r   r   r   rW   rX   rW   )
r%   rW   r   r   rA   boolrB   r[   rX   rZ   )F)r%   rW   r   r   rA   r\   rX   rZ   )
__future__r   importlib.utilrT   osr-   r>   rI   typingr   r   r   r:   r   r	   util.pyfilesr
   configr   r,   r   __annotations__r   r   r(   r4   r7   rD   rE   rR   rK   r   r   r   <module>rd      s:   #  	   
       2,2 	4 &,
,), !, 		,0+
 +)B+	+* *E
EE-1E<EE	E 

495
55-15	5 5* 
&B B
 
(5 5r   