
    ѮhL                       d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dlZd dl	m
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 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   G d d      Z!ee"e"f   Z# G d ded      Z$ G d de      Z% G d  d!      Z&	 	 d$	 	 	 	 	 	 	 d%d"Z'e(d#k(  r e'        yy)&    )annotations)ArgumentParser)	Namespace)ConfigParserN)Path)Any)cast)Dict)Mapping)Optional)overload)Protocol)Sequence)TextIO)Union)	TypedDict   )__version__)command)util)compat)_preserving_path_as_strc                     e Zd ZU dZddddej
                  d ej                         df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)dZdZ	de
d<   	 dZde
d	<   	 dZde
d
<   	 ed*d       Zed*d       ZdZde
d<   	 ej"                  d+d       Zd,dZej"                  d-d       Zej"                  d.d       Zd/dZd0dZe	 d1	 	 	 	 	 d2d       Ze	 	 	 	 	 	 d3d       Ze	 	 	 	 	 	 d4d       Z	 d5	 	 	 	 	 d6dZd7dZd8dZd9dZ	 d5	 	 	 	 	 	 	 d:dZed;d       Ze	 d5	 	 	 	 	 d<d       Z	 d5	 	 	 	 	 d<dZed;d       Ze	 d5	 	 	 	 	 d<d        Z	 d5	 	 	 	 	 d=d!Zd>d"Z 	 d5	 	 	 	 	 d?d#Z!ej"                  d@d$       Z"dAd%Z#dBd&Z$dBd'Z%dCd(Z&y)DConfiga;  Represent an Alembic configuration.

    Within an ``env.py`` script, this is available
    via the :attr:`.EnvironmentContext.config` attribute,
    which in turn is available at ``alembic.context``::

        from alembic import context

        some_param = context.config.get_main_option("my option")

    When invoking Alembic programmatically, a new
    :class:`.Config` can be created by passing
    the name of an .ini file to the constructor::

        from alembic.config import Config
        alembic_cfg = Config("/path/to/yourapp/alembic.ini")

    With a :class:`.Config` object, you can then
    run Alembic commands programmatically using the directives
    in :mod:`alembic.command`.

    The :class:`.Config` object can also be constructed without
    a filename.   Values can be set programmatically, and
    new sections will be created as needed::

        from alembic.config import Config
        alembic_cfg = Config()
        alembic_cfg.set_main_option("script_location", "myapp:migrations")
        alembic_cfg.set_main_option("sqlalchemy.url", "postgresql://foo/bar")
        alembic_cfg.set_section_option("mysection", "foo", "bar")

    .. warning::

       When using programmatic configuration, make sure the
       ``env.py`` file in use is compatible with the target configuration;
       including that the call to Python ``logging.fileConfig()`` is
       omitted if the programmatic configuration doesn't actually include
       logging directives.

    For passing non-string values to environments, such as connections and
    engines, use the :attr:`.Config.attributes` dictionary::

        with engine.begin() as connection:
            alembic_cfg.attributes['connection'] = connection
            command.upgrade(alembic_cfg, "head")

    :param file\_: name of the .ini file to open if an ``alembic.ini`` is
     to be used.    This should refer to the ``alembic.ini`` file, either as
     a filename or a full path to the file.  This filename if passed must refer
     to an **ini file in ConfigParser format** only.

    :param toml\_file: name of the pyproject.toml file to open if a
     ``pyproject.toml`` file is to be used.  This should refer to the
     ``pyproject.toml`` file, either as a filename or a full path to the file.
     This file must be in toml format. Both :paramref:`.Config.file\_` and
     :paramref:`.Config.toml\_file` may be passed simultaneously, or
     exclusively.

     .. versionadded:: 1.16.0

    :param ini_section: name of the main Alembic section within the
     .ini file
    :param output_buffer: optional file-like input buffer which
     will be passed to the :class:`.MigrationContext` - used to redirect
     the output of "offline generation" when using Alembic programmatically.
    :param stdout: buffer where the "print" output of commands will be sent.
     Defaults to ``sys.stdout``.

    :param config_args: A dictionary of keys and values that will be used
     for substitution in the alembic config file, as well as the pyproject.toml
     file, depending on which / both are used.  The dictionary as given is
     **copied** to two new, independent dictionaries, stored locally under the
     attributes ``.config_args`` and ``.toml_args``.   Both of these
     dictionaries will also be populated with the replacement variable
     ``%(here)s``, which refers to the location of the .ini and/or .toml file
     as appropriate.

    :param attributes: optional dictionary of arbitrary Python keys/values,
     which will be populated into the :attr:`.Config.attributes` dictionary.

     .. seealso::

        :ref:`connection_sharing`

    Nalembicstrcmd_optsOptional[Namespace]c	                   |rt        |      nd| _        |rt        |      nd| _        || _        || _        || _        || _        t        |      | _        t        |      | _	        |r| j                  j                  |       yy)z Construct a new :class:`.Config`N)r   config_file_nametoml_file_nameconfig_ini_sectionoutput_bufferstdoutr   dictconfig_args	toml_args
attributesupdate)	selffile_	toml_fileini_sectionr#   r$   r   r&   r(   s	            `/home/www/academy-backend.kofcorporation.com/venv/lib/python3.12/site-packages/alembic/config.py__init__zConfig.__init__v   s     /4#E* 	 3<#I. 	 #.* ,k*OO"":.     Optional[str]r    r!   c                F    | j                   y t        | j                         S N)r    r   r*   s    r.   _config_file_pathzConfig._config_file_path   s"      (D))**r0   c                F    | j                   y t        | j                         S r3   )r!   r   r4   s    r.   _toml_file_pathzConfig._toml_file_path   s"    &D''((r0   r"   c                    i S )a  A Python dictionary for storage of additional state.


        This is a utility dictionary which can include not just strings but
        engines, connections, schema objects, or anything else.
        Use this to pass objects into an env.py script, such as passing
        a :class:`sqlalchemy.engine.base.Connection` when calling
        commands from :mod:`alembic.command` programmatically.

        .. seealso::

            :ref:`connection_sharing`

            :paramref:`.Config.attributes`

         r4   s    r.   r(   zConfig.attributes   s	    $ 	r0   c                    |rt        |      |z  }nt        |      }t        j                  | j                  |dfi | j                   y)a  Render a message to standard out.

        When :meth:`.Config.print_stdout` is called with additional args
        those arguments will formatted against the provided text,
        otherwise we simply output the provided text verbatim.

        This is a no-op when the``quiet`` messaging option is enabled.

        e.g.::

            >>> config.print_stdout('Some text %s', 'arg')
            Some Text arg

        
N)r   r   write_outstreamr$   messaging_opts)r*   textargoutputs       r.   print_stdoutzConfig.print_stdout   s>      Y_FYFT[[&$N$:M:MNr0   c                t   | j                   r%| j                   j                         j                  }n
t               }|j	                         | j
                  d<   t        | j
                        }| j                   r#t        j                  || j                   g       |S |j                  | j                         |S )a  Return the underlying ``ConfigParser`` object.

        Dir*-ect access to the .ini file is available here,
        though the :meth:`.Config.get_section` and
        :meth:`.Config.get_main_option`
        methods provide a possibly simpler interface.

        here)r5   absoluteparentr   as_posixr&   r   r   read_config_parseradd_sectionr"   )r*   rC   file_configs      r.   rI   zConfig.file_config   s     !!))224;;D6D#'==? "4#3#34!!%%kD4J4J3KL  ##D$;$;<r0   c                   | j                   r| j                   j                         r| j                   j                         j                  }|j	                         | j
                  d<   t        | j                   d      5 }t        j                  j                  |      }|j                  di       j                  di       }t        |t              st        j                  d      |cddd       S i S # 1 sw Y   yxY w)zMReturn a dictionary of the [tool.alembic] section from
        pyproject.tomlrC   rbtoolr   zIncorrect TOML formatN)r7   existsrD   rE   rF   r'   openr   tomllibloadget
isinstancer%   r   CommandError)r*   rC   f	toml_datadatas        r.   toml_alembic_configzConfig.toml_alembic_config   s    
 D$8$8$?$?$A''00299D%)]]_DNN6"d**D1 Q"NN//2	 }}VR044YC!$-++,CDD  I s   >A(C22C;c                    ddl }t        |j                        j                         j                  }t        |dz        S )zReturn the directory where Alembic setup templates are found.

        This method is used by the alembic ``init`` and ``list_templates``
        commands.

        r   N	templates)r   r   __file__rD   rE   r   )r*   r   package_dirs      r.   get_template_directoryzConfig.get_template_directory  s6     	7++,557>>;,--r0   c                4    t        | j                               S )zReturn the directory where Alembic setup templates are found.

        This method is used by the alembic ``init`` and ``list_templates``
        commands.

        .. versionadded:: 1.16.0

        )r   r\   r4   s    r.   _get_template_pathzConfig._get_template_path  s     D//122r0   c                     y r3   r9   r*   namedefaults      r.   get_sectionzConfig.get_section(  s     $'r0   c                     y r3   r9   r`   s      r.   rc   zConfig.get_section0  s     r0   c                     y r3   r9   r`   s      r.   rc   zConfig.get_section5  s     47r0   c                    | j                   j                  |      s|S t        | j                   j                  |            S )zReturn all the configuration options from a given .ini file section
        as a dictionary.

        If the given section does not exist, the value of ``default``
        is returned, which is expected to be a dictionary or other mapping.

        )rI   has_sectionr%   itemsr`   s      r.   rc   zConfig.get_section:  s9     ++D1ND$$**4011r0   c                >    | j                  | j                  ||       y)a:  Set an option programmatically within the 'main' section.

        This overrides whatever was in the .ini file.

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)set_section_optionr"   r*   ra   values      r.   set_main_optionzConfig.set_main_optionI  s     	 7 7uEr0   c                P    | j                   j                  | j                  |       y r3   )rI   remove_optionr"   )r*   ra   s     r.   remove_main_optionzConfig.remove_main_optionZ  s    &&t'>'>Er0   c                    | j                   j                  |      s| j                   j                  |       | j                   j                  |||       y)aW  Set an option programmatically within the given section.

        The section is created if it doesn't exist already.
        The value here will override whatever was in the .ini
        file.

        Does **NOT** consume from the pyproject.toml file.

        .. seealso::

            :meth:`.Config.get_alembic_option` - includes pyproject support

        :param section: name of the section

        :param name: name of the value

        :param value: the value.  Note that this value is passed to
         ``ConfigParser.set``, which supports variable interpolation using
         pyformat (e.g. ``%(some_value)s``).   A raw percent sign not part of
         an interpolation symbol must therefore be escaped, e.g. ``%%``.
         The given value may refer to another value already in the file
         using the interpolation format.

        N)rI   rg   rH   set)r*   sectionra   rl   s       r.   rj   zConfig.set_section_option]  sD    4 ++G4((1WdE2r0   c                    | j                   j                  |      s&t        j                  d| j                  d|d      | j                   j                  ||      r| j                   j                  ||      S |S )z9Return an option from the given section of the .ini file.zNo config file z found, or file has no '[z
]' section)rI   rg   r   rS   r    
has_optionrQ   )r*   rs   ra   rb   s       r.   get_section_optionzConfig.get_section_option{  sr     ++G4##$($9$97D  &&w5##''66Nr0   c                     y r3   r9   r`   s      r.   get_main_optionzConfig.get_main_option  s    ?Br0   c                     y r3   r9   r`   s      r.   rx   zConfig.get_main_option       r0   c                <    | j                  | j                  ||      S )a  Return an option from the 'main' section of the .ini file.

        This defaults to being a key from the ``[alembic]``
        section, unless the ``-n/--name`` flag were used to
        indicate a different section.

        Does **NOT** consume from the pyproject.toml file.

        .. seealso::

            :meth:`.Config.get_alembic_option` - includes pyproject support

        )rv   r"   r`   s      r.   rx   zConfig.get_main_option  s      &&t'>'>gNNr0   c                     y r3   r9   r`   s      r.   get_alembic_optionzConfig.get_alembic_option  s    BEr0   c                     y r3   r9   r`   s      r.   r}   zConfig.get_alembic_option  rz   r0   c                    | j                   j                  | j                  |      r&| j                   j                  | j                  |      S | j	                  ||      S )a  Return an option from the "[alembic]" or "[tool.alembic]" section
        of the configparser-parsed .ini file (e.g. ``alembic.ini``) or
        toml-parsed ``pyproject.toml`` file.

        The value returned is expected to be None, string, list of strings,
        or dictionary of strings.   Within each type of string value, the
        ``%(here)s`` token is substituted out with the absolute path of the
        ``pyproject.toml`` file, as are other tokens which are extracted from
        the :paramref:`.Config.config_args` dictionary.

        Searches always prioritize the configparser namespace first, before
        searching in the toml namespace.

        If Alembic was run using the ``-n/--name`` flag to indicate an
        alternate main section name, this is taken into account **only** for
        the configparser-parsed .ini file.  The section name in toml is always
        ``[tool.alembic]``.


        .. versionadded:: 1.16.0

        )rb   )rI   ru   r"   rQ   _get_toml_config_valuer`   s      r.   r}   zConfig.get_alembic_option  sU    4 &&t'>'>E##''(?(?FF..tW.EEr0   c                ,   | j                   j                  | j                  |      r)| j                   j                  | j                  |      dk(  S | j                  j                  |d      }t        |t              st        j                  d|      |S )NtrueFz*boolean value expected for TOML parameter )	rI   ru   r"   rQ   rW   rR   boolr   rS   rk   s      r.   get_alembic_boolean_optionz!Config.get_alembic_boolean_option  s    &&t'>'>E  $$T%<%<dCvM ,,00u=EeT*''@I  Lr0   c                   t               }| j                  j                  ||      }||u r|S |t        |t              r|| j
                  z  }|S t        |t              r|rWt        |d   t              rD|D cg c]3  }|j                         D ci c]  \  }}||| j
                  z   c}}5 }}}}|S t        d|D cg c]  }|| j
                  z   c}      }|S t        |t              r=t        d|j                         D ci c]  \  }}||| j
                  z   c}}      }|S t        j                  d|      |S c c}}w c c}}}w c c}w c c}}w )Nr   	list[str]zdict[str, str]z%unsupported TOML value type for key: )objectrW   rQ   rR   r   r'   listr%   rh   r	   r   rS   )r*   ra   rb   USE_DEFAULTrl   dvkvs           r.   r   zConfig._get_toml_config_value  st    h$$(({; 	 KN%%0( ' E4(Za$7 #(  >@XXZHTQA00HE "  !#E%Jqa4>>&:%JE  E4($9>GAQT^^,,G  '';D8D  ! I &K
 Hs$   <EE
.EE
E
Ec                v    t        t        t        j                  dt	        | j
                  dd      i            S )zThe messaging options.quietF)r	   MessagingOptionsr   immutabledictgetattrr   r4   s    r.   r=   zConfig.messaging_opts  s7     '$--%@A
 	
r0   c                    |D ]  }| j                  |      }| n y ddt        j                  ddd}	 ||   }|dk(  rt        j                  d       |S # t
        $ r}t        d|d	|d
      |d }~ww xY w)N r;   :;)spacenewlineosr   r   version_path_separatorz[The version_path_separator configuration parameter is deprecated; please use path_separator'z' is not a valid value for z-; expected 'space', 'newline', 'os', ':', ';')rx   r   pathsepr   warn_deprecatedKeyError
ValueError)r*   namesra   	separatorsplit_on_pathsepkes          r.   _get_file_separator_charzConfig._get_file_separator_char  s     	D,,T2I$	
  **
		*C //$$? J  	 d$ 		s   A 	A7A22A7c                   | j                   j                  | j                  dd       }|r~| j                  dd      }|;t	        j
                  d       t        j                  d      }|j                  |      S |j                  |      D cg c]  }|r|j                          c}S t        d| j                  dd             S c c}w )Nversion_locationsfallbackpath_separatorr   zNo path_separator found in configuration; falling back to legacy splitting on spaces/commas for version_locations.  Consider adding path_separator=os to Alembic config.
, *|(?: +)r   rI   rQ   r"   r   r   r   recompilesplitstripr	   r   )r*   version_locations_str
split_char_split_on_space_commaxs        r.   get_version_locations_listz!Config.get_version_locations_list"  s     $ 0 0 4 4##%84 !5 !
 !66 ":J ! $$; )+

=(A%,223HII 388D GGI  ++,?F s   Cc                   | j                   j                  | j                  dd       }|r}| j                  d      }|;t	        j
                  d       t        j                  d      }|j                  |      S |j                  |      D cg c]  }|r|j                          c}S t        d| j                  dd             S c c}w )Nprepend_sys_pathr   r   zNo path_separator found in configuration; falling back to legacy splitting on spaces, commas, and colons for prepend_sys_path.  Consider adding path_separator=os to Alembic config.z, *|(?: +)|\:r   r   )r*   prepend_sys_path_strr   _split_on_space_comma_colonr   s        r.   get_prepend_sys_paths_listz!Config.get_prepend_sys_paths_listE  s    #//33##%7$  4  
  667GHJ! $$; /1jj9I.J+2889MNN 277
C GGI  ++,>E s   Cc                0   g }| j                   j                  d      sUt        d| j                  dg             }|D ]2  }t	        |      }|j                  d      |d<   |j                  |       4 |S t        j                  d      }| j                  di       }|j                  |j                  dd            }|D ]Q  }|s|D 	ci c]+  }	|	j                  |dz         r|	t        |      d	z   d  ||	   - }}	||d<   |j                  |       S |S c c}	w )
Npost_write_hookszlist[dict[str, str]]ra   
_hook_namer   hooks .r   )rI   rg   r	   r   r%   popappendr   r   rc   r   rQ   
startswithlen)
r*   r   toml_hook_configcfgoptsr   ini_hook_configr   ra   keys
             r.   get_hooks_listzConfig.get_hooks_liste  sB   +-++,>?#&++,>C  ( #Cy%)XXf%5\"T"#0 % %'JJ}$=!"../A2FO)//##GR0E  
#  /~~dSj1 D	A(/#*>>  &*\"T"
# s   0D)r+   "Union[str, os.PathLike[str], None]r,   r   r-   r   r#   zOptional[TextIO]r$   r   r   r   r&   Mapping[str, Any]r(   zOptional[Dict[str, Any]]returnNone)r   zOptional[Path])r   zDict[str, Any])r>   r   r?   r   r   r   )r   r   )r   r   )r   r   )r   r   ).)ra   r   rb   r   r   zOptional[Dict[str, str]])ra   r   rb   Dict[str, str]r   r   )ra   r   rb   zMapping[str, str]r   z(Union[Dict[str, str], Mapping[str, str]]r3   )ra   r   rb   Optional[Mapping[str, str]]r   r   )ra   r   rl   r   r   r   )ra   r   r   r   )rs   r   ra   r   rl   r   r   r   )rs   r   ra   r   rb   r1   r   r1   )ra   r   rb   r   r   r   )ra   r   rb   r1   r   r1   )ra   r   rb   r1   r   AUnion[None, str, list[str], dict[str, str], list[dict[str, str]]])ra   r   r   r   )ra   r   rb   zOptional[Any]r   r   )r   r   )r   r   r   r1   )r   zOptional[list[str]])r   zlist[PostWriteHookConfig])'__name__
__module____qualname____doc__sysr$   r   r   r/   r   __annotations__r    r!   propertyr5   r7   r"   memoized_propertyr(   rA   rI   rW   r\   r^   r   rc   rm   rp   rj   rv   rx   r}   r   r   r=   r   r   r   r   r9   r0   r.   r   r      s_   Tp 598<$*.(,);););)=/3/1/ 6/ 	/
 (/ / &/ '/ -/ 
/6 %)H!(	 '+m*2$(NM( + +
 ) )
 #" 
 &O. 
 , 
 &
.	3 ),''"&'	!' ' "0	  77"37	17 7
 AE22"=2	$2F"F3> AE"%0=	 B B26"/	 
 37OO"/O	O$ E E26"/	 
 37FF"/F	JF> 37"/	JB 

 
@!F@!r0   r   c                      e Zd ZU ded<   y)r   r   r   N)r   r   r   r   r9   r0   r.   r   r     s    Kr0   r   F)totalc                  $    e Zd ZU dZded<   ddZy)CommandFunctionzA function that may be registered in the CLI as an alembic command.
    It must be a named function and it must accept a :class:`.Config` object
    as the first argument.

    .. versionadded:: 1.15.3

    r   r   c                     y r3   r9   )r*   configargskwargss       r.   __call__zCommandFunction.__call__  s    r0   N)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r9   r0   r.   r   r     s     MMr0   r   c            	      z   e Zd ZU dZdTdUdZi ddd eded	      fd
dd eed      fdd edd      fdd eed      fdd eed      fdd edd      fdd edd       fd!d" eed#      fd$d% eed&      fd'd( eed)      fd*d+d, edd-      fd.d/ edd0      fd1d2 edd3      fd4d5d6 ed7d8      fd9d:d; edd<      fd=d> edd?      fd@dA eddB      fZ edCD       edED       edFdGH      dIZe	j                  dJdKiiZdLedM<   dUdNZdVdOZdWdPZdXdQZdYdRZdTdZdSZy)[CommandLinez/Provides the command line interface to Alembic.Nc                &    | j                  |       y r3   )_generate_args)r*   progs     r.   r/   zCommandLine.__init__  s    D!r0   templatez-tz
--templategenericz"Setup template for use with 'init')rb   typehelpmessagez-mz	--messagez%Message string to use with 'revision')r   r   sqlz--sql
store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionr   tagz--tagz<Arbitrary 'tag' name - can be used by custom env.py scripts.headz--headzCSpecify head revision or <branchname>@head to base new revision on.splicez--splicez6Allow a non-head revision as the 'head' to splice onto
depends_onz--depends-onr   zNSpecify one or more revision identifiers which this revision should depend on.rev_idz--rev-idz9Specify a hardcoded revision id instead of generating oneversion_pathz--version-pathz2Specify specific path from config for version filebranch_labelz--branch-labelz3Specify a branch label to apply to the new revisionverbosez-vz	--verbosezUse more verbose outputresolve_dependenciesz--resolve-dependenciesz+Treat dependency versions as down revisionsautogeneratez--autogeneratezgPopulate revision script with candidate migration operations, based on comparison of database to model.	rev_rangez-rz--rev-rangestorez1Specify a revision range; format is [start]:[end]indicate_currentz-iz--indicate-currentzIndicate the current revisionpurgez--purgez7Unconditionally erase the version table before stampingpackagez	--packagezFWrite empty __init__.py files to the environment and version locationszlocation of scripts directoryr   zrevision identifier+z/one or more revisions, or 'heads' for all heads)nargsr   )	directoryrevision	revisionsr  r  zdict[Any, dict[str, str]]_POSITIONAL_TRANSLATIONSc                   t        |      }|j                  dddt        z         |j                  dddd	
       |j                  ddt        dd       |j                  ddd
       |j                  ddd
       |j                  dddd
       |j	                         | _        d d t        t              D        D        }|D ]  }| j                  |        || _	        y )Nr   z	--versionversionz%%(prog)s %s)r   r  z-cz--configr   zAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini". May also refer to pyproject.toml file.  May be specified twice to reference both files separatelyr   z-nz--namer   zfName of section in .ini file to use for Alembic config (only applies to configparser config, not toml))r   rb   r   z-xzlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingz
--raiseerrr   z!Raise a full stack trace on errorz-qz--quietzDo not log to std output.c              3     K   | ]J  }t        j                  |      r3|j                  d    dk7  r!|j                  dk(  rt	        t
        |       L yw)r   _zalembic.commandN)inspect
isfunctionr   r   r	   r   ).0fns     r.   	<genexpr>z-CommandLine._generate_args.<locals>.<genexpr>_  sJ      
""2&KKNc)MM%66 "%
s   AAc              3  <   K   | ]  }t        t        |        y wr3   )r   r   )r  ra   s     r.   r  z-CommandLine._generate_args.<locals>.<genexpr>a  s     G$ww-Gs   )
r   add_argumentr   r   add_subparsers
subparsersdirr   register_commandparser)r*   r   r  alembic_commandsr  s        r.   r   zCommandLine._generate_args4  s&   T*	>K3O 	 	
 	1	 	 	
 	> 	 	
 	; 	 	
 	4 	 	

 	,	 	 	
 !//1
G#g,G
 # 	&B!!"%	& r0   c                   | j                  |      \  }}}| j                  j                  |j                  |      }|j	                  |||f       |D ]<  }|| j
                  v s| j
                  |   }|dd |d   }	} |j                  |i |	 > |D ]1  }| j                  j                  |i       }	 |j                  |fi |	 3 y)a-  Registers a function as a CLI subcommand. The subcommand name
        matches the function name, the arguments are extracted from the
        signature and the help text is read from the docstring.

        .. versionadded:: 1.15.3

        .. seealso::

            :ref:`custom_commandline`
        r   )cmdr   N)	_inspect_functionr  
add_parserr   set_defaults_KWARGS_OPTSr  _POSITIONAL_OPTSrQ   )
r*   r  
positionalkwarg	help_text	subparserr?   	kwarg_optr   r   s
             r.   r  zCommandLine.register_commandn  s     (,'='=b'A$
E9OO..r{{.K	B
E#:; 	6Cd''' --c2	&q_imd&	&&55		6  	0C((,,S"5D"I""3/$/	0r0   c                   t        j                  |      }|d   +|d   dt        |d           }|d   t        |d          d  }n
|d   dd  }g }|| j                  v r,|D cg c]!  }| j                  |   j	                  ||      # }}|j
                  }|rJg }|j                  d      D ]3  }|j                         s n$|j                  |j                                5 ng }dj                  |      }	|||	fS c c}w )N   r   r   r;   r   )
r   inspect_getfullargspecr   r  rQ   r   r   r   r   join)
r*   r  specr   r!  ra   help_
help_linesliner"  s
             r.   r  zCommandLine._inspect_function  s   ,,R07ac$q'l]3JGSa\MO,EaJE... ' --b155dDAJ  

JD) 4zz|%%djjl3	4 JHHZ(	5)++'s   "&C:c                d   |j                   \  }}}	  ||g|D cg c]  }t        ||d        c}i |D ci c]  }|t        ||d        c} y c c}w c c}w # t        j                  $ r@}|j                  r t        j
                  t        |      fi |j                   Y d }~y d }~ww xY wr3   )r  r   r   rS   raiseerrerrr   r=   )r*   r   optionsr  r   r!  r   es           r.   run_cmdzCommandLine.run_cmd  s     'J
	:5?@''1d+@ :??A1ggq$//?@?   	:Q96#8#89		:s2   A A
	A AA 
A B//6B**B/c                   |j                   }t        j                  j                  d      }|r't        j                  j                  |      dk(  r|}d}n|rd}|}nd}d}|s||fS d x}}|D ]W  }t        j                  j                  |      dk(  r|t        j                  d      |}?|t        j                  d      |}Y |r|n||r|fS |fS )NALEMBIC_CONFIGzpyproject.tomlzalembic.iniz'pyproject.toml indicated more than oncez"only one ini file may be indicated)r   r   environrQ   pathbasenamer   rS   )	r*   r0  r   alembic_config_envdefault_pyproject_tomldefault_alembic_configtomlinira   s	            r.   _inis_from_configzCommandLine._inis_from_config  s   ZZ^^,<=  !348HH%7"%2"%5"%7"%2"%5")+AAAs 	Dww%)99#++A  ?++<  	 t!7C
 	
2
 	
r0   c                   | j                   j                  |      }t        |d      s| j                   j                  d       y| j	                  |      \  }}t        |||j                  |      }| j                  ||       y)z6Executes the command line with the provided arguments.r  ztoo few arguments)r+   r,   r-   r   N)r  
parse_argshasattrerrorr=  r   ra   r2  )r*   argvr0  r;  r<  r   s         r.   mainzCommandLine.main  ss    ++((.w& KK12..w7ID##LL 	C LLg&r0   r3   )r   r1   r   r   )r  r   r   r   )r  r   r   ztuple[Any, Any, str])r   r   r0  r   r   r   )r0  r   r   ztuple[str, str])rB  Optional[Sequence[str]]r   r   )r   r   r   r   r/   r%   r   r  r  r   stampr  r   r   r  r  r2  r=  rC  r9   r0   r.   r   r     s   9"A!9
A 	c GH
A 	# 
A0 	)
1A@ 	+
AAP 	#M
QA^ 	8
_An 	!
oA~ 	I
AL 	J
MAZ 	+DE
[Ad 	$#B!
eAr 	#(
sAD 	H
EAT 	 #4
UAd 	#N
eAr 	#4
sALF >?&
 B
	 	
K0;7 8t06,>:&
P'r0   r   c                <    t        |      j                  |        y)z(The console runner function for Alembic.r  )rB  N)r   rC  )rB  r   r   s      r.   rC  rC    s     TT*r0   __main__)NN)rB  rD  r   r1   r   r   r   r   ))
__future__r   argparser   r   configparserr   r  r   pathlibr   r   r   typingr   r	   r
   r   r   r   r   r   r   r   typing_extensionsr   r   r   r   r   r   util.pyfilesr   r   r   PostWriteHookConfigr   r   r   rC  r   r9   r0   r.   <module>rP     s    " #  %  	  	 
           '     1g	 g	T c3h' y Nh NP' P'h
 %)+
!+
+ + 
	+ zF r0   