o
    8 h                     @  s  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 dZ!ee"e"f Z#G dd deddZ$G dd deZ%G d d! d!Z&		d-d.d*d+Z'e(d,kre'  dS dS )/    )annotations)ArgumentParser)	Namespace)ConfigParserN)Path)Any)cast)Dict)Mapping)Optional)overload)Protocol)Sequence)TextIO)Union)	TypedDict   )__version__)command)util)compat)_preserving_path_as_strc                   @  s  e Zd ZU dZddddejde dfdfddZdZ	de
d< 	 dZde
d< 	 dZde
d< 	 edgddZedgddZdZde
d< 	 ejdhd!d"Zdid&d'Zejdjd)d*Zejdkd+d,Zdld-d.Zdmd0d1Ze	2dndod6d7Zedpd9d7Zedqd<d7Z	drdsd>d7Zdtd@dAZdudBdCZdvdEdFZ	drdwdGdHZedxdIdJZe	drdydKdJZ	drdydLdJZedxdMdNZe	drdydOdNZ	drdzdQdNZd{dSdTZ 	drd|dVdWZ!ejd}dYdZZ"d~d\d]Z#dd_d`Z$ddadbZ%ddddeZ&dS )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file_"Union[str, os.PathLike[str], None]	toml_fileini_sectionstroutput_bufferOptional[TextIO]stdoutr   cmd_optsOptional[Namespace]config_argsMapping[str, Any]
attributesOptional[Dict[str, Any]]returnNonec	           	      C  sh   |rt |nd| _|rt |nd| _|| _|| _|| _|| _t|| _t|| _	|r2| j
| dS dS )z Construct a new :class:`.Config`N)r   config_file_nametoml_file_nameconfig_ini_sectionr   r!   r"   dictr$   	toml_argsr&   update)	selfr   r   r   r   r!   r"   r$   r&    r1   V/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/alembic/config.py__init__v   s   

zConfig.__init__Optional[str]r*   r+   Optional[Path]c                 C     | j d u rd S t| j S N)r*   r   r0   r1   r1   r2   _config_file_path      

zConfig._config_file_pathc                 C  r6   r7   )r+   r   r8   r1   r1   r2   _toml_file_path   r:   zConfig._toml_file_pathr,   Dict[str, Any]c                 C  s   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`

        r1   r8   r1   r1   r2   r&      s   zConfig.attributestextargr   c                 G  s8   |r	t || }nt |}tj| j|dfi | j dS )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)r0   r=   r>   outputr1   r1   r2   print_stdout   s   zConfig.print_stdoutr   c                 C  s\   | j r
| j  j}nt }| | jd< t| j}| j r&t|| j g |S |	| 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)r9   absoluteparentr   as_posixr$   r   r   read_config_parseradd_sectionr,   )r0   rD   file_configr1   r1   r2   rJ      s   
zConfig.file_configc                 C  s   | j rI| j  rI| j  j}| | jd< t| j d$}tj	|}|
di 
di }t|ts6td|W  d   S 1 sBw   Y  dS i S )zMReturn a dictionary of the [tool.alembic] section from
        pyproject.tomlrD   rbZtoolr   zIncorrect TOML formatN)r;   existsrE   rF   rG   r.   openr   tomllibloadget
isinstancer-   r   CommandError)r0   rD   fZ	toml_datadatar1   r1   r2   toml_alembic_config   s   

$zConfig.toml_alembic_configc                 C  s$   ddl }t|j j}t|d 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__rE   rF   r   )r0   r   package_dirr1   r1   r2   get_template_directory  s   zConfig.get_template_directoryr   c                 C  s   t |  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   rY   r8   r1   r1   r2   _get_template_path  s   	zConfig._get_template_path.namedefaultOptional[Dict[str, str]]c                 C     d S r7   r1   r0   r[   r\   r1   r1   r2   get_section(     zConfig.get_sectionDict[str, str]c                 C  r^   r7   r1   r_   r1   r1   r2   r`   0  ra   Mapping[str, str](Union[Dict[str, str], Mapping[str, str]]c                 C  r^   r7   r1   r_   r1   r1   r2   r`   5  ra   Optional[Mapping[str, str]]c                 C  s    | j |s|S t| 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.

        )rJ   has_sectionr-   itemsr_   r1   r1   r2   r`   :  s   
valuec                 C  s   |  | j|| dS )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,   r0   r[   rh   r1   r1   r2   set_main_optionI  s   zConfig.set_main_optionc                 C  s   | j | j| d S r7   )rJ   remove_optionr,   )r0   r[   r1   r1   r2   remove_main_optionZ  s   zConfig.remove_main_optionsectionc                 C  s,   | j |s| j | | j ||| dS )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)rJ   rf   rI   set)r0   rn   r[   rh   r1   r1   r2   ri   ]  s   zConfig.set_section_optionc                 C  s@   | j |std| j|f | j ||r| j ||S |S )z9Return an option from the given section of the .ini file.z6No config file %r found, or file has no '[%s]' section)rJ   rf   r   rR   r*   
has_optionrP   )r0   rn   r[   r\   r1   r1   r2   get_section_option{  s   zConfig.get_section_optionc                 C  r^   r7   r1   r_   r1   r1   r2   get_main_option     zConfig.get_main_optionc                 C  r^   r7   r1   r_   r1   r1   r2   rr     ra   c                 C  s   |  | 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

        )rq   r,   r_   r1   r1   r2   rr     s   c                 C  r^   r7   r1   r_   r1   r1   r2   get_alembic_option  rs   zConfig.get_alembic_optionc                 C  r^   r7   r1   r_   r1   r1   r2   rt     ra   FUnion[None, str, list[str], dict[str, str], list[dict[str, str]], int]c                 C  s.   | j | j|r| j | j|S | j||d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

        )r\   )rJ   rp   r,   rP   _get_toml_config_valuer_   r1   r1   r2   rt     s   boolc                 C  sP   | j | j|r| j | j|dkS | j|d}t|ts&td||S )NtrueFz*boolean value expected for TOML parameter )	rJ   rp   r,   rP   rU   rQ   rw   r   rR   rj   r1   r1   r2   get_alembic_boolean_option  s   
z!Config.get_alembic_boolean_optionOptional[Any]c                   s   t  } j||}||u r|S |d urkt|tr | j }|S t|trG|r9t|d tr9 fdd|D }|S td fdd|D }|S t|tr\td fdd|	 D }|S t|t
rc|S td	||S )
Nr   c                   s"   g | ]} fd d|  D qS )c                      i | ]
\}}|| j  qS r1   r.   .0kvr8   r1   r2   
<dictcomp>      z<Config._get_toml_config_value.<locals>.<listcomp>.<dictcomp>)rg   )r~   Zdvr8   r1   r2   
<listcomp>  s    z1Config._get_toml_config_value.<locals>.<listcomp>	list[str]c                   s   g | ]}| j  qS r1   r|   )r~   r   r8   r1   r2   r     s    zdict[str, str]c                   r{   r1   r|   r}   r8   r1   r2   r     r   z1Config._get_toml_config_value.<locals>.<dictcomp>z%unsupported TOML value type for key: )objectrU   rP   rQ   r   r.   listr-   r   rg   intr   rR   )r0   r[   r\   ZUSE_DEFAULTrh   r1   r8   r2   rv     s>   






zConfig._get_toml_config_valueMessagingOptionsc              	   C  s   t ttdt| jddiS )zThe messaging options.quietF)r   r   r   immutabledictgetattrr"   r8   r1   r1   r2   rA     s   zConfig.messaging_optsnamesc              
   G  s   |D ]}|  |}|d ur nqd S ddtjddd}z|| }W n ty6 } z	td||f |d }~ww |dkr@td |S )	N r?   :;)spacenewlineosr   r   zM'%s' is not a valid value for %s; expected 'space', 'newline', 'os', ':', ';'version_path_separatorz[The version_path_separator configuration parameter is deprecated; please use path_separator)rr   r   pathsepKeyError
ValueErrorr   warn_deprecated)r0   r   r[   	separatorZsplit_on_pathsepker1   r1   r2   _get_file_separator_char  s:   
zConfig._get_file_separator_charOptional[list[str]]c                 C  sp   | j j| jdd d}|r/| dd}|d u r%td td}||S dd ||D S t	d	| 
dd S )
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.
, *|(?: +)c                 S     g | ]}|r|  qS r1   stripr~   xr1   r1   r2   r   @      z5Config.get_version_locations_list.<locals>.<listcomp>r   rJ   rP   r,   r   r   r   recompilesplitr   rv   )r0   Zversion_locations_str
split_char_split_on_space_commar1   r1   r2   get_version_locations_list(  s(   


z!Config.get_version_locations_listc                 C  sn   | j j| jdd d}|r.| d}|d u r$td td}||S dd ||D S t	d| 
dd S )	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, *|(?: +)|\:c                 S  r   r1   r   r   r1   r1   r2   r   `  r   z5Config.get_prepend_sys_paths_list.<locals>.<listcomp>r   r   )r0   Zprepend_sys_path_strr   Z_split_on_space_comma_colonr1   r1   r2   get_prepend_sys_paths_listK  s$   



z!Config.get_prepend_sys_paths_listlist[PostWriteHookConfig]c                   s   g }| j ds(td| dg }|D ]}t|}|d|d< || q|S td}| 	di  |
 dd}|D ]sCq> fdd	 D }|d< || q>|S )
Npost_write_hookszlist[dict[str, str]]r[   
_hook_namer   hooks c                   s4   i | ]}| d  r|td d  | qS ).r   N)
startswithlen)r~   keyZini_hook_configr[   r1   r2   r     s    z)Config.get_hooks_list.<locals>.<dictcomp>)rJ   rf   r   rv   r-   popappendr   r   r`   r   rP   )r0   r   Ztoml_hook_configcfgoptsr   r   r1   r   r2   get_hooks_listk  s2   


zConfig.get_hooks_list)r   r   r   r   r   r   r   r    r!   r   r"   r#   r$   r%   r&   r'   r(   r)   )r(   r5   )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\   rb   r(   rb   )r[   r   r\   rc   r(   rd   r7   )r[   r   r\   re   r(   re   )r[   r   rh   r   r(   r)   )r[   r   r(   r)   )rn   r   r[   r   rh   r   r(   r)   )rn   r   r[   r   r\   r4   r(   r4   )r[   r   r\   r   r(   r   )r[   r   r\   r4   r(   r4   )r[   r   r\   r4   r(   ru   )r[   r   r(   rw   )r[   r   r\   rz   r(   ru   )r(   r   )r   r   r(   r4   )r(   r   )r(   r   )'__name__
__module____qualname____doc__sysr!   r   r   r3   r"   __annotations__r*   r+   propertyr9   r;   r,   memoized_propertyr&   rC   rJ   rU   rY   rZ   r   r`   rk   rm   ri   rq   rr   rt   ry   rv   rA   r   r   r   r   r1   r1   r1   r2   r      s   
 X






!%
	
 
# r   c                   @  s   e Zd ZU ded< dS )r   rw   r   N)r   r   r   r   r1   r1   r1   r2   r     s   
 r   F)totalc                   @  s$   e Zd ZU dZded< dd
dZdS )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   configr   argsr   kwargsr(   c                 O  r^   r7   r1   )r0   r   r   r   r1   r1   r2   __call__  s    zCommandFunction.__call__N)r   r   r   r   r   r   r(   r   )r   r   r   r   r   r   r1   r1   r1   r2   r     s   
 r   c                	   @  s  e Zd ZU dZdidjddZi d	d
dededdfdddeeddfddedddfddeeddfddeeddfdd edd!dfd"d#ed$d%dfd&d'eed(dfd)d*eed+dfd,d-eed.dfd/d0d1edd2dfd3d4edd5dfd6d7edd8dfd9d:d;ed<d=dfd>d?d@eddAdfdBdCeddDdfdEdFeddGdfZedHdIedJdIedKdLdMdNZe	j
dOdPiiZdQedR< djdSdTZdkdWdXZdldZd[Zdmd`daZdndcddZdidodgdhZdS )pCommandLinez/Provides the command line interface to Alembic.Nprogr4   r(   r)   c                 C  s   |  | d S r7   )_generate_args)r0   r   r1   r1   r2   r3     s   zCommandLine.__init__templatez-tz
--templateZgenericz"Setup template for use with 'init')r\   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                 C  s   t |d}|jdddt d |jdddd	d
 |jddtddd |jdddd
 |jdddd
 |jddddd
 | | _dd dd ttD D }|D ]}| | qP|| _	d S )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   r\   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                 s  s<    | ]}t |r|jd  dkr|jdkrtt|V  qdS )r   _zalembic.commandN)inspect
isfunctionr   r   r   r   )r~   fnr1   r1   r2   	<genexpr>e  s    
z-CommandLine._generate_args.<locals>.<genexpr>c                 s  s    | ]}t t|V  qd S r7   )r   r   r~   r[   r1   r1   r2   r   g  s    )
r   add_argumentr   r   add_subparsers
subparsersdirr   register_commandparser)r0   r   r   Zalembic_commandsr   r1   r1   r2   r   :  sP   

	


zCommandLine._generate_argsr   r   c           
      C  s   |  |\}}}| jj|j|d}|j|||fd |D ]}|| jv r;| j| }|dd |d }}	|j|i |	 q|D ]}| j|i }	|j|fi |	 q>dS )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_OPTSrP   )
r0   r   
positionalkwarg	help_textZ	subparserr>   Z	kwarg_optr   r   r1   r1   r2   r   t  s   

zCommandLine.register_commandtuple[Any, Any, str]c           	        s   t  }|d d ur&|d dt|d   }|d t|d  d  }n
|d dd  }g } jv r? fdd|D } j}|r\g }|dD ]}| sS n||  qKng }d|}|||fS )N   r   r   c                   s   g | ]}j   ||qS r1   )r   rP   r   r   r0   r1   r2   r     s    z1CommandLine._inspect_function.<locals>.<listcomp>r?   r   )	r   inspect_getfullargspecr   r   r   r   r   r   join)	r0   r   specr  r  Zhelp_
help_linesliner  r1   r	  r2   r     s*   



zCommandLine._inspect_functionr   r   optionsr   c              
     s    j \}}}z||g fdd|D R i  fdd|D  W d S  tjyF } z jr/ tjt|fi |j W Y d }~d S d }~ww )Nc                   s   g | ]}t  |d qS r7   r   r~   r   r  r1   r2   r     s    z'CommandLine.run_cmd.<locals>.<listcomp>c                   s   i | ]	}|t  |d qS r7   r  r  r  r1   r2   r     s    z'CommandLine.run_cmd.<locals>.<dictcomp>)r   r   rR   raiseerrerrr   rA   )r0   r   r  r   r  r  er1   r  r2   run_cmd  s   &zCommandLine.run_cmdtuple[str, str]c           	      C  s   |j }tjd}|rtj|dkr|}d}n|rd}|}nd}d}|s)||fS d  }}|D ]!}tj|dkrE|d urBtd|}q/|d urNtd|}q/|rU|n||r[|fS |fS )NZALEMBIC_CONFIGzpyproject.tomlzalembic.iniz'pyproject.toml indicated more than oncez"only one ini file may be indicated)r   r   environrP   pathbasenamer   rR   )	r0   r  r   Zalembic_config_envZdefault_pyproject_tomlZdefault_alembic_configtomlinir[   r1   r1   r2   _inis_from_config  s@   
zCommandLine._inis_from_configargvOptional[Sequence[str]]c                 C  sV   | j |}t|ds| j d dS | |\}}t|||j|d}| || dS )z6Executes the command line with the provided arguments.r   ztoo few arguments)r   r   r   r"   N)r   
parse_argshasattrerrorr  r   r[   r  )r0   r  r  r  r  r   r1   r1   r2   main  s   
zCommandLine.mainr7   )r   r4   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   r3   r-   r   r  r  r   stampr   r   r   r   r   r  r  r#  r1   r1   r1   r2   r     s<  
 

 (/7?FM
RYbjry 


:


(r   r  r  r   r4   r   r   r(   r)   c                 K  s   t |dj| d dS )z(The console runner function for Alembic.r   )r  N)r   r#  )r  r   r   r1   r1   r2   r#    s   r#  __main__)NN)r  r  r   r4   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   Zutil.pyfilesr   r   r   PostWriteHookConfigr   r   r   r#  r   r1   r1   r1   r2   <module>   sT        t  V

