
    Ѯh                       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 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)Dict)List)Optional)TYPE_CHECKING)Union   )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    l/home/www/academy-backend.kofcorporation.com/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#   2   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,   J   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_optionsr8   _   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_optionr;   t   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)getr8   
subprocessDEVNULLrun)r)   r    ignore_outputcommandr=   r5   r6   kws           r   	_run_hookrH   ~   su     !UD1C!++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
entrypointrI   z*Could not find entrypoint console_scripts.z-czimport z; r:   z())r;   r   importlib_metadata_getr   r   r   sys
executablemoduleattrrH   )r)   r    rE   entrypoint_nameentryimplrF   s          r   rI   rI      s     +7LAO../@A 
::(D

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

 	
$++bQtyyk<G
 dG]G4r   execc                <    t        |d      }t        | |||g       y )NrN   )rF   )r;   rH   )r)   r    rE   rN   s       r   exec_rV      s    %g|<JdG]ZLAr   rO   c                    t        |d      }t        j                  j                  |      t        j                  d|       t
        j                  d|g}t        | |||       y )NrO   zCould not find module z-m)r;   	importlibr   	find_specr   rM   rN   rH   )r)   r    rE   module_namerF   s        r   rO   rO      sZ    &w9K~~,4"8 FGG~~t[1GdG]G4r   )r   strreturnr   )r   r[   r   Union[str, os.PathLike[str]]r    r   r\   r   )r)   r]   r*   zlist[PostWriteHookConfig]r\   None)r5   r[   r)   r[   r\   	List[str])r    r   r   r[   r\   r[   )
r)   r[   r    r   rE   boolrF   r_   r\   r^   )F)r)   r[   r    r   rE   r`   r\   r^   )#
__future__r   importlib.utilrX   osr1   rB   rM   typingr   r   r   r   r   r	   r
   r>   r   r   util.pyfilesr   configr   r0   r   __annotations__r   r#   r,   r8   r;   rH   rI   rV   rO   r   r   r   <module>rh      sF   #  	   
           2,2 	4 &,
,/, !, 		,0+
&+/H+	+* *E
EE-1E<EE	E 

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