|L iddlmZddlmZddlmZddlmZddlZddlZddl m Z ddl Z ddl Z ddl mZddl mZdd l mZdd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlm Z GddZ!ee"e"fZ#GddedZ$GddeZ%Gd d!Z& d$ d%d"Z'e(d#k(re'yy)&) annotations)ArgumentParser) Namespace) ConfigParserN)Path)Any)cast)Dict)Mapping)Optional)overload)Protocol)Sequence)TextIO)Union) TypedDict) __version__)command)util)compat)_preserving_path_as_strceZdZUdZddddej dejdf d)dZdZ de d< dZ de d < dZ de d < e d*d Ze d*d ZdZde d < ej"d+dZd,dZej"d-dZej"d.dZd/dZd0dZe d1 d2dZe d3dZe d4dZ d5 d6dZd7dZd8dZd9dZ d5 d:dZed;dZe d5 dd"Z d5 d?d#Z!ej"d@d$Z"dAd%Z#dBd&Z$dBd'Z%dCd(Z&y)DConfiga;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` Nalembicstrcmd_optsOptional[Namespace]c |r t|nd|_|r t|nd|_||_||_||_||_t||_t||_ |r|jj|yy)z Construct a new :class:`.Config`N) rconfig_file_nametoml_file_nameconfig_ini_section output_bufferstdoutrdict config_args toml_args attributesupdate) selffile_ toml_file ini_sectionr#r$rr&r(s T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/alembic/config.py__init__zConfig.__init__vs/4 #E * 3< #I . #.*    ,k*  OO " ": .  Optional[str]r r!cF|jyt|jSN)r rr*s r._config_file_pathzConfig._config_file_paths"  (D))**r0cF|jyt|jSr3)r!rr4s r._toml_file_pathzConfig._toml_file_paths"    &D''((r0r"ciS)aA 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` r4s r.r(zConfig.attributess $ r0c|rt||z}n t|}tj|j|dfi|jy)aRender 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)rrwrite_outstreamr$messaging_opts)r*textargoutputs r. print_stdoutzConfig.print_stdouts> Y_FYF T[[&$N$:M:MNr0ct|jr%|jjj}n t}|j |j d<t |j }|jr#tj||jg|S|j|j|S)aReturn 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) r5absoluteparentras_posixr&rrread_config_parser add_sectionr")r*rC file_configs r.rIzConfig.file_configs  ! !))224;;D6D#'==? "4#3#34  ! !  % %kD4J4J3K L  # #D$;$; <r0c|jr|jjr|jjj}|j |j d<t |jd5}tjj|}|jdijdi}t|tstjd|cdddSiS#1swYyxYw)zMReturn a dictionary of the [tool.alembic] section from pyproject.tomlrCrbtoolrzIncorrect TOML formatN)r7existsrDrErFr'openrtomllibloadget isinstancer%r CommandError)r*rCf toml_datadatas r.toml_alembic_configzConfig.toml_alembic_configs   D$8$8$?$?$A''00299D%)]]_DNN6 "d**D1 Q"NN//2  }}VR044YC!$-++,CDD   I  s >A(C22C;cddl}t|jjj}t |dz S)zReturn the directory where Alembic setup templates are found. This method is used by the alembic ``init`` and ``list_templates`` commands. rN templates)rr__file__rDrEr)r*r package_dirs r.get_template_directoryzConfig.get_template_directorys6 7++,557>> ;,--r0c4t|jS)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 )rr\r4s r._get_template_pathzConfig._get_template_pathsD//122r0cyr3r9r*namedefaults r. get_sectionzConfig.get_section(s$'r0cyr3r9r`s r.rczConfig.get_section0sr0cyr3r9r`s r.rczConfig.get_section5s47r0c|jj|s|St|jj|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.rczConfig.get_section:s9++D1ND$$**4011r0c>|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*ravalues r.set_main_optionzConfig.set_main_optionIs  7 7uEr0cP|jj|j|yr3)rI remove_optionr")r*ras r.remove_main_optionzConfig.remove_main_optionZs &&t'>'>Er0c|jj|s|jj||jj|||y)aWSet 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)rIrgrHset)r*sectionrarls r.rjzConfig.set_section_option]sD4++G4    ( ( 1 WdE2r0c|jj|s&tjd|jd|d|jj ||r|jj ||S|S)z9Return an option from the given section of the .ini file.zNo config file z found, or file has no '[z ]' section)rIrgrrSr has_optionrQ)r*rsrarbs r.get_section_optionzConfig.get_section_option{sr++G4##$($9$97D     & &w 5##''6 6Nr0cyr3r9r`s r.get_main_optionzConfig.get_main_options?Br0cyr3r9r`s r.rxzConfig.get_main_optionr0c<|j|j||S)aReturn 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 )rvr"r`s r.rxzConfig.get_main_options &&t'>'>gNNr0cyr3r9r`s r.get_alembic_optionzConfig.get_alembic_optionsBEr0cyr3r9r`s r.r}zConfig.get_alembic_optionrzr0c|jj|j|r&|jj|j|S|j ||S)aReturn 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)rIrur"rQ_get_toml_config_valuer`s r.r}zConfig.get_alembic_optionsU8    & &t'>'> E##''(?(?F F..tW.E Er0c,|jj|j|r)|jj|j|dk(S|jj|d}t |t stjd||S)NtrueFz*boolean value expected for TOML parameter ) rIrur"rQrWrRboolrrSrks r.get_alembic_boolean_optionz!Config.get_alembic_boolean_options    & &t'>'> E  $$T%<%@XXZHTQA00HE& !#E%Jqa4>>&:%JE E4($9>GAQT^^,,G E3' '';D8D %I &K Hs$<E"E.E"E) E. E"c vtttjdt |j ddiS)zThe messaging options.quietF)r MessagingOptionsr immutabledictgetattrrr4s r.r=zConfig.messaging_optss7    '$--%@A   r0c|D]}|j|}|nyddtjddd} ||}|dk(rtjd|S#t $r}t d|d |d |d}~wwxYw) N r;:;)spacenewlineosrrversion_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', ':', ';')rxrpathseprwarn_deprecatedKeyError ValueError)r*namesra separator split_on_pathsepkes r._get_file_separator_charzConfig._get_file_separator_chars D,,T2I$  **    *C//$$?J d$   sA A7A22A7c|jj|jdd}|r~|jdd}|;t j dt jd}|j|S|j|Dcgc]}|r|jc}Std|jddScc}w)Nversion_locationsfallbackpath_separatorrzNo 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 rIrQr"rrrrecompilesplitstripr r)r*version_locations_str split_char_split_on_space_commaxs r.get_version_locations_listz!Config.get_version_locations_list(s $ 0 0 4 4  # #%84!5!  !66 ":J!$$;)+ =(A%,223HII388DGGI ++,?F  s Cc|jj|jdd}|r}|jd}|;t j dt jd}|j|S|j|Dcgc]}|r|jc}Std|jddScc}w)Nprepend_sys_pathrrzNo 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 , *|(?: +)|\:rr)r*prepend_sys_path_strr_split_on_space_comma_colonrs r.get_prepend_sys_paths_listz!Config.get_prepend_sys_paths_listKs#//33  # #%7$ 4  667GHJ!$$;/1jj9I.J+2889MNN277 CGGI ++,>E  s Cc0g}|jjdsUtd|jdg}|D]2}t |}|j d|d<|j |4|Stjd}|jdi}|j|jdd}|D]Q}|s|D cic]+} | j|dzr| t|d zd|| -}} ||d<|j |S|Scc} w) Npost_write_hookszlist[dict[str, str]]ra _hook_namerhooks.r)rIrgr rr%popappendrrrcrrQ startswithlen) r*rtoml_hook_configcfgoptsrini_hook_configrrakeys r.get_hooks_listzConfig.get_hooks_listksB+-++,>?#&++,>C  ( #Cy%)XXf%5\" T" #0 %%'JJ}$= !"../A2FO)//##GR0E # /~~dSj1D A (/#*>> &*\" T" # s0D)r+"Union[str, os.PathLike[str], None]r,rr-rr#zOptional[TextIO]r$rrrr&Mapping[str, Any]r(zOptional[Dict[str, Any]]returnNone)rzOptional[Path])rzDict[str, Any])r>rr?rrr)rr)rr)rr)rr).)rarrbrrzOptional[Dict[str, str]])rarrbDict[str, str]rr)rarrbzMapping[str, str]rz(Union[Dict[str, str], Mapping[str, str]]r3)rarrbOptional[Mapping[str, str]]rr)rarrlrrr)rarrr)rsrrarrlrrr)rsrrarrbr1rr1)rarrbrrr)rarrbr1rr1)rarrbr1rFUnion[None, str, list[str], dict[str, str], list[dict[str, str]], int])rarrr)rarrbz Optional[Any]rr)rr)rrrr1)rzOptional[list[str]])rzlist[PostWriteHookConfig])'__name__ __module__ __qualname____doc__sysr$rrr/r__annotations__r r!propertyr5r7r"memoized_propertyr(rArIrWr\r^r rcrmrprjrvrxr}rrr=rrrrr9r0r.rrsdTp598<$*.(,);););)=/3/1/6/ / ( /  /&/'/-/ /6%)H!( '+m*2$(NM( ++ )) #" &O. , & . 3),''"&' !''"0 77"37 177 AE 2 2"= 2 $ 2F"F3>AE  "% 0=   BB 26"/  37OO"/O O$EE 26"/  37FF"/F FB 37##"/# #J   @!F@!r0rceZdZUded<y)rrrN)rrrrr9r0r.rrs Kr0rF)totalc$eZdZUdZded<ddZy)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 rrcyr3r9)r*configargskwargss r.__call__zCommandFunction.__call__sr0N)rrrrrrrr)rrrrrrr9r0r.rrsMMr0rc eZdZUdZdXdYdZidddeded fd d d eed fddeddfddeedfddeedfddeddfddedd fd!d"eed#fd$d%eed&fd'd(eed)fd*d+d,edd-fd.d/edd0fd1d2edd3fd4d5d6ed7d8fd9d:d;edd<fd=d>edd?fd@dAeddBfdCdDdEeddFfiZedGHedIHedJdKLdMZe jdNdOiiZ dPe dQ<dYdRZ dZdSZd[dTZd\dUZd]dVZdXd^dWZy)_ CommandLinez/Provides the command line interface to Alembic.Nc&|j|yr3)_generate_args)r*progs r.r/zCommandLine.__init__s D!r0templatez-tz --templategenericz"Setup template for use with 'init')rbtypehelpmessagez-mz --messagez%Message string to use with 'revision')rrsqlz--sql store_truez\Don't emit SQL to database - dump to standard output/file instead. See docs on offline mode.actionrtagz--tagz@head to base new revision on.splicez--splicez6Allow a non-head revision as the 'head' to splice onto depends_onz --depends-onrzNSpecify 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 revisionverbosez-vz --verbosezUse more verbose outputresolve_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-rangestorez1Specify a revision range; format is [start]:[end]indicate_currentz-iz--indicate-currentzIndicate the current revisionpurgez--purgez7Unconditionally erase the version table before stampingpackagez --packagezFWrite empty __init__.py files to the environment and version locations check_heads-cz --check-headsziCheck if all head revisions are applied to the database. Exit with an error code if this is not the case.zlocation of scripts directoryrzrevision identifier+z/one or more revisions, or 'heads' for all heads)nargsr) directoryrevision revisionsrrzdict[Any, dict[str, str]]_POSITIONAL_TRANSLATIONSct|}|jdddtz|jdddd |jd d td d|jddd |jddd |jdddd |j |_ddt tDD}|D]}|j|||_ y)Nrz --versionversionz %%(prog)s %s)rr rz--configrzAlternate 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 separatelyrz-nz--namerzfName of section in .ini file to use for Alembic config (only applies to configparser config, not toml))rrbrz-xzlAdditional arguments consumed by custom env.py scripts, e.g. -x setting1=somesetting -x setting2=somesettingz --raiseerrrz!Raise a full stack trace on errorz-qz--quietzDo not log to std output.c3K|]J}tj|r3|jddk7r!|jdk(rt t |Lyw)r_zalembic.commandN)inspect isfunctionrrr r).0fns r. z-CommandLine._generate_args..psJ ""2&KKNc)MM%66 " % sAAc3<K|]}tt|ywr3)rr)rras r.rz-CommandLine._generate_args..rsG$ww-Gs) r add_argumentrradd_subparsers subparsersdirrregister_commandparser)r*rralembic_commandsrs r.rzCommandLine._generate_argsEs&T*  >K3O     1     >    ;    4    ,  !//1 G#g,G # &B  ! !" % & r0c|j|\}}}|jj|j|}|j |||f|D]<}||j vs|j |}|dd|d} }|j |i| >|D]1}|jj|i} |j |fi| 3y)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)cmdrN) _inspect_functionr add_parserr set_defaults _KWARGS_OPTSr_POSITIONAL_OPTSrQ) r*r positionalkwarg help_text subparserr? kwarg_optrrs r.rzCommandLine.register_commands(,'='=b'A$ E9OO..r{{.K B E#:; 6Cd''' --c2 &q_imd& &&55  6  0C((,,S"5D "I " "3 /$ / 0r0ctj|}|d+|ddt|d }|dt|d d}n |ddd}g}||jvr,|Dcgc]!}|j|j ||#}}|j }|rJg}|j dD]3}|jsn$|j|j5ng}dj|} ||| fScc}w)Nrrr;r) rinspect_getfullargspecrrrQrrrrjoin) r*rspecr#r$rahelp_ help_linesliner%s r.rzCommandLine._inspect_functions,,R0 7 ac$q'l]3JGSa\MO,EaJE .. .'--b155dDAJ   J D) 4zz|%%djjl3  4 JHHZ( 5)++'s"&C:c d|j\}}} ||g|Dcgc]}t||dc}i|Dcic]}|t||dc}ycc}wcc}w#tj$r@}|jrtj t |fi|jYd}~yd}~wwxYwr3)rrrrSraiseerrerrrr=)r*roptionsrr#r$res r.run_cmdzCommandLine.run_cmds ' J :  5?@''1d+@ :??A1ggq$//? @?   :Q96#8#89  :s2AA AA A AB//6B**B/c|j}tjjd}|r'tjj |dk(r|}d}n |rd}|}nd}d}|s||fSdx}}|D]W}tjj |dk(r|t jd|}?|t jd|}Y|r|n||r|fS|fS)NALEMBIC_CONFIGzpyproject.tomlz alembic.iniz'pyproject.toml indicated more than oncez"only one ini file may be indicated)rrenvironrQpathbasenamerrS) r*r3ralembic_config_envdefault_pyproject_tomldefault_alembic_configtomliniras r._inis_from_configzCommandLine._inis_from_configs ZZ^^,<=   !348HH%7 "%2 " %5 "%7 "%2 "%5 ")+AA As Dww%)99#++A?++< t!7C  2  r0c|jj|}t|ds|jjdy|j |\}}t |||j |}|j||y)z6Executes the command line with the provided arguments.rztoo few arguments)r+r,r-rN)r parse_argshasattrerrorr@rrar5)r*argvr3r>r?rs r.mainzCommandLine.mainss++((.w& KK  1 2..w7ID##LL C LLg &r0r3)rr1rr)rrrr)rrrztuple[Any, Any, str])rrr3rrr)r3rrztuple[str, str])rEOptional[Sequence[str]]rr)rrrrr/r%rr!r"rstamprrrrrr5r@rFr9r0r.rrs 9"L   !9  L    c G H L   #   L0   )  1L@   +  ALP   #M  QL^   8  _Ln   !  oL~   I  LL   J  MLZ     +D E [Ld  $ #B ! eLr   #(  sLD    H  ELT   #4  ULd   #N  eLr   #4  sLB    #G   CLL\>?& B   K0;78t06,> :& P'r0rc <t|j|y)z(The console runner function for Alembic.r )rEN)rrF)rErrs r.rFrFsTT*r0__main__)NN)rErGrr1rrrr)) __future__rargparserr configparserrrrpathlibrrrtypingrr r r r r rrrrtyping_extensionsrrrrrr util.pyfilesrrrPostWriteHookConfigrrrrFrr9r0r.rSs"#%  '1m m `c3h'y Nh N['['~ %)+ !+ ++ + zFr0