
    -hT                    n   d dl m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mZ d d	lmZ d d
lmZ erd dlmZmZ d dlmZ d dlmZ d dD             Zd dD             Zd dD             Zd dD             Z e!e"df         Z#	 e!e#ef         Z$	 d4dZ%e G d d                      Z&e G d  d!                      Z' G d" d#          Z( ej)        d$          Z* ej)        d%          Z+ ej)        d&          Z,d5d)Z-d6d-Z.e G d. d/                      Z/d7d2Z0d7d3Z1dS )8    )annotationsN)defaultdict)suppress)	dataclass)chain)Path)TYPE_CHECKINGClassVar)UnhandledEditableModuleError)logger)IteratorSequence)Pattern)Modulec                6    g | ]}t          j        |          S  recompile.0pats     K/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/_griffe/finder.py
<listcomp>r   (   s     sssC
3sss    )z^__editables_\w+\.py$z^_editable_impl_\w+\.py$c                6    g | ]}t          j        |          S r   r   r   s     r   r   r   )   s      X X XSC X X Xr   )z^__editable__\w+\.py$c                6    g | ]}t          j        |          S r   r   r   s     r   r   r   *   s     '\'\'\C
3'\'\'\r   )z^_\w+_editable.py$c                6    g | ]}t          j        |          S r   r   r   s     r   r   r   +   s     "^"^"^s2:c??"^"^"^r   )z^_\w+_editable_loader.py$.stringstrpatternsSequence[Pattern]returnboolc                :     t           fd|D                       S )Nc              3  B   K   | ]}|                               V  d S N)match)r   patternr   s     r   	<genexpr>z!_match_pattern.<locals>.<genexpr>4   s/      ==w}}V$$======r   )any)r   r!   s   ` r   _match_patternr,   3   s&    ====H======r   c                  :    e Zd ZU dZded<   	 ded<   	 dZded<   dS )	PackagezThis class is a simple placeholder used during the process of finding packages.

    Parameters:
        name: The package name.
        path: The package path(s).
        stubs: An optional path to the related stubs file (.pyi).
    r    namer   pathNzPath | Nonestubs)__name__
__module____qualname____doc____annotations__r1   r   r   r   r.   r.   7   sG           IIIJJJEr   r.   c                  *    e Zd ZU dZded<   	 ded<   dS )NamespacePackagezThis class is a simple placeholder used during the process of finding packages.

    Parameters:
        name: The package name.
        path: The package paths.
    r    r/   
list[Path]r0   N)r2   r3   r4   r5   r6   r   r   r   r8   r8   I   s6           III!))r   r8   c                      e Zd ZU dZg dZded<   	  ee          Zded<   	 d2d3dZd4dZ	d5dZ
dddd6dZd7d Z	 d2d8d%Zd9d(Zd:d*Zd;d,Zd4d-Zd<d.Zd=d0Zd>d1ZdS )?ModuleFinderaf  The Griffe finder, allowing to find modules on the file system.

    The module finder is generally not used directly.
    Each [`GriffeLoader`][griffe.GriffeLoader] instance creates its own module finder instance.
    The finder can be configured when instantiating the loader
    thanks to the [loader][griffe.GriffeLoader]'s `search_paths` parameter.
    ).pyz.pycz.pyoz.pyd.pyiz.sozClassVar[list[str]]accepted_py_module_extensionszClassVar[set[str]]extensions_setNsearch_pathsSequence[str | Path] | Noner#   Nonec                    i | _         g | _        	 |pt          j        D ]$}|                     t          |                     %t          t                    | _        | 	                                 dS )zmInitialize the finder.

        Parameters:
            search_paths: Optional paths to search into.
        N)
_paths_contentsr@   sysr0   append_search_pathr   r   list_always_scan_for_extend_from_pth_files)selfr@   r0   s      r   __init__zModuleFinder.__init__f   st     8:(*& !,CH 	0 	0D##DJJ////7B47H7H##%%%%%r   r0   r   c                x    |                                 }|| j        vr| j                            |           dS dS )zAppend a search path.

        The path will be resolved (absolute, normalized).
        The path won't be appended if it is already in the search paths list.

        Parameters:
            path: The path to append.
        N)resolver@   appendrJ   r0   s     r   rF   zModuleFinder.append_search_pathw   sD     ||~~t((($$T***** )(r   positionintc                z    |                                 }|| j        vr| j                            ||           dS dS )a/  Insert a search path at the given position.

        The path will be resolved (absolute, normalized).
        The path won't be inserted if it is already in the search paths list.

        Parameters:
            position: The insert position in the list.
            path: The path to insert.
        N)rM   r@   insert)rJ   rP   r0   s      r   insert_search_pathzModuleFinder.insert_search_path   sF     ||~~t((($$Xt44444 )(r   TF)try_relative_pathfind_stubs_packagemodule
str | PathrU   r$   rV   &tuple[str, Package | NamespacePackage]c                  t          |t                    r.|                     |          \  }}|                     |          }n|rj	 |                     t          |                    \  }}|                     |          }nL# t          $ r! |}|                    dd          d         }Y n"w xY w|}|                    dd          d         }|s||                     |          fS 	 |                     |          }n# t          $ r d}Y nw xY w	 |                     |dz             }n# t          $ r d}Y nw xY w||t          |          |r||rzt          |t                    r"t          |t                    r|j	        |_
        n?t          |t                    r*t          |t                    r|xj	        |j	        z  c_	        ||fS ||p|fS )a5  Find the top-level parent module of a module.

        If a Path is passed, only try to find the module as a file path.
        If a string is passed, first try to find the module as a file path,
        then look into the search paths.

        Parameters:
            module: The module name or path.
            try_relative_path: Whether to try finding the module as a relative path,
                when the given module is not already a path.
            find_stubs_package: Whether to search for stubs-only package.
                If both the package and its stubs are found, they'll be merged together.
                If only the stubs are found, they'll be used as the package itself.

        Raises:
            FileNotFoundError: When a Path was passed and the module could not be found:

                - the directory has no `__init__.py` file in it
                - the path does not exist

            ModuleNotFoundError: When a string was passed and the module could not be found:

                - no `module/__init__.py`
                - no `module.py`
                - no `module.pth`
                - no `module` directory (namespace packages)
                - or unsupported .pth file

        Returns:
            The name of the module, and an instance representing its (namespace) package.
        .   r   N-stubs)
isinstancer   _module_name_path_top_module_nameFileNotFoundErrorsplitfind_packageModuleNotFoundErrorr.   r0   r1   r8   )	rJ   rW   rU   rV   module_namemodule_pathtop_module_namepackager1   s	            r   	find_speczModuleFinder.find_spec   s5   N fd## 	6'+'='=f'E'E$K"33K@@OO 
	6E+/+A+A$v,,+O+O([
 #'"7"7"D"D	 % : : :$"(,,sA"6"6q"9: !K$ll32215O " 	C 1 1/ B BBB	''88GG" 	 	 	GGG		%%o&@AAEE" 	 	 	EEE	 ?u}%o666  	(u 	('7++ +
5'0J0J + %
G%566 +:eM];^;^ +
*'' G,u,,s6   %B (B-,B-(C> >DDD* *D98D9re   r    Package | NamespacePackagec                    t          |          t          | d          g}|}|                    d          }g }| j        D ]}|                     |          }|r |D ]}||z  }||v r|j        r@|                    d          }	t          |||	                                r|	nd          c c S |dz  }
|
                                rOt          |
          s@|
                    d          }	t          ||
|	                                r|	nd          c c S |dz  }
|
                                rt          ||
d          c c S |	                    |           |rt          ||          S t          |          )a  Find a package or namespace package.

        Parameters:
            module_name: The module name.

        Raises:
            ModuleNotFoundError: When the module cannot be found.

        Returns:
            A package or namespace package wrapper.
        r<   r]   r=   N__init__.pyz__init__.pyi)r   removesuffixr@   	_contentssuffixwith_suffixr.   exists_is_pkg_style_namespacerN   r8   rd   )rJ   re   	filepathsreal_module_namenamespace_dirsr0   path_contentschoiceabs_pathr1   init_modules              r   rc   zModuleFinder.find_package   s     K$$$%%
	 '+88BB% 	8 	8D NN400M 8' 8 8F#f}H=00#? j$,$8$8$@$@E#*+;XPUP\P\P^P^Ghuudh#i#iiiiii&.&>&--// m8OP[8\8\ m$/$;$;F$C$CE#*+;[SXS_S_SaSaJk%%gk#l#llllll&.&?&--// P#*+;[$#O#OOOOOO&--h777 	A#K@@@!+...r   Path | list[Path]seen
set | NoneIterator[NamePartsAndPathType]c              #    K   t          |t                    r1t                      }|D ]}|                     ||          E d{V  dS |j        dk    r|j        }n|j        | j        v rdS t          |pd          }|                     |          D ]}|	                    |          }|j        |v rt          j        d|           6|j        dk    }|j        }|s|                    dd          d         }|dk    rIt          |j                  dk    r|j        dd	         |fV  ||                    |j                   |r|                    d
          j        |fV  |                    |          j        |fV  dS )a  Iterate on a module's submodules, if any.

        Parameters:
            path: The module path.
            seen: If not none, this set is used to skip some files.
                The goal is to replicate the behavior of Python by
                only using the first packages (with `__init__` modules)
                of the same name found in different namespace packages.
                As soon as we find an `__init__` module, we add its parent
                path to the `seen` set, which will be reused when scanning
                the next namespace packages.

        Yields:
            name_parts (tuple[str, ...]): The parts of a submodule name.
            filepath (Path): A submodule filepath.
        NrK   r   z'Skip %s, another module took precedencer<   r[   r\   r    )r^   rG   setiter_submodulesstemparentro   r?   _filter_py_modulesrelative_tor   debugrb   lenpartsaddrp   	with_name)	rJ   r0   r{   	path_elemskipsubpathrel_subpathpy_filer   s	            r   r   zModuleFinder.iter_submodules  s     * dD!! 	 55D! A A	//	4@@@@@@@@@@F9
"";DD [D///F 4:2..t44 	A 	AG!--d33K!T))FPPP!(E1G#D -zz#q))!,z!! {())Q..!',g5555#HH[/000 A!--b117@@@@@!++D117@@@@@-	A 	Ar   r   list[NamePartsAndPathType]c           	         t          t          |                     |j                  |                     | j        |j                                     t                    S )zReturn the list of a module's submodules.

        Parameters:
            module: The parent module.

        Returns:
            A list of tuples containing the parts of the submodule name and its path.
        )key)sortedr   r   filepathrH   r/   _module_depth)rJ   rW   s     r   
submoduleszModuleFinder.submodulesV  s[     $$V_55$$T%:6;%GHH  
 
 
 	
r   tuple[str, Path]c                @   |                                 }|                                r:| j        D ])}|d| z  }|                                r|j        |fc S *|j        |fS |                                r"|j        dk    r|j        j        |fS |j        |fS t          )NrK   )absoluteis_dirr>   rq   r/   r   r   ra   )rJ   r0   extrf   s       r   r_   zModuleFinder._module_name_pathg  s    }};;== 	#9 2 2"%5%5%55%%'' 29k111129d?";;== 	#yJ&&{'--9d?"r   r9   c                    || j         vrL	 t          |                                          | j         |<   n!# t          t          f$ r g | j         |<   Y nw xY w| j         |         S r'   )rD   rG   iterdirra   NotADirectoryErrorrO   s     r   rn   zModuleFinder._contentsv  sw    t+++0-1$,,..-A-A$T**%'9: 0 0 0-/$T***0#D))s   )5 AAc                P    || j         vr| j                             |           d S d S r'   )r@   rN   rO   s     r   _append_search_pathz ModuleFinder._append_search_path~  s5    t((($$T***** )(r   c                :   | j         D ]}|                     |          D ]z}|j        dk    rmt          |          D ]]}|j        x}r8| j        |                             |j                            |                     | 	                    |j                   ^{d S )Nz.pth)
r@   rn   ro   _handle_pth_filealways_scan_forrH   rN   r0   joinpathrF   )rJ   r0   item	directoryscans        r   rI   z#ModuleFinder._extend_from_pth_files  s    % 	@ 	@Dt,, @ @;&((%5d%;%; @ @	#,#<<4 ^ 1$7>>y~?V?VW[?\?\]]]//	????@	@ 	@r   Iterator[Path]c              #     K   t          j        |dd          D ]Z\  }}}d |D             |d d <   |D ]@}t           j                            |          d         | j        v rt          ||          V  A[d S )NT)topdownfollowlinksc                    g | ]
}|d k    |S )__pycache__r   )r   dirs     r   r   z3ModuleFinder._filter_py_modules.<locals>.<listcomp>  s"    CCCsc].B.Bs.B.B.Br   r\   )oswalkr0   splitextr?   r   )rJ   r0   rootdirsfilesrelfiles         r   r   zModuleFinder._filter_py_modules  s      !#t!N!N!N 	. 	.D$CCdCCCDG  . .7##G,,Q/43FFFtW-----.	. 	.r   c                6   |                                 r|n|j        }|                                }| j        D ]j}t	          t
          t                    5  |                    |                                          }|j        d         cd d d            c S # 1 swxY w Y   k|j        |k    rJ|j        dz  	                                r.|j        }|j        |k    r|j        dz  	                                .| 
                    d|j                   |j        S )Nr   rl   )r   r   rM   r@   r   
ValueError
IndexErrorr   r   rq   rT   r/   )rJ   r0   parent_pathsearch_pathrel_paths        r   r`   zModuleFinder._top_module_name  s[   "kkmm<dd!))++, 	) 	)K*j11 ) )&22;3F3F3H3HII~a() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
  K//[5G-5W4_4_4a4a/%,K  K//[5G-5W4_4_4a4a/;#5666s   4BB	B	r'   )r@   rA   r#   rB   )r0   r   r#   rB   )rP   rQ   r0   r   r#   rB   )rW   rX   rU   r$   rV   r$   r#   rY   )re   r    r#   rj   )r0   rz   r{   r|   r#   r}   )rW   r   r#   r   )r0   r   r#   r   )r0   r   r#   r9   )r#   rB   )r0   r   r#   r   )r0   r   r#   r    )r2   r3   r4   r5   r>   r6   r   r?   rK   rF   rT   ri   rc   r   r   r_   rn   r   rI   r   r`   r   r   r   r;   r;   X   s          :h9g9g!gggg5),-J)K)KNKKKK4& & & & &"+ + + +5 5 5 5$ #'#(Q- Q- Q- Q- Q- Q-f-/ -/ -/ -/d  @A @A @A @A @AD
 
 
 
"       * * * *+ + + +@ @ @ @. . . .           r   r;   zG(?:__import__\([\"']pkg_resources[\"']\).declare_namespace\(__name__\))zP(?:__path__ = __import__\([\"']pkgutil[\"']\).extend_path\(__path__, __name__\))z^import[ \t]+\w+$ry   r   c                    |                      d          }t          t                              |          pt                              |                    S )Nutf8encoding)	read_textr$   _re_pkgresourcessearch_re_pkgutil)ry   codes     r   rr   rr     sH      & 11D ''--I1C1CD1I1IJJJr   name_parts_and_pathNamePartsAndPathTyperQ   c                ,    t          | d                   S )Nr   )r   )r   s    r   r   r     s    "1%&&&r   c                  (    e Zd ZU ded<   dZded<   dS )_SPr   r0   r   r    r   N)r2   r3   r4   r6   r   r   r   r   r   r     s,         JJJOr   r   r0   	list[_SP]c                   g }	 |                      d          }n# t          $ r |cY S w xY w|                                                    dd                              d          D ]}|                                }t
                              |          rq| j        |t          d          d          	                                 dz  }t          t                    5  t          |          cd d d            c S # 1 swxY w Y   |rc|                    d	          sNt          j                            |          r/|                    t%          t'          |                               	|S )
Nr   r   ;
Fkeependsimportr<   #)r   UnicodeDecodeErrorstripreplace
splitlines_re_import_liner(   r   r   lstripr   r   _handle_editable_module
startswithr   r0   rq   rN   r   r   )r0   directoriestextlineeditable_modules        r   r   r     s     K ~~v~..   

$$S$//::E:JJ 0 0zz||  && 	@"ktCMMOO/D/K/K/M/M,R,R,RRO677 @ @.??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 	0,, 	01E1E 	0s4::///s    **"D  D	D	c                z   t          | j        g t          t          R           r	 |                     d                                                              d          }n"# t          $ r}t          |           |d }~ww xY wt          |d         
                    d          d                   }|j                            d          rt          |j        j                  gS t          |          gS t          | j        t                    rt          j        |                                           }|j        D ]}t%          |t          j                  r|j        d	         }n#t%          |t          j                  r|j        }nMt%          |t          j                  rB|j        d
k    r7t%          |j        t          j                  rd |j        j        D             c S t          | j        t8                    r+t          j        |                                           }|j        D ]}t%          |t          j                  rt%          |j        t          j                  rt%          |j        j        t          j                  r|j        j        j        dk    rt%          |j        j         d         t          j!                  r_t          |j        j         d         j        d          }tE          |#                                          j        }t          ||          gc S t          |           )Nr   r   Fr   r   '   rK   r   MAPPINGc                    g | ]B}t          |t          j                  t          t	          |j                  j                  CS r   )r^   astConstantr   r   valuer   )r   csts     r   r   z+_handle_editable_module.<locals>.<listcomp>  s@    rrrT^_bdgdpTqTqrDOO233rrrr   installr\   src)r   )$r,   r/   _editable_editables_patterns$_editable_scikit_build_core_patternsr   r   r   ra   r   r   rb   r   r   r   _editable_setuptools_patternsr   parsebodyr^   Assigntargets	AnnAssigntargetNameidr   Dictvalues_editable_meson_python_patternsExprCallfuncargsr   nextr   )	r0   editable_lineserrornew_pathparsed_modulenoder   
build_pathpkg_names	            r   r   r     s   di!g#?!gBf!g!ghh 
	@!^^V^<<BBDDOOY^O__NN  	@ 	@ 	@.t44%?	@r*0055a899=##J// 	1.//00Hdi!>?? s 	$.."2"233!& 	s 	sD$
++ aD#-00 &#(++ s	Y0F0F:VZV`bebjKkKk0Frrtz?Prrrrrrdi!@AA C 	$.."2"233!& 	C 	CD4**
Ctz3844
C tz99
C JO&)33tzq13<@@ 4 "$*/!"4":EBB

 2 2 4 455:JAAABBBB
&t
,
,,s   <A# #
B-A==B)r   r    r!   r"   r#   r$   )ry   r   r#   r$   )r   r   r#   rQ   )r0   r   r#   r   )2
__future__r   r   r   r   rE   collectionsr   
contextlibr   dataclassesr   	itertoolsr   pathlibr   typingr	   r
   _griffe.exceptionsr   _griffe.loggerr   collections.abcr   r   r   _griffe.modelsr   r   r   r   r   tupler    NamePartsTyper   r,   r.   r8   r;   r   r   r   r   rr   r   r   r   r   r   r   r   <module>r     s	  " # " " " " " 



 				 				 



 # # # # # #       ! ! ! ! ! !             * * * * * * * * ; ; ; ; ; ; ! ! ! ! ! ! &22222222%%%%%%  ts;rsss  X X<W X X X '\'\C['\'\'\ $"^"^>]"^"^"^ c3h 0]D01  => > > >        " * * * * * * * *I  I  I  I  I  I  I  I X
 2:hii bjlmm"*122
K K K K
' ' ' '        
   <-- -- -- -- -- --r   