U of@s*UddlmZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z d d l mZd d lmZd ZiZded<dddddZdddddddZddddddZdddd d!d"Zed#d+ddd%dd&d'd#Zed(d,ddd%dd&d)d*ZdS)-) annotationsN)Any)Callable)Dict)List)Mapping)Optional)Union)util)compatZREVISION_SCRIPT_FILENAMEdict _registrystrr)namereturncsfdd}|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` cs |t<|S)N)r)fnrH/opt/hc_python/lib/python3.8/site-packages/alembic/script/write_hooks.pydecorate&szregister..decorater)rrrrrregisters rzMapping[str, Union[str, int]]r)rrevisionoptionsrc CsRz t|}Wn6tk rB}ztd|d|W5d}~XYn X|||SdS)a7Invokes 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` zNo formatter with name 'z ' registeredN)rKeyErrorr CommandError)rrrhookkerrr_invoke-s   rzMapping[str, str]None)path hook_configrc sddlm}|dd}|D]s,q"fddD}|d<z |d}Wn:tk r}ztd d |W5d }~XYq"Xtjd d dt|||W5QRXq"d S)z&Invoke hooks for a generated revision.)_split_on_space_commahookscs4i|],}|dr|tdd|qS).r"N) startswithlen).0keyr!rrr Lsz_run_hooks.. _hook_nametypeKey z&.type is required for post write hook NzRunning post write hook T)newline) baser#splitgetrr rstatusr)r r!r#namesoptstype_rrr+r _run_hooksBs,   r8z List[str])cmdline_options_strr rcs:t|krtd|}tj|tjd}fdd|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.  )posixcsg|]}|tqSr)replaceREVISION_SCRIPT_TOKEN)r)optionr rr msz*_parse_cmdline_options..)r=shlexr2r Zis_posix)r9r cmdline_options_listrr?r_parse_cmdline_options_s   rCconsole_scriptsFbool)r r ignore_outputrc Csz |d}WnBtk rN}z$td|dd|d|W5d}~XYnXtdD]}|j|krZ|}qqZtd||dd}|dd }t||} i} |rtj | d <| d <tj t j d d |j d|j d|jdg| fd|i| dS)N entrypointr/r-z,.entrypoint is required for post write hook rDz*Could not find entrypoint console_scripts.cwdrr%stdoutstderrz-czimport z; r&z())rr rr Zimportlib_metadata_getrr3rC subprocessDEVNULLrunsys executablemoduleattr) r rrFZentrypoint_namerentryimplrHr9rBkwrrrrDtsB     execc Csz |d}WnBtk rN}z$td|dd|d|W5d}~XYnX|dd}|dd}t||}i}|rtj|d<|d <tj|f|fd|i|dS) NrOr/r-z,.executable is required for post write hook rHrr%rIrJ)rr rr3rCrKrLrM) r rrFrOrrHr9rBrTrrrexec_s0    rV)F)F) __future__rrArKrNtypingrrrrrrr r%r r r=r__annotations__rrr8rCrDrVrrrrs0           &