
    Vic3                        S SK Jr  S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJs  Jr  S SKJr  \" SS9 " S S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       rg)    )ABC)abstractmethod)	dataclass)fnmatch)Path)	FrozenSet)List)Optional)Set)Tuple)UnionN)TargetT)frozenc                       \ rS rSrSr\S\S\4S j5       r\S\	\
   S\\\R                     \	\   4   4S j5       rSrg	)
SubprojectMatcher   z
This is a base class for "matchers" that create "subprojects" from a list of
potential candidates.
Subclasses must implement `is_match` and `make_subprojects`.
pathreturnc                     [         e)zJ
Whether the given path has a relevant filename for this type of matcher.
NotImplementedErrorselfr   s     g/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/semdep/matchers/base.pyis_matchSubprojectMatcher.is_match%   s
    
 "!    dep_source_filesc                     [         e)z
Use the files given in `dep_source_files` to make as many subprojects
as possible. This may not use all the files in `dep_source_files`.

Returns:
- the list of created subprojects
- the set of files that were used to construct the returned subprojects.
r   r   r   s     r   make_subprojects"SubprojectMatcher.make_subprojects,   
     "!r    N)__name__
__module____qualname____firstlineno____doc__r   r   boolr   r   r   r   r	   out
Subprojectr!   __static_attributes__r$   r   r   r   r      si     "T "d " " " )& 1"	tCNN#Yt_4	5" "r   r   c                      \ rS rSr% Sr\R                  \S'   \R                  \S'   \R                  \S'   \
\S'   \S\S\
4S	 j5       r\S\S\
4S
 j5       r\S\S\\   S\\   4S j5       r\S\\\S4   \S\4   \\\4   4   S\4S j5       rS\S\
4S jrS\\   S\\\   \\   4   4S jrS\\   S\\\R4                     \\   4   4S jrSrg)LockfileManifestMatcher;   a  
An abstract class for matchers that look for a single lockfile and a single
manifest.

Subprojects are a match only when the lockfile is found, and are created
whether the manifest is found or not.

If `make_manifest_only_subprojects` is true, then subprojects are created
for manifests that do not have a corresponding lockfile.

Child classes must implement _is_manifest_match, _is_lockfile_match, _lockfile_to_manifest, and _get_subproject_root
manifest_kindlockfile_kind	ecosystemmake_manifest_only_subprojectsr   r   c                     [         eNr   r   s     r   _is_manifest_match*LockfileManifestMatcher._is_manifest_matchO       !!r   c                     [         er6   r   r   s     r   _is_lockfile_match*LockfileManifestMatcher._is_lockfile_matchS   r9   r   lockfile_path
candidatesc                     [         e)zd
Given a lockfile path, return the path to the corresponding manifest
if it exists in `candidates`.
r   )r   r=   r>   s      r   _lockfile_to_manifest-LockfileManifestMatcher._lockfile_to_manifestW   s
     "!r   manifest_lockfile_pathsNc                     [         e)z
Get the root of the subproject. The arguments are passed in a tuple of
(manifest_path, lockfile_path) rather than individually to allow
verifying that at least one of the arguments is not None.
r   r   rB   s     r   _get_subproject_root,LockfileManifestMatcher._get_subproject_roota   r#   r   c                 T    U R                  U5      =(       d    U R                  U5      $ r6   )r7   r;   r   s     r   r    LockfileManifestMatcher.is_matcho   s#    &&t,M0G0G0MMr   r   c                     [        5       n[        5       nU H_  nUR                  nU R                  U5      (       a  UR                  U5        U R	                  U5      (       d  MN  UR                  U5        Ma     X24$ )z
Classifies the provided source files as lockfiles, manifests, or neither.

Returns a tuple of (manifest_paths, lockfile_paths)
)setfpathr;   addr7   )r   r   	lockfiles	manifeststargetr   s         r   _filter_manifest_lockfiles2LockfileManifestMatcher._filter_manifest_lockfilesr   sj      #u	"u	&F<<D&&t,,d#&&t,,d# ' %%r   c                 ,   U R                  U5      u  p#[        5       n/ nU GHn  n[        S U 5       5      nU R                  Xg5      nUb$  U R	                  X45      n	UR                  U5        OU R	                  X45      n	[        R                  " U R                  [        R                  " [        U5      5      5      n
U(       aS  [        R                  " [        R                  " U R                  [        R                  " [        U5      5      S9U
45      nO[        R                  " U
5      nUR                  [        R                   " [        R                  " [        U	5      5      [        R"                  " U5      U R$                  S95        GMq     [        5       nU R&                  (       a  X$-
   H  nUR                  [        R                   " [        R                  " [        UR(                  5      5      [        R"                  " [        R*                  " [        R                  " U R                  [        R                  " [        U5      5      S95      5      U R$                  S95        UR                  U5        M     U[        XL-  U-  5      4$ )z
Use the files given in `dep_source_files` to make as many subprojects
as possible. This may not use all the files in `dep_source_files`.
c              3   8   #    U  H  oR                   v   M     g 7fr6   )rK   ).0rO   s     r   	<genexpr>;LockfileManifestMatcher.make_subprojects.<locals>.<genexpr>   s     "O>NF<<>Ns   kindr   root_dirdependency_sourcer3   )rP   rJ   	frozensetr@   rE   rL   r+   Lockfiler2   FpathstrManifestLockfileManifestr1   LockfileOnlyappendr,   DependencySourcer3   r4   parentManifestOnly)r   r   rN   rM   paired_manifestssubprojectsr=   r>   matching_manifest_pathrZ   lockfile
dep_sourcelone_manifestsmanifest_paths                 r   r!   (LockfileManifestMatcher.make_subprojects   s"     $>>?OP	 '*e,. 'M""O>N"OOJ%)%?%?&" &144+; !$$%;<  44+; ||D$6$6		#mBT8UVH% 11!%!3!3!$3/E+F!G !
 !--h7
 YYs8}5&)&:&::&F"nnA 'T ..!*!=""NN!$3}/C/C+D!E*-*>*>,, #)-););),3}3E)F!"+ #'.. ""=1 ">" I&6&G)&STTTr   r$   )r%   r&   r'   r(   r)   r+   ManifestKind__annotations__LockfileKind	Ecosystemr*   r   r   r7   r;   r   r
   r@   r   r   rE   r   r   r   rP   r	   r,   r!   r-   r$   r   r   r/   r/   ;   sp    ######}}$(("t " " " "t " " " "!"/8"	$" " "!&$*uT4Z0%d
2CC"
"
 
" "NT Nd N& )& 1&	s4y#d)#	$&$OU )& 1OU	tCNN#Yt_4	5OUr   r/   c                       \ rS rSr% Sr\\S'   \\   \S'   S\S\	4S jr
S\S\	4S jrS	\S
\\   S\\   4S jrS\\\S4   \S\4   \\\4   4   S\4S jrSrg)ExactLockfileManifestMatcher   a)  
Matcher for lockfiles and manifests that have an exact filename.
Both manifest and lockfile name must be defined.

Attributes:
    lockfile_name (str): The exact name of the lockfile.
    manifest_name (str): The exact name of the manifest
Example:
    For Pipfile.lock, the manifest is Pipfile.
lockfile_namemanifest_namer   r   c                 4    UR                   U R                  :H  $ r6   namerw   r   s     r   r7   /ExactLockfileManifestMatcher._is_manifest_match       yyD....r   c                 4    UR                   U R                  :H  $ r6   rz   rv   r   s     r   r;   /ExactLockfileManifestMatcher._is_lockfile_match   r|   r   r=   r>   c                 j    U R                   (       a"  UR                  U R                   -  nX2;   a  U$ S $ g r6   )rw   re   )r   r=   r>   rm   s       r   r@   2ExactLockfileManifestMatcher._lockfile_to_manifest   s6     )0043E3EEM$1$?=ITIr   rB   Nc                 J    US   b  US   R                   $ US   R                   $ Nr      re   rD   s     r   rE   1ExactLockfileManifestMatcher._get_subproject_root   s9     'q)5 $A&--	
 )+22	
r   r$   )r%   r&   r'   r(   r)   r_   rp   r
   r   r*   r7   r;   r   r@   r   r   rE   r-   r$   r   r   rt   rt      s    	 C= /t / //t / /!/8	$
!&$*uT4Z0%d
2CC"


 

r   rt   c                       \ rS rSr% Sr\\S'   \\S'   S\S\4S jr	S\S\4S jr
S	\S
\\   S\\   4S jrS\\\S4   \S\4   \\\4   4   S\4S jrSrg)$PatternManifestStaticLockfileMatcheri  a  
Matcher for manifests that follow a specific pattern and a static lockfile name.
Attributes:
    manifest_pattern: The pattern that the manifest name should match.
            This manifest file must be at the subproject root.
    lockfile_name: The exact name of the lockfile.
manifest_patternrv   r   r   c                 4    UR                   U R                  :H  $ r6   r~   r   s     r   r;   7PatternManifestStaticLockfileMatcher._is_lockfile_match  r|   r   c                 @    [        [        U5      U R                  5      $ r6   )r   r_   r   r   s     r   r7   7PatternManifestStaticLockfileMatcher._is_manifest_match  s    s4y$"7"788r   r=   r>   c                     U Vs1 s H  o0R                  U5      (       d  M  UiM     nnU(       d  g U H!  nUR                  UR                  :X  d  M  Us  $    g s  snf r6   )r7   re   )r   r=   r>   r   manifest_candidatesmanifest_candidates         r   r@   :PatternManifestStaticLockfileMatcher._lockfile_to_manifest  sd     (
'T+B+B4+HDZ 	 
 # #6!((M,@,@@)) #6 
s
   AArB   Nc                 J    US   b  US   R                   $ US   R                   $ r   r   rD   s     r   rE   9PatternManifestStaticLockfileMatcher._get_subproject_root%  s9     'q)5 $A&--	
 )+22	
r   r$   )r%   r&   r'   r(   r)   r_   rp   r   r*   r;   r7   r   r
   r@   r   r   rE   r-   r$   r   r   r   r     s     /t / /9t 9 9!/8	$

!&$*uT4Z0%d
2CC"



 


r   r   c                       \ rS rSr% Sr\R                  \S'   \R                  \S'   \	S\
S\4S j5       r\	S\
S\
4S	 j5       rS\
S\4S
 jrS\\   S\\
   4S jrS\\   S\\\R(                     \\
   4   4S jrSrg)ManifestOnlyMatcheri2  z
A matcher for lone manifests. These matchers must be placed after matchers
that look for both a manifest and a lockfile.

Implementors must implement _is_manifest_match and _get_subproject_root
r1   r3   r   r   c                     [         er6   r   r   s     r   r7   &ManifestOnlyMatcher._is_manifest_match>  r9   r   rm   c                     [         er6   r   r   rm   s     r   rE   (ManifestOnlyMatcher._get_subproject_rootB  r9   r   c                 $    U R                  U5      $ r6   )r7   r   s     r   r   ManifestOnlyMatcher.is_matchF  s    &&t,,r   r   c                 .   ^  [        U 4S jU 5       5      $ )zM
Return only the matching manifests from the set of dependency source files.
c              3      >#    U  H3  nTR                  UR                  5      (       d  M%  UR                  v   M5     g 7fr6   )r7   rK   )rT   pr   s     r   rU   AManifestOnlyMatcher._filter_matching_manifests.<locals>.<genexpr>O  s,      
-1H1H1QGAGG-s   $>>)r\   r    s   ` r   _filter_matching_manifests.ManifestOnlyMatcher._filter_matching_manifestsI  s      
-
 
 	
r   c                    U R                  U5      n/ nU H  nU R                  U5      n[        R                  " [        R                  " U R
                  [        R                  " [        U5      5      S95      nUR                  [        R                  " [        R                  " [        U5      5      [        R                  " U5      U R                  S95        M     X24$ )NrW   rY   )r   rE   r+   rf   ra   r1   r^   r_   rc   r,   rd   r3   )r   r   rN   rh   rm   rZ   manifest_dep_sources          r   r!   $ManifestOnlyMatcher.make_subprojectsS  s     334DE	,.&M00?H"%"2"2++#))C<N2O#
  YYs8}5&)&:&:;N&O"nn ' %%r   r$   N)r%   r&   r'   r(   r)   r+   ro   rp   rr   r   r   r*   r7   rE   r   r   r   r   r   r	   r,   r!   r-   r$   r   r   r   r   2  s     ###}}"t " " " "$ "4 " "-T -d -
 )& 1
	4
& )& 1&	tCNN#Yt_4	5&r   r   c                   D    \ rS rSr% \\S'   S\S\4S jrS\S\4S jr	Sr
g	)
ExactManifestOnlyMatcherik  rw   rm   r   c                     UR                   $ r6   r   r   s     r   rE   -ExactManifestOnlyMatcher._get_subproject_rooto  s    ###r   r   c                 4    UR                   U R                  :H  $ r6   ry   r   s     r   r7   +ExactManifestOnlyMatcher._is_manifest_matchr  r|   r   r$   N)r%   r&   r'   r(   r_   rp   r   rE   r*   r7   r-   r$   r   r   r   r   k  s.    $$ $4 $/t / /r   r   )abcr   r   dataclassesr   r   pathlibr   typingr   r	   r
   r   r   r   ,semgrep.semgrep_interfaces.semgrep_output_v1semgrep_interfacessemgrep_output_v1r+   semgrep.typesr   r   r/   rt   r   r   r   r$   r   r   <module>r      s      !         : :   $" " ": $WU/ WU WUt $)
#: )
 )
X $+
+B +
 +
\ $5&+ 5& 5&p $/2 / /r   