o
    h                     @  s(  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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' zej(rd dl)m*Z* d d l)m+Z+ nd dl,m*Z* d d l,m+Z+ W n e-y   dZ*Y nw e.d!Z/e.d"Z0e.d#Z1e.d$Z2d%Z3e.d&Z4e.d'Z5G d(d) d)Z6G d*d+ d+ej!Z7dS ),    )annotations)contextmanagerN)
ModuleType)Any)cast)Iterator)List)Mapping)Optional)Sequence)Set)Tuple)TYPE_CHECKING)Union   revision)write_hooks   )util)	migration)compat)not_none)
_GetRevArg)
_RevIdType)Revision)Config)MessagingOptions)RevisionStep)	StampStep)ZoneInfo)ZoneInfoNotFoundErrorz (?!\.\#|__init__)(.*\.py)(c|o)?$z(?!\.\#|__init__)(.*\.py)$z([a-f0-9]+)\.py$z\w+z%(rev)s_%(slug)sz
, *|(?: +)z, *|(?: +)|\:c                   @  sl  e Zd ZdZedddddddedejf	d~ddZe	dddZ
ejdddZdd!d"Zedd%d&Ze					ddd-d.Z	0ddd2d3Zdd7d8Zdd;d<Zdd>d?ZddAdBZddHdIZddJdKZddMdNZddOdPZddQdRZddVdWZddXdYZdd]d^Zdd_d`Ze	ddadbZ ddedfZ!ddgdhZ"ddjdkZ#ddmdnZ$					dddxdyZ%dd|d}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strfile_templatetruncate_slug_lengthOptional[int]version_locationsOptional[List[str]]
sourcelessbooloutput_encodingtimezoneOptional[str]hook_configOptional[Mapping[str, str]]recursive_version_locationsmessaging_optsreturnNonec                 C  sv   || _ || _|| _|pd| _|| _|| _t| j| _	|| _
|| _|	| _|
| _t|tjs9tdtj| d S )Nr#   zVPath doesn't exist: %r.  Please use the 'init' command to create a new scripts folder.)r%   r'   r*   r(   r,   r.   r   RevisionMap_load_revisionsrevision_mapr/   r1   r3   r4   osaccessF_OKr   CommandErrorpathabspath)selfr%   r'   r(   r*   r,   r.   r/   r1   r3   r4    rA   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/alembic/script/base.py__init__N   s$   

zScriptDirectory.__init__c                 C  s$   | j }t|dkrtd|d S )Nr   z"Multiple version_locations presentr   )_version_locationslenr   r=   )r@   locrA   rA   rB   versionsp   s   
zScriptDirectory.versionsSequence[str]c                 C  s0   | j rdd | j D S tjtj| jdfS )Nc                 S  s   g | ]}t jt|qS rA   )r:   r>   r?   r   coerce_resource_to_filename).0locationrA   rA   rB   
<listcomp>{   s    z6ScriptDirectory._version_locations.<locals>.<listcomp>rG   )r*   r:   r>   r?   joinr%   r@   rA   rA   rB   rD   x   s
   z"ScriptDirectory._version_locationsIterator[Script]c           	      c  s    | j rdd | jD }n| jg}t }|D ]=}t| |D ]4}tj|}||v r2t	
d|  q|| tj|}tj|}t| ||}|d u rOq|V  qqd S )Nc                 S  s   g | ]
}t j|r|qS rA   )r:   r>   exists)rJ   versrA   rA   rB   rL      s    
z3ScriptDirectory._load_revisions.<locals>.<listcomp>zJFile %s loaded twice! ignoring. Please ensure version_locations is unique.)r*   rD   rG   setScript_list_py_dirr:   r>   realpathr   warnaddbasenamedirname_from_filename)	r@   pathsdupesrQ   	file_path	real_pathfilenamedir_namescriptrA   rA   rB   r8      s4   
zScriptDirectory._load_revisionsconfigr   c                 C  sJ  | d}|du rtd| d}|durt|}nd}| d}|rc| d}dddtjd	d
d}z|| }W n tyM }	 ztd| |	d}	~	ww |du rXt	|}
ndd |	|D }
nd}
| d}|rxt
t	|tjdd< | ddk}tt|| dt|| ddk| dd|
| d|di ||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*   version_path_separator 
:;)Nspacenewliner:   rg   rh   za'%s' is not a valid value for version_path_separator; expected 'space', 'newline', 'os', ':', ';'c                 S  s   g | ]}|r|  qS rA   )strip)rJ   xrA   rA   rB   rL      s    z/ScriptDirectory.from_config.<locals>.<listcomp>prepend_sys_pathr   r3   truer'   r,   r.   r$   r/   post_write_hooks)	r'   r(   r,   r.   r*   r/   r1   r3   r4   )get_main_optionr   r=   intr:   pathsepKeyError
ValueError_split_on_space_commasplitlist_split_on_space_comma_colonsysr>   r"   rI   _default_file_templateget_sectionr4   )clsrb   rc   tslr(   version_locations_strrd   split_on_path
split_charker*   rm   rvlrA   rA   rB   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r   r   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)head_argheadsz(Can't locate revision identified by '%s'r   )r   RangeNotAncestorErrorr   r   lowerupperr   r=   MultipleHeadsargumentformat_as_commar   ResolutionErrorRevisionErrorargs)
r@   r   r   r   r   r   rnamhreerrrA   rA   rB   _catch_revision_errors   sF   	
z&ScriptDirectory._catch_revision_errorsbaser   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.

        r   TF)	inclusiveassert_relative_lengthN)r   r9   iterate_revisionsr   rS   )r@   r   r   revrA   rA   rB   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)r   r   r   rS   r9   get_revisionsr@   r   rA   rA   rB   r   5  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)r   r   r   rS   r9   _get_all_currentr   rA   rA   rB   get_all_current@  s   
$zScriptDirectory.get_all_currentrS   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)r   r   rS   r9   get_revisionr   rA   rA   rB   r   D  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.Nr   r   )r   r9   _resolve_revision_number)r@   r   r   branch_namerA   rA   rB   as_revision_numberP  s   
z"ScriptDirectory.as_revision_numberr   !Union[str, Tuple[str, ...], None]r   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   rS   r9   r   )r@   r   r   r   rA   rA   rB   r   a  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.r   N)r   r9   get_current_headrN   rA   rA   rB   r   {  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.
        )rw   r9   r   rN   rA   rA   rB   	get_heads  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_basesrE   r   r=   )r@   basesrA   rA   rB   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.

        )rw   r9   r   rN   rA   rA   rB   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)r   r   T)implicit_basec                      g | ]
}t j j|qS rA   )r   MigrationStepupgrade_from_scriptr9   rJ   ra   rN   rA   rB   rL         z1ScriptDirectory._upgrade_revs.<locals>.<listcomp>)r   r   reversedrw   r@   r   r   revsrA   rN   rB   _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)select_for_downgradec                   r   rA   )r   r   downgrade_from_scriptr9   r   rN   rA   rB   rL     r   z3ScriptDirectory._downgrade_revs.<locals>.<listcomp>)r   r   r   rA   rN   rB   _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   r   T)include_dependenciesc              	     s"   g | ]}t |jd dd jqS )NFT)r   r   r   r9   rJ   r   rN   rA   rB   rL     s    z/ScriptDirectory._stamp_revs.<locals>.<listcomp>c                 S     g | ]}|j qS rA   r   r   rA   rA   rB   rL         Fc                 S  r   rA   r   r   rA   rA   rB   rL   ,  r   rA   )r   r   r   to_tupleextendr9   filter_for_lineager   r   rS   unique_listrR   _get_descendant_nodes_get_ancestor_nodesintersectionr   r   r   append)r@   r   r   
heads_revsstepsfiltered_headsr   destsdestdescendants	ancestors
todo_headssteprA   rN   rB   _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%   rN   rA   rA   rB   run_envA  s   	zScriptDirectory.run_envc                 C  s   t jt j| jdS )Nr   )r:   r>   r?   rM   r%   rN   rA   rA   rB   env_py_locationL  s   zScriptDirectory.env_py_locationsrcr   c                 K  s`   t jdtj| fi | j t j||| jfi | W d    d S 1 s)w   Y  d S NzGenerating )r   statusr:   r>   r?   r4   template_to_filer.   )r@   r   r   r   rA   rA   rB   _generate_templateP  s   "z"ScriptDirectory._generate_templatec                 C  sT   t jdtj| fi | j t|| W d    d S 1 s#w   Y  d S r   )r   r   r:   r>   r?   r4   shutilcopy)r@   r   r   rA   rA   rB   
_copy_fileV  s   "zScriptDirectory._copy_filer>   c                 C  sf   t j|}t j|s1tjd| fi | j t | W d    d S 1 s*w   Y  d S d S )NzCreating directory )r:   r>   r?   rP   r   r   r4   makedirs)r@   r>   rA   rA   rB   _ensure_directory\  s   "z!ScriptDirectory._ensure_directorydatetime.datetimec                 C  s   | j d urOt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)tzinfo)r/   r    r   r=   r!   r   datetimeutcnowreplaceutc
astimezonenow)r@   r   create_daterA   rA   rB   _generate_create_dated  s8   

z%ScriptDirectory._generate_create_daterevidmessageOptional[_RevIdType]spliceOptional[bool]branch_labelsversion_path
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 tj|j} nqttdn j}tjtj|} jD ]}tj||kr nqt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 sw   Y  nd} jtj jd|ft |t!t"dd |
D t#|t!||tj$|dur1|ndd|  j%}|rDt&'|| zt ( |}W n tjyc }	 z	t|	jd |	d}	~	ww |du rkdS |r~|j)s~t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   .r   z"Duplicate head revisions specifiedr   zAMultiple version locations present, please specify --version-pathz7Path %s 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 rA   )r   r   )rJ   r   deprA   rA   rB   rL     s    
z5ScriptDirectory.generate_revision.<locals>.<listcomp>c                   s    g | ]}t  j||fqS rA   )r   r9   r   )rJ   r  rN   rA   rB   rL     s    zscript.py.makoc                 s  s"    | ]}|d ur|j nd V  qd S r   r   )rJ   hrA   rA   rB   	<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?)+rS   verify_rev_idr   r   r   r=   r   r   r   r   r
   r9   r   rE   rR   r   rD   
isinstancer:   r>   rY   rG   normpathr?   r*   r   	_rev_pathis_headto_listr   rM   r%   r&   tuple_rev_as_scalartupler   r   r1   r   
_run_hooks
_from_pathr   add_revision)r@   r   r   r   r   r   r   r  r   r   r   r  r   head_	norm_path	vers_pathr>   resolved_depends_onro   ra   rA   rN   rB   generate_revision  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j||S )N_ r   r   z%s.py)	r   slugepochyearmonthdayhourminutesecond)rq   	timestamprM   _slug_refindallr   rE   r(   rsplitr'   r  r  r   r!  r"  r#  r:   r>   )r@   r>   r  r   r   r  r  r_   rA   rA   rB   r    s&   zScriptDirectory._rev_path)r%   r&   r'   r&   r(   r)   r*   r+   r,   r-   r.   r&   r/   r0   r1   r2   r3   r-   r4   r   r5   r6   r5   r&   )r5   rH   )r5   rO   )rb   r   r5   r"   )NNNNN)r   r0   r   r0   r   r0   r   r0   r   r0   r5   r   )r   r   )r   r&   r   r&   r5   rO   )r   r   r5   r   )r   r   r5   r   )r   r&   r5   rS   )r   r0   r5   r   )r   r   r   r   r   r   r5   rO   )r5   r0   )r5   r   )r   r&   r   r&   r5   r   )r   r&   r   r0   r5   r   )r   r   r   r   r5   r   )r5   r6   )r   r&   r   r&   r   r   r5   r6   )r   r&   r   r&   r5   r6   )r>   r&   r5   r6   )r5   r   )NFNNN)r   r&   r   r0   r   r   r   r   r   r   r   r0   r  r   r   r   r5   r  )
r>   r&   r  r&   r   r0   r   r   r5   r&   )'__name__
__module____qualname____doc__rz   r   r   
EMPTY_DICTrC   propertyrG   memoized_propertyrD   r8   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rA   rA   rA   rB   r"   :   sr    "
	T.









	


^



  r"   c                      s   e Zd ZU dZd0 fddZded< 	 ded< 	 d	Zd
ed< 	 ed1ddZed1ddZ	ed1ddZ
d1ddZ					d2d3ddZ				d4d5d d!Zd1d"d#Zed6d'd(Zed7d*d+Zed8d.d/Z  ZS )9rS   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&   r>   c              	     sJ   || _ || _t j||jtjt|dd ddtjt|dd ddd d S )Nr   rA   )defaultr  )r   dependencies)r1  r>   superrC   r  r   r   getattr)r@   r1  r  r>   	__class__rA   rB   rC   7  s   
zScript.__init__Nr   _db_current_indicatorr5   c                 C  s   t d| jd S ))Return the docstring given in the script.z

r   )r   rv   longdocrN   rA   rA   rB   docO  s   z
Script.docc                 C  s2   | j j}|rt| j dr|| j j}| S dS )r9  _alembic_source_encodingr  )r1  r,  hasattrdecoder<  rk   )r@   r;  rA   rA   rB   r:  U  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
rf   c                 s  s    | ]}d | V  qdS )z    %sNrA   )rJ   pararA   rA   rB   r    s    z#Script.log_entry.<locals>.<genexpr>)r   r  is_branch_pointis_merge_pointr8  _format_down_revisionr3  r   r   nextrevr   r>   rM   r:  
splitlines)r@   entryrA   rA   rB   	log_entryc  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@  rA  )rF  r   r  rD  rE  r;  rN   rA   rA   rB   __str__  s   zScript.__str__FTinclude_branchesr-   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)rB  z%s%sr@  rA  z, %s)r   r3  rF  r   r   r   _is_real_headr  r8  rD  rE  r;  )r@   rL  rM  rN  rO  rP  textrA   rA   rB   
_head_only  s<   

	zScript._head_onlyverbosec                 C  s   |r| j S | ||||S r   )rJ  rS  )r@   rT  rL  rM  rN  rO  rA   rA   rB   
cmd_format  s
   zScript.cmd_formatc                 C  s   | j sdS t| jS )Nz<base>)r  r   r   _versioned_down_revisionsrN   rA   rA   rB   rF    s   zScript._format_down_revision	scriptdirr"   r  c                 C  s   t j|\}}| |||S r   )r:   r>   rv   rZ   )r|   rW  r>   dir_r_   rA   rA   rB   r    s   zScript._from_pathr   c                   s   g }t j|ddD ]M\}}}|drq	t|D ]}|t j|| q|jrLt j|dt jrLdd |D  |	 fddt 
D  |jsR |S |  q	|S )NT)topdown__pycache__c                 S  s   h | ]	}| d d qS ).r   )rv   )rJ   r_   rA   rA   rB   	<setcomp>  s    z&Script._list_py_dir.<locals>.<setcomp>c                 3  s0    | ]}| d d  vrtj|V  qdS )r[  r   N)rv   r:   r>   rM   )rJ   pycnamespy_cache_pathrA   rB   r    s    z&Script._list_py_dir.<locals>.<genexpr>)r:   walkendswithsortedr   r>   rM   r,   rP   r   listdirr3   sort)r|   rW  r>   r[   rootdirsfilesr_   rA   r^  rB   rT     s$   

zScript._list_py_dirrX  r_   c                 C  s   |j r	t|}nt|}|sd S |d}|j r)|ddk}|ddk}nd }}|s1|rQtjtj||}tjtj||d }	|sO|rQ|	rQd S t	
||}
t|
dspt|}|sjt	d| |d}n|
j}t|
|tj||S )Nr   r   coFr   zCould not determine revision id from filename %s. Be sure the 'revision' variable is declared inside the script (please see 'Upgrading from Alembic 0.1 to 0.2' in the documentation).)r,   _sourceless_rev_filematch_only_source_rev_filegroupr:   r>   rP   rM   r   r   r=  _legacy_revr=   r   rS   )r|   rW  rX  r_   py_matchpy_filenameis_cis_o	py_exists
pyc_existsr1  mr   rA   rA   rB   rZ     s6   



zScript._from_filename)r1  r   r  r&   r>   r&   r(  )FFFTT)rL  r-   rM  r-   rN  r-   rO  r-   rP  r-   r5   r&   )FFFT)rT  r-   rL  r-   rM  r-   rN  r-   rO  r-   r5   r&   )rW  r"   r>   r&   r5   r  )rW  r"   r>   r&   r5   r   )rW  r"   rX  r&   r_   r&   r5   r  )r)  r*  r+  r,  rC   __annotations__r8  r.  r;  r:  rJ  rK  rS  rU  rF  r0  r  rT   rZ   __classcell__rA   rA   r6  rB   rS   /  sD   
 
#+
$rS   )8
__future__r   
contextlibr   r   r:   r   r   ry   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r  r   r   r   runtimer   r   r   r   r   r   rb   r   r   runtime.migrationr   r   py39zoneinfor    r!   backports.zoneinfoImportErrorcompilerk  rm  ro  r%  rz   ru   rx   r"   rS   rA   rA   rA   rB   <module>   sr    





     z