
    PqhU                    L   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	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 G d ded      Z G d d      ZddZedk(  r e        yy)    )annotations)ArgumentParser)	Namespace)ConfigParserN)Any)cast)Dict)Mapping)Optional)overload)TextIO)Union)	TypedDict   )__version__)command)util)compatc                     e Zd ZU dZ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j                  d        ZddZej                  d        ZddZe	 d	 	 	 	 	 dd       Ze	 	 	 	 	 	 d d       Ze	 	 	 	 	 	 d!d       Z	 d"	 	 	 	 	 d#dZd$dZd%dZd&dZ	 d"	 	 	 	 	 	 	 d'dZed(d       Ze	 d"	 	 	 	 	 d)d       Zd"dZej                  d*d       Zy)+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.
    :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.  The dictionary as given
     is **copied** to a new one, stored locally as the attribute
     ``.config_args``. When the :attr:`.Config.file_config` attribute is
     first invoked, the replacement variable ``here`` will be added to this
     dictionary before the dictionary is passed to ``ConfigParser()``
     to parse the .ini file.

    :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"Union[str, os.PathLike[str], None]strcmd_optsOptional[Namespace]c                    || _         || _        || _        || _        || _        t        |      | _        |r| j                  j                  |       yy)z Construct a new :class:`.Config`N)	config_file_nameconfig_ini_sectionoutput_bufferstdoutr   dictconfig_args
attributesupdate)selffile_ini_sectionr   r    r   r"   r#   s           O/srv/www/ollama/chat-ollama/venv/lib/python3.12/site-packages/alembic/config.py__init__zConfig.__init__c   sQ     !&"-* ,OO"":.     r   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`

         r%   s    r(   r#   zConfig.attributes   s	    $ 	r*   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Nr*   c                   | j                   rGt        j                  j                  t        j                  j	                  | j                               }nd}|| j
                  d<   t        | j
                        }| j                   r#t        j                  || j                   g       |S |j                  | j                         |S )a  Return the underlying ``ConfigParser`` object.

        Direct 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)r   ospathabspathdirnamer"   r   r   read_config_parseradd_sectionr   )r%   r8   file_configs      r(   r?   zConfig.file_config   s       77??277??43H3H#IJDD#' "4#3#34  %%kD4I4I3JK  ##D$;$;<r*   c                    ddl }t        j                  j                  t        j                  j	                  |j
                              }t        j                  j                  |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   r9   r:   r;   r<   __file__join)r%   r   package_dirs      r(   get_template_directoryzConfig.get_template_directory   sA     	ggoobggoog6F6F&GHww||K55r*   c                     y Nr,   r%   namedefaults      r(   get_sectionzConfig.get_section        	r*   c                     y rG   r,   rH   s      r(   rK   zConfig.get_section   rL   r*   c                     y rG   r,   rH   s      r(   rK   zConfig.get_section   rL   r*   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.

        )r?   has_sectionr!   itemsrH   s      r(   rK   zConfig.get_section   s9     ++D1ND$$**4011r*   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%   rI   values      r(   set_main_optionzConfig.set_main_option   s     	 7 7uEr*   c                P    | j                   j                  | j                  |       y rG   )r?   remove_optionr   )r%   rI   s     r(   remove_main_optionzConfig.remove_main_option  s    &&t'>'>Er*   c                    | j                   j                  |      s| j                   j                  |       | j                   j                  |||       y)a  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.

        :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)r?   rP   r>   set)r%   sectionrI   rT   s       r(   rS   zConfig.set_section_option  sD    ( ++G4((1WdE2r*   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)r?   rP   r   CommandErrorr   
has_optionget)r%   r[   rI   rJ   s       r(   get_section_optionzConfig.get_section_option,  sr     ++G4##$($9$97D  &&w5##''66Nr*   c                     y rG   r,   rH   s      r(   get_main_optionzConfig.get_main_option:  s    r*   c                     y rG   r,   rH   s      r(   rb   zConfig.get_main_option>  rL   r*   c                <    | j                  | j                  ||      S )zReturn 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.

        )r`   r   rH   s      r(   rb   zConfig.get_main_optionD  s     &&t'>'>gNNr*   c                v    t        t        t        j                  dt	        | j
                  dd      i            S )zThe messaging options.quietF)r   MessagingOptionsr   immutabledictgetattrr   r-   s    r(   r1   zConfig.messaging_optsN  s7     '$--%@A
 	
r*   )r&   r   r'   r   r   zOptional[TextIO]r    r   r   r   r"   zMapping[str, Any]r#   zOptional[dict]returnNone)r2   r   rj   rk   )rj   r   ).)rI   r   rJ   rk   rj   zOptional[Dict[str, str]])rI   r   rJ   Dict[str, str]rj   rl   )rI   r   rJ   zMapping[str, str]rj   z(Union[Dict[str, str], Mapping[str, str]]rG   )rI   r   rJ   Optional[Mapping[str, str]]rj   rm   )rI   r   rT   r   rj   rk   )rI   r   rj   rk   )r[   r   rI   r   rT   r   rj   rk   )r[   r   rI   r   rJ   Optional[str]rj   rn   )rI   r   rJ   r   rj   r   )rI   r   rJ   rn   rj   rn   )rj   rg   )__name__
__module____qualname____doc__sysr    r   rh   r)   r   __annotations__r   r   memoized_propertyr#   r5   r?   rE   r   rK   rU   rX   rS   r`   rb   r1   r,   r*   r(   r   r      s@   FT 59$*.(,);););)=%)/1/ / (	/
 / &/ '/ #/ 
/( %)H!(	 <@8?2"" 
 &O. 
 ,
6 ),"&	!  "0	 
 "3	1  AE22"=2	$2F"F32 AE"%0=	   26"/	 
O 

 
r*   r   c                      e Zd ZU ded<   y)rg   boolrf   N)ro   rp   rq   rt   r,   r*   r(   rg   rg   Y  s    Kr*   rg   F)totalc                  .    e Zd ZdddZddZddZddZy)	CommandLineNc                &    | j                  |       y rG   )_generate_args)r%   progs     r(   r)   zCommandLine.__init__^  s    D!r*   c           	        fd}t        |      }|j                  dddt        z         |j                  ddt        t        j
                  j                  d	d
      d       |j                  ddt        dd       |j                  ddd       |j                  ddd       |j                  dddd       |j                         }t        j                  ddiit        t              D cg c]  }t        t        |       c}D ]W  }t        j                  |      s|j                  d   dk7  s-|j                  dk(  s=t!        j"                  |      }|d    +|d   d!t%        |d            }|d   t%        |d           d  }	n
|d   d!d  }g }	|v r"|D 
cg c]  }
|   j                  |
|
       }}
|j&                  }|rJg }|j)                  d"      D ]3  }|j+                         s n$|j-                  |j+                                5 ng }|j/                  |j                  d#j1                  |      $       ||||	       j3                  |||	f%       Z || _        y c c}w c c}
w )&Nc           	        i dddt        dt        d      fddd	t        t        d
      fddt        dd      fddt        t        d      fddt        t        d      fddt        dd      fddt        dd      fddt        t        d       fd!d"t        t        d#      fd$d%t        t        d&      fd'd(d)t        dd*      fd+d,t        dd-      fd.d/t        dd0      fd1d2d3t        d4d5      fd6d7d8t        dd9      fd:d;t        dd<      fd=d>t        dd?      f}d@dAdBdC}|D ](  }||v s||   }|dDdE |dE   }} |j                  |i | * |D ]\  }|dFk(  s| 	v r/	|    |   dFk(  r$
j                  dFdG|j                  dF      H       ;
j                  ||j                  |      I       ^ y )JNtemplatez-tz
--templategenericz"Setup template for use with 'init')rJ   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-onappendzNSpecify 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 directoryzrevision identifierz/one or more revisions, or 'heads' for all heads)	directoryrevision	revisionsr   r   +)nargsr   r   )r!   r   add_argumentr_   )fnparser
positionalkwargskwargs_optspositional_helpr3   argskwpositional_translations	subparsers            r(   add_optionsz/CommandLine._generate_args.<locals>.add_optionsb  sW   H  ) AH  'NH" +(#H4  15HD  3EHT +0UHd "'@eHt  )uHD $ '!EHT $ '!UHd 3LMeHn ',+J)oH| $+0!}HN !&2OH` #(+<%aHp +*qH@ +<AHKT =1NO
  5+%&s+D#Abz48"D'F''44	5 " O;&44/3C8KG**#!,00= +  **3_5H5H5M*NOr*   r}   z	--versionversionz%%(prog)s %s)r   r   z-cz--configALEMBIC_CONFIGzalembic.inizaAlternate config file; defaults to value of ALEMBIC_CONFIG environment variable, or "alembic.ini")r   rJ   r   z-nz--namer   z6Name of section in .ini file to use for Alembic configz-xr   zlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingr   z
--raiseerrr   z!Raise a full stack trace on errorz-qz--quietzDo not log to std output.r   r   r   _zalembic.command   r   r/    r   )cmd)r   r   r   r   r9   environr_   add_subparsersr   stampdirri   inspect
isfunctionro   rp   r   inspect_getfullargspeclenrr   splitstripr   
add_parserrC   set_defaultsr   )r%   r}   r   r   
subparsersnr   specr   kwargrI   help_	help_textliner   r   s                 @@r(   r|   zCommandLine._generate_argsa  s   a	OF  T*	>K3O 	 	
 	JJNN#3]CD 	 	
 	L 	 	
 	; 	 	
 	4 	 	

 	,	 	 	
 **,
#*==:{2K"L03G=177A&= #	DB""2&KKNc)MM%6644R87&!%ac$q'l]!;J GSa\MO4E!%aJE00 %/"  0377dC"J " 

 "I %D 1 ;#zz|!%,,TZZ\:	; !#I&11KKchhy&9 2 	 B	:u=&&B
E+B&CG#	DH I >"s   4I1"I6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rG   )r   ri   r   r]   raiseerrerrr   r1   )r%   configoptionsr   r   r   kes           r(   run_cmdzCommandLine.run_cmdU  s     'J
	:5?@''1d+@ :??A1ggq$//?@?   	:Q96#8#89		:s2   A A
	A AA 
A B//6B**B/c                    | j                   j                  |      }t        |d      s| j                   j                  d       y t	        |j
                  |j                  |      }| j                  ||       y )Nr   ztoo few arguments)r&   r'   r   )r   
parse_argshasattrerrorr   r   rI   r   )r%   argvr   cfgs       r(   mainzCommandLine.maind  s`    ++((.w& KK12nn#LL C
 LLg&r*   rG   )r}   rn   rj   rk   )r   r   r   r   rj   rk   )ro   rp   rq   r)   r|   r   r   r,   r*   r(   rz   rz   ]  s    "rh:'r*   rz   c                <    t        |      j                  |        y)z(The console runner function for Alembic.r   )r   N)rz   r   )r   r}   r   s      r(   r   r   s  s     TT*r*   __main__)NN)
__future__r   argparser   r   configparserr   r   r9   rs   typingr   r   r	   r
   r   r   r   r   typing_extensionsr   r7   r   r   r   r   r   rg   rz   r   ro   r,   r*   r(   <module>r      s    " #  %  	 
         '    |
 |
~	y S' S'l+ zF r*   