o
    8 h                      @  s,  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
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 ddlmZ ddl m!Z! erd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+ zej,rd d!l-m.Z. d d"l-m/Z/ nd d!l0m.Z. d d"l0m/Z/ W n e1y   dZ.Y nw e2d#Z3e2d$Z4e2d%Z5e2d&Z6d'Z7G d(d) d)Z8G d*d+ d+ej$Z9dS ),    )annotations)contextmanagerN)Path)
ModuleType)Any)cast)Iterator)List)Optional)Sequence)Set)Tuple)TYPE_CHECKING)Union   revision)write_hooks   )util)	migration)compat)not_none_preserving_path_as_str)
_GetRevArg)
_RevIdType)Revision)Config)MessagingOptions)PostWriteHookConfig)RevisionStep)	StampStep)ZoneInfo)ZoneInfoNotFoundErrorz (?!\.\#|__init__)(.*\.py)(c|o)?$z(?!\.\#|__init__)(.*\.py)$z([a-f0-9]+)\.py$z\w+z%(rev)s_%(slug)sc                   @  s  e Zd ZdZedddddg dedejf	dddZe	dddZ
ejddd Zejdd"d#Zdd%d&Zedd)d*Ze					ddd1d2Z	4ddd6d7Zdd;d<Zdd?d@ZddBdCZddEdFZddLdMZddNdOZddQdRZddSdTZddUdVZddZd[Zdd\d]ZddadbZddcddZ e	ddedfZ!ddidjZ"ddkdlZ#ddmdnZ$ddpdqZ%ddsdtZ&						ddddZ'dddZ(dS )ScriptDirectoryaH  Provides operations upon an Alembic script directory.

    This object is useful to get information as to current revisions,
    most notably being able to get at the "head" revision, for schemes
    that want to test if the current revision in the database is the most
    recent::

        from alembic.script import ScriptDirectory
        from alembic.config import Config
        config = Config()
        config.set_main_option("script_location", "myapp:migrations")
        script = ScriptDirectory.from_config(config)

        head_revision = script.get_current_head()



    (   NFutf-8r   dirUnion[str, os.PathLike[str]]file_templatestrtruncate_slug_lengthOptional[int]version_locations0Optional[Sequence[Union[str, os.PathLike[str]]]]
sourcelessbooloutput_encodingtimezoneOptional[str]hookslist[PostWriteHookConfig]recursive_version_locationsmessaging_optsreturnNonec                 C  s   t || _dd |pdD | _|| _|pd| _|| _|| _t| j	| _
|| _|| _|	| _|
| _t|tjs@td| dd S )Nc                 S  s   g | ]}t |qS  r   ).0pr;   r;   [/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/alembic/script/base.py
<listcomp>_   s    z,ScriptDirectory.__init__.<locals>.<listcomp>r;   r&   zPath doesn't exist: z@.  Please use the 'init' command to create a new scripts folder.)r   r(   r.   r*   r,   r0   r2   r   RevisionMap_load_revisionsrevision_mapr3   r5   r7   r8   osaccessF_OKr   CommandError)selfr(   r*   r,   r.   r0   r2   r3   r5   r7   r8   r;   r;   r>   __init__M   s$   


zScriptDirectory.__init__c                 C  
   t | jS )zreturn a single version location based on the sole path passed
        within version_locations.

        If multiple version locations are configured, an error is raised.


        )r+   _singular_version_locationrG   r;   r;   r>   versionss   s   
	zScriptDirectory.versionsr   c                 C  s$   | j }t|dkrtd|d S )Nr   z"Multiple version_locations presentr   )_version_locationslenr   rF   )rG   locr;   r;   r>   rJ   ~   s   
z*ScriptDirectory._singular_version_locationSequence[Path]c                 C  s(   | j rdd | j D S t| jd gS )Nc                 S  s   g | ]	}t | qS r;   )r   coerce_resource_to_filenameabsolute)r<   locationr;   r;   r>   r?      s    z6ScriptDirectory._version_locations.<locals>.<listcomp>rL   )r.   r   r(   rR   rK   r;   r;   r>   rM      s
   z"ScriptDirectory._version_locationsIterator[Script]c                 c  s    dd | j D }t }|D ]0}t| |D ]'}| }||v r*td| d q|| t| |}|d u r:q|V  qqd S )Nc                 S  s   g | ]}|  r|qS r;   )exists)r<   versr;   r;   r>   r?      s    z3ScriptDirectory._load_revisions.<locals>.<listcomp>zFile zC loaded twice! ignoring. Please ensure version_locations is unique.)	rM   setScript_list_py_dirresolver   warnadd
_from_path)rG   pathsdupesrV   Z	file_pathZ	real_pathscriptr;   r;   r>   rA      s$   

zScriptDirectory._load_revisionsconfigr   c                 C  s   | d}|du rtd| d}|durt|}nd}| }|r+|tjdd< |d}tt	|| dt
||d| d	d
| | d| ||jd
S )zProduce a new :class:`.ScriptDirectory` given a :class:`.Config`
        instance.

        The :class:`.Config` need only have the ``script_location`` key
        present.

        script_locationNz0No 'script_location' key found in configuration.r,   r   r7   r*   r0   r2   r'   r3   )	r*   r,   r0   r2   r.   r3   r5   r7   r8   )Zget_alembic_optionr   rF   intZget_prepend_sys_paths_listsyspathZget_alembic_boolean_optionr%   rQ   _default_file_templateZget_version_locations_listZget_hooks_listr8   )clsra   rb   Ztslr,   Zprepend_sys_pathZrvlr;   r;   r>   from_config   s:   
	


zScriptDirectory.from_configancestormultiple_headsstartend
resolutionIterator[None]c           
   
   c  s   zd V  W d S  t jy9 } z%|d u rtt|j}|d u r$tt|j}|s(d}|||d }t||d }~w t jy] } z|sEd}||pJ|j	t
|jd }t||d }~w t jyx } z|d u rnd|j	 }t||d }~w t jy }	 z	t|	jd |	d }	~	ww )NzgRequested range %(start)s:%(end)s does not refer to ancestor/descendant revisions along the same branchrk   rl   zMultiple head revisions are present for given argument '%(head_arg)s'; please specify a specific target revision, '<branchname>@%(head_arg)s' to narrow to a specific head, or 'heads' for all heads)Zhead_argheadsz(Can't locate revision identified by '%s'r   )r   ZRangeNotAncestorErrorr   r   lowerupperr   rF   ZMultipleHeadsargumentformat_as_commarp   ZResolutionErrorRevisionErrorargs)
rG   ri   rj   rk   rl   rm   ZrnaZmhreerrr;   r;   r>   _catch_revision_errors   sF   	
z&ScriptDirectory._catch_revision_errorsbaserp   headc                 c  s\    | j ||d | jj||dddD ]}tt|V  qW d   dS 1 s'w   Y  dS )a-  Iterate through all revisions.

        :param base: the base revision, or "base" to start from the
         empty revision.

        :param head: the head revision; defaults to "heads" to indicate
         all head revisions.  May also be "head" to indicate a single
         head revision.

        ro   TF)Z	inclusiveZassert_relative_lengthN)ry   rB   iterate_revisionsr   rX   )rG   rz   r{   revr;   r;   r>   walk_revisions   s   
"zScriptDirectory.walk_revisionsid_r   Tuple[Script, ...]c                 C  sF   |    tttdf | j|W  d   S 1 sw   Y  dS )zReturn the :class:`.Script` instance with the given rev identifier,
        symbolic name, or sequence of identifiers.

        .N)ry   r   r   rX   rB   get_revisionsrG   r   r;   r;   r>   r     s   


$zScriptDirectory.get_revisionsTuple[str, ...]Set[Script]c                 C  sB   |    ttt | j|W  d    S 1 sw   Y  d S N)ry   r   r   rX   rB   Z_get_all_currentr   r;   r;   r>   get_all_current  s   
$zScriptDirectory.get_all_currentrX   c                 C  s>   |    tt| j|W  d   S 1 sw   Y  dS )zReturn the :class:`.Script` instance with the given rev id.

        .. seealso::

            :meth:`.ScriptDirectory.get_revisions`

        N)ry   r   rX   rB   get_revisionr   r;   r;   r>   r     s   
	$zScriptDirectory.get_revision%Optional[Union[str, Tuple[str, ...]]]c                 C  sT   |    | j|\}}W d   n1 sw   Y  |s dS |dkr&|S |d S )z[Convert a symbolic revision, i.e. 'head' or 'base', into
        an actual revision number.Nrp   r   )ry   rB   Z_resolve_revision_number)rG   r   r}   Zbranch_namer;   r;   r>   as_revision_number+  s   
z"ScriptDirectory.as_revision_numberrr   !Union[str, Tuple[str, ...], None]rq   kwr   c                 K  s    t tt | jj||fi |S )a  Iterate through script revisions, starting at the given
        upper revision identifier and ending at the lower.

        The traversal uses strictly the `down_revision`
        marker inside each migration script, so
        it is a requirement that upper >= lower,
        else you'll get nothing back.

        The iterator yields :class:`.Script` objects.

        .. seealso::

            :meth:`.RevisionMap.iterate_revisions`

        )r   r   rX   rB   r|   )rG   rr   rq   r   r;   r;   r>   r|   <  s   z!ScriptDirectory.iterate_revisionsc                 C  s:   | j dd | j W  d   S 1 sw   Y  dS )aG  Return the current head revision.

        If the script directory has multiple heads
        due to branching, an error is raised;
        :meth:`.ScriptDirectory.get_heads` should be
        preferred.

        :return: a string revision number.

        .. seealso::

            :meth:`.ScriptDirectory.get_heads`

        z}The script directory has multiple heads (due to branching).Please use get_heads(), or merge the branches using alembic merge.rj   N)ry   rB   get_current_headrK   r;   r;   r>   r   V  s
   $z ScriptDirectory.get_current_head	List[str]c                 C     t | jjS )aU  Return all "versioned head" revisions as strings.

        This is normally a list of length one,
        unless branches are present.  The
        :meth:`.ScriptDirectory.get_current_head()` method
        can be used normally when a script directory
        has only one head.

        :return: a tuple of string revision numbers.
        )listrB   rp   rK   r;   r;   r>   	get_headsn  s   zScriptDirectory.get_headsc                 C  s.   |   }t|dkrtd|r|d S dS )a#  Return the "base" revision as a string.

        This is the revision number of the script that
        has a ``down_revision`` of None.

        If the script directory has multiple bases, an error is raised;
        :meth:`.ScriptDirectory.get_bases` should be
        preferred.

        r   z@The script directory has multiple bases. Please use get_bases().r   N)	get_basesrN   r   rF   )rG   basesr;   r;   r>   get_base{  s   zScriptDirectory.get_basec                 C  r   )zreturn all "base" revisions as strings.

        This is the revision number of all scripts that
        have a ``down_revision`` of None.

        )r   rB   r   rK   r;   r;   r>   r     s   zScriptDirectory.get_basesdestinationcurrent_revList[RevisionStep]c                   s\    j d|d  j||dd} fddtt|D W  d    S 1 s'w   Y  d S )NzFDestination %(end)s is not a valid upgrade target from current head(s)ri   rl   T)Zimplicit_basec                      g | ]
}t j j|qS r;   )r   MigrationStepupgrade_from_scriptrB   r<   r`   rK   r;   r>   r?         z1ScriptDirectory._upgrade_revs.<locals>.<listcomp>)ry   r|   reversedr   rG   r   r   Zrevsr;   rK   r>   _upgrade_revs  s   

$zScriptDirectory._upgrade_revsc                   sT    j d|d  j||dd} fdd|D W  d    S 1 s#w   Y  d S )NzHDestination %(end)s is not a valid downgrade target from current head(s)r   T)Zselect_for_downgradec                   r   r;   )r   r   downgrade_from_scriptrB   r   rK   r;   r>   r?     r   z3ScriptDirectory._downgrade_revs.<locals>.<listcomp>)ry   r|   r   r;   rK   r>   _downgrade_revs  s   
$zScriptDirectory._downgrade_revsr   r   List[StampStep]c              	     s   j dd  |}g }|sd}g }t|D ]}|r.| jjttt	 ||dd qt
|} |p;d g}|D ]{}|d u rQ| fdd|D  q>||v rVq>t j|g}	t j|g}
|	|r|
|rtJ dd |D }t||jd	d	 j}|| q>|
|rd
d |D }t||jdd	 j}|| q>td|jdd j}|| q>|W  d    S 1 sw   Y  d S )NzCMultiple heads are present; please specify a single target revisionr   rz   T)Zinclude_dependenciesc              	     s"   g | ]}t |jd dd jqS )NFT)r   r"   r   rB   r<   r{   rK   r;   r>   r?     s    z/ScriptDirectory._stamp_revs.<locals>.<listcomp>c                 S     g | ]}|j qS r;   r   r   r;   r;   r>   r?         Fc                 S  r   r;   r   r   r;   r;   r>   r?     r   r;   )ry   r   r   to_tupleextendrB   Zfilter_for_lineager   r   rX   unique_listrW   Z_get_descendant_nodes_get_ancestor_nodesintersectionr   r"   r   append)rG   r   rp   Z
heads_revsZstepsZfiltered_headsr}   Zdestsdestdescendants	ancestorsZ
todo_headsstepr;   rK   r>   _stamp_revs  s   







$zScriptDirectory._stamp_revsc                 C  s   t | jd dS )zRun the script environment.

        This basically runs the ``env.py`` script present
        in the migration environment.   It is called exclusively
        by the command functions in :mod:`alembic.command`.


        env.pyN)r   load_python_filer(   rK   r;   r;   r>   run_env  s   	zScriptDirectory.run_envc                 C  s   t t| jdS )Nr   )r+   r   r(   rK   r;   r;   r>   env_py_location'  s   zScriptDirectory.env_py_locationsrcr   c                 K  s`   t jd|  fi | j t j||| jfddi| W d    d S 1 s)w   Y  d S )NzAppending to existing append_with_newlinesTr   statusrR   r8   template_to_filer2   rG   r   r   r   r;   r;   r>   _append_template+  s   "z ScriptDirectory._append_templatec                 K  s\   t jd|  fi | j t j||| jfi | W d    d S 1 s'w   Y  d S NzGenerating r   r   r;   r;   r>   _generate_template8  s   "z"ScriptDirectory._generate_templatec                 C  sP   t jd|  fi | j t|| W d    d S 1 s!w   Y  d S r   )r   r   rR   r8   shutilcopy)rG   r   r   r;   r;   r>   
_copy_file>  s   "zScriptDirectory._copy_filere   c                 C  s^   |  }| s-tjd| fi | j t| W d    d S 1 s&w   Y  d S d S )NzCreating directory )rR   rU   r   r   r8   rC   makedirs)rG   re   r;   r;   r>   _ensure_directoryD  s   "z!ScriptDirectory._ensure_directorydatetime.datetimec                 C  s   | j d urMtd u rtdzt| j }W n ty    d }Y nw |d u r?z	t| j  }W n ty>   td| j  d w tjjtj jd	|}|S tj }|S )NzePython >= 3.9 is required for timezone support or the 'backports.zoneinfo' package must be installed.zCan't locate timezone: %s)tz)
r3   r#   r   rF   r$   rr   datetimenowutc
astimezone)rG   tzinfocreate_dater;   r;   r>   _generate_create_dateL  s8   

z%ScriptDirectory._generate_create_daterevidmessageOptional[_RevIdType]spliceOptional[bool]branch_labelsversion_path"Union[str, os.PathLike[str], None]
depends_onOptional[Script]c	              
     s  |du rd}zt | W n tjy# }
 z	t|
jd |
d}
~
ww  jdd" tt	t
d df  j|}|D ]}|dksDJ q<W d   n1 sOw   Y  tt|t|krctd	  }|du rt jd
kr|D ]}|durt|t sJ |jj} nqttdn j}nt|}t|tsJ | } jD ]
}| |kr n
qtd| d jr |  ||||}|s|D ]}|dur|jstd|j q|r   dd  fddt|D D }W d   n	1 sw   Y  nd} jt jd|ft|tt dd |D t!|t||tj"|dur3|ndd|	  j#}|rFt$%|| zt & |}W n tjye }
 z	t|
jd |
d}
~
ww |du rmdS |r|j'std|j||j(f  j)| |S )a  Generate a new revision file.

        This runs the ``script.py.mako`` template, given
        template arguments, and creates a new file.

        :param revid: String revision id.  Typically this
         comes from ``alembic.util.rev_id()``.
        :param message: the revision message, the one passed
         by the -m argument to the ``revision`` command.
        :param head: the head revision to generate against.  Defaults
         to the current "head" if no branches are present, else raises
         an exception.
        :param splice: if True, allow the "head" version to not be an
         actual head; otherwise, the selected head must be a head
         (e.g. endpoint) revision.

        Nr{   r   z{Multiple heads are present; please specify the head revision on which the new revision should be based, or perform a merge.r   r   .rz   z"Duplicate head revisions specifiedr   zAMultiple version locations present, please specify --version-pathzPath z0 is not represented in current version locationszeRevision %s is not a head revision; please specify --splice to create a new branch from this revisionc                 S  s$   g | ]\}}||j v r|n|jqS r;   )r   r   )r<   r}   depr;   r;   r>   r?     s    
z5ScriptDirectory.generate_revision.<locals>.<listcomp>c                   s    g | ]}t  j||fqS r;   )r   rB   r   )r<   r   rK   r;   r>   r?     s    zscript.py.makoc                 s  s"    | ]}|d ur|j nd V  qd S r   r   )r<   hr;   r;   r>   	<genexpr>  s     z4ScriptDirectory.generate_revision.<locals>.<genexpr>zempty message)up_revisiondown_revisionr   r   r   commar   zVersion %s specified branch_labels %s, however the migration file %s does not have them; have you upgraded your script.py.mako to include the 'branch_labels' section?)*rX   Zverify_rev_idr   ru   r   rF   rv   ry   r   r   r
   rB   r   rN   rW   r   rM   
isinstance_script_pathparentrJ   r   rR   r.   r   	_rev_pathis_headto_listr   r(   r+   Ztuple_rev_as_scalartupler   rt   r5   r   Z
_run_hooksr]   r   re   Zadd_revision)rG   r   r   r{   r   r   r   r*   r   r   rx   rp   r   r   Zhead_Z	norm_pathZ	vers_pathre   Zresolved_depends_onZpost_write_hooksr`   r;   rK   r>   generate_revisiong  s   








z!ScriptDirectory.generate_revisionrev_idr   c                 C  s   t | }dt|pd }t|| jkr(|d | j ddd d }d| j	||||j
|j|j|j|j|jd	  }t|| S )N_ r   r   z%s.py)	r}   slugepochyearmonthdayhourminutesecond)rc   	timestampjoin_slug_refindallrq   rN   r,   rsplitr*   r   r   r   r   r   r   r   )rG   re   r   r   r   r   r   filenamer;   r;   r>   r     s&   zScriptDirectory._rev_path)r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r+   r3   r4   r5   r6   r7   r1   r8   r   r9   r:   r9   r+   r9   r   )r9   rP   )r9   rT   )ra   r   r9   r%   )NNNNN)ri   r4   rj   r4   rk   r4   rl   r4   rm   r4   r9   rn   )rz   rp   )rz   r+   r{   r+   r9   rT   )r   r   r9   r   )r   r   r9   r   )r   r+   r9   rX   )r   r4   r9   r   )rr   r   rq   r   r   r   r9   rT   )r9   r4   )r9   r   )r   r+   r   r+   r9   r   )r   r+   r   r4   r9   r   )r   r   rp   r   r9   r   )r9   r:   )r   r   r   r   r   r   r9   r:   )r   r   r   r   r9   r:   )re   r   r9   r:   )r9   r   )NFNNNN)r   r+   r   r4   r{   r   r   r   r   r   r   r   r*   r4   r   r   r   r   r9   r   )
re   r)   r   r+   r   r4   r   r   r9   r   ))__name__
__module____qualname____doc__rf   r   r   
EMPTY_DICTrH   propertyrL   memoized_propertyrJ   rM   rA   classmethodrh   r   ry   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%   9   sz    &

	*.









	


^




 r%   c                      s   e Zd ZU dZd0 fdd	Zded< 	 ded< 	 ed1ddZdZded< 	 ed2ddZ	ed2ddZ
ed2ddZd2ddZ					d3d4d!d"Z				d5d6d$d%Zd2d&d'Zed7d+d,Zed8d.d/Z  ZS )9rX   zRepresent a single revision file in a ``versions/`` directory.

    The :class:`.Script` instance is returned by methods
    such as :meth:`.ScriptDirectory.iterate_revisions`.

    moduler   r   r+   re   r)   c              	     sN   || _ t|| _t j||jtjt|dd ddtjt|dd ddd d S )Nr   r;   )defaultr   )r   dependencies)	r   r   re   superrH   r   r   r   getattr)rG   r   r   re   	__class__r;   r>   rH   "  s   

zScript.__init__r9   r   c                 C  rI   r   )r   re   rK   r;   r;   r>   r   ;  s   
zScript._script_pathNr   _db_current_indicatorc                 C  s   t d| jd S ))Return the docstring given in the script.z

r   )rw   splitlongdocrK   r;   r;   r>   docC  s   z
Script.docc                 C  s2   | j j}|rt| j dr|| j j}| S dS )r  _alembic_source_encodingr   )r   r   hasattrdecoder  strip)rG   r  r;   r;   r>   r
  I  s   zScript.longdocc                 C  s   d| j | jrdnd| jrdnd| jrdnd| jrdndf }| jr+|d|  f 7 }n	|d|  f 7 }| jrA|d	t| j 7 }| jrN|d
t| j	 7 }| j
r\|dt| j
f 7 }|d| jf 7 }|dddd | j D  7 }|S )NzRev: %s%s%s%s%s
 (head)r    (branchpoint) (mergepoint)
 (current)zMerges: %s
zParent: %s
zAlso depends on: %s
zBranches into: %s
zBranch names: %s
z	Path: %s
z
%s

c                 s  s    | ]}d | V  qdS )z    %sNr;   )r<   parar;   r;   r>   r   w  s    z#Script.log_entry.<locals>.<genexpr>)r   r   is_branch_pointis_merge_pointr  _format_down_revisionr  r   rt   Znextrevr   re   r   r
  
splitlines)rG   entryr;   r;   r>   	log_entryW  s6   


zScript.log_entryc                 C  s:   d|   | j| jrdnd| jrdnd| jrdnd| jf S )Nz%s -> %s%s%s%s, %sr  r   r  r  )r  r   r   r  r  r  rK   r;   r;   r>   __str__{  s   zScript.__str__FTinclude_branchesr1   include_docinclude_parentstree_indicatorshead_indicatorsc                 C  s   | j }|r| jrd|  t| j|f }nd|  |f }|d us$J |r3| jr3|dt| j 7 }|s7|rR|d| jr>dnd| jrG| jsGdnd| jrMdndf 7 }|rf|d	| j	r[d
nd| j
radndf 7 }|ro|d| j 7 }|S )Nz%s (%s) -> %sz%s -> %sz (%s)z%s%s%sr  r   z (effective head)r  z%s%sr  r  z, %s)r   r  r  r   rt   r   Z_is_real_headr   r  r  r  r  )rG   r  r  r  r   r!  textr;   r;   r>   
_head_only  s<   

	zScript._head_onlyverbosec                 C  s   |r| j S | ||||S r   )r  r#  )rG   r$  r  r  r  r   r;   r;   r>   
cmd_format  s
   zScript.cmd_formatc                 C  s   | j sdS t| jS )Nz<base>)r   r   rt   _versioned_down_revisionsrK   r;   r;   r>   r    s   zScript._format_down_revision	scriptdirr%   
List[Path]c                   s   g }t j|ddD ]E\}}}|jdrq	t|D ]	}|||  q|jrD|d  rDdd |D  | fdd	 D  |j
sJ |S |  q	|S )NT)top_down__pycache__c                 S  s    h | ]}t |jd d qS ).r   )r   namer	  )r<   r   r;   r;   r>   	<setcomp>  s    z&Script._list_py_dir.<locals>.<setcomp>c                 3  s,    | ]}|j d d  vr| V  qdS )r+  r   N)r,  r	  )r<   ZpycnamesZpy_cache_pathr;   r>   r     s    z&Script._list_py_dir.<locals>.<genexpr>)r   	path_walkr,  endswithsortedr   r0   rU   r   iterdirr7   sort)rg   r'  re   r^   rootdirsfilesr   r;   r.  r>   rY     s(   
zScript._list_py_dirr   c                 C  s   t |}|j|j}}|jrt|}nt|}|sd S |d}|jr4|ddk}|ddk}nd }}|s<|rR||  }	||d   }
|	sP|rR|
rRd S t	
||}t|dsst|}|smt	d| d|d}n|j}t|||| S )	Nr   r   coFr   z.Could not determine revision id from filename z. Be sure the 'revision' variable is declared inside the script (please see 'Upgrading from Alembic 0.1 to 0.2' in the documentation).)r   r   r,  r0   _sourceless_rev_filematch_only_source_rev_filegrouprU   r   r   r  _legacy_revrF   r   rX   )rg   r'  re   dir_r   Zpy_matchZpy_filenameZis_cZis_oZ	py_existsZ
pyc_existsr   mr   r;   r;   r>   r]     s:   



zScript._from_path)r   r   r   r+   re   r)   r   r   )FFFTT)r  r1   r  r1   r  r1   r   r1   r!  r1   r9   r+   )FFFT)r$  r1   r  r1   r  r1   r  r1   r   r1   r9   r+   )r'  r%   re   r   r9   r(  )r'  r%   re   r)   r9   r   )r   r   r   r   rH   __annotations__r   r   r  r  r
  r  r  r#  r%  r  r   rY   r]   __classcell__r;   r;   r  r>   rX     sD   
 
#+
(rX   ):
__future__r   
contextlibr   r   rC   pathlibr   rw   r   rd   typesr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   runtimer   r   r   Zutil.pyfilesr   r   r   r   ra   r   r   r    runtime.migrationr!   r"   py39Zzoneinfor#   r$   Zbackports.zoneinfoImportErrorcompiler:  r<  r>  r   rf   r%   rX   r;   r;   r;   r>   <module>   sr    



     f