o
    tBh                      @  s<  d 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	m
Z
 ddlmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZ ddlm Z  e!e"Z#e	G dd dZ$G dd dej%Z&d8ddZ'd9dd Z(d:d'd(Z)d;d+d,Z*d<d/d0Z+d=d4d5Z,d>d6d7Z-dS )?zCommon functions.    )annotationsN)	dataclassfield)	find_spec)Path)Callable	GeneratorIterable)Marker)NormalizedNamecanonicalize_name)
PipSession)install_req_from_line)ParsedRequirementparse_requirements   )__version__c                   @  s>   e Zd ZU dZded< ded< eedZded< dddZdS )FoundModulez!A module with uses in the source.strmodnamer   filename)default_factoryzlist[tuple[str, int]]	locationsreturnNonec                 C  s   t | j | _d S N)r   r   resolveself r   l/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pip_check_reqs/common.py__post_init__&   s   zFoundModule.__post_init__N)r   r   )	__name__
__module____qualname____doc____annotations__r   listr   r!   r   r   r   r    r      s   
 r   c                      sP   e Zd Zd fddZdd	d
ZdddZdddZdddZdddZ  Z	S ) _ImportVisitorignore_modules_functionCallable[[str], bool]r   r   c                   s    t    || _i | _d | _d S r   )super__init___ignore_modules_function_modules	_location)r   r)   	__class__r   r    r,   +   s   

z_ImportVisitor.__init__locationr   c                C  s
   || _ d S r   )r/   )r   r2   r   r   r    set_location1   s   
z_ImportVisitor.set_locationnode
ast.Importc                 C  s    |j D ]
}| |j|j qd S r   )names_add_modulenamelinenor   r4   aliasr   r   r    visit_Import5   s   
z_ImportVisitor.visit_Importast.ImportFromc                 C  sN   |j dkrd S |jD ]}|j d u s|jdkrq
| |j d |j |j q
d S )N
__future__r   .)moduler6   levelr7   r8   r9   r:   r   r   r    visit_ImportFrom=   s   

z_ImportVisitor.visit_ImportFromr   r9   intc           	   	   C  s  |  |rd S g }|dD ]q}dg ||}zt|d}W n ty+   Y  d S w |d u r3 d S |jd u r>|| q|j}|dkrFqt|}|j}|| j	vri|
 r`|jdkr_|j}n	 t||d| j	|< t| jtsqJ | j	| j| j|f  d S d S )Nr?   )r8   frozen__init__.py)r   r   )r-   splitjoinr   
ValueErrororiginappendr   r8   r.   is_fileparentr   
isinstancer/   r   r   )	r   r   r9   modname_parts_progressmodname_partr8   module_specmodpathmodpath_pathr   r   r    r7   J   sB   




z_ImportVisitor._add_moduledict[str, FoundModule]c                 C  s   | j S r   )r.   r   r   r   r    finalise}   s   z_ImportVisitor.finalise)r)   r*   r   r   )r2   r   r   r   )r4   r5   r   r   )r4   r=   r   r   )r   r   r9   rC   r   r   )r   rS   )
r"   r#   r$   r,   r3   r<   rB   r7   rT   __classcell__r   r   r0   r    r(   *   s    



3r(   rootr   r   Generator[Path, None, None]c                 c  sR    |   r| jdkr|  V  d S |  d}t|| dD ]}| V  qd S )Nz.pyz" is not a python file or directoryz*.py)rK   suffixabsoluterH   rglob)rV   msgitemr   r   r    pyfiles   s   

r]   pathsIterable[Path]ignore_files_functionr*   r)   rS   c              	   C  s   t |d}| D ]5}t|D ].}|t|rtd| qtd| |jdd}|jt|d |t	
|t| qq| S )N)r)   zignoring: %szscanning: %szutf-8)encoding)r2   )r(   r]   r   loginfodebug	read_textr3   visitastparserT   )r^   r`   r)   vispathr   contentr   r   r    find_imported_modules   s   
rl   ignore_requirements_function)Callable[[str | ParsedRequirement], bool]skip_incompatibleboolrequirements_filenameset[NormalizedName]c                 C  s   t  }tt|t dD ]8}t|jj}t|tsJ | |r&t	d| q|r7|j}t
|ds7t	d| qt	d| |t| q|S )N)sessionzignoring requirement: %s)full_requirementz:ignoring requirement (incompatible environment marker): %szfound requirement: %s)setr   r   r   r   requirementr8   rM   rb   rd   has_compatible_markersaddr   )rm   ro   rq   explicitrv   requirement_namerequirement_stringr   r   r    find_required_modules   s2   	

r|   rt   r   c                 C  s.   d| vrdS |  dd }|sdS t| S )N;Tr   )rF   r
   evaluate)rt   enviroment_markerr   r   r    rw      s   rw   rj   Path | Nonec                 C  s&   | j | j j kr	dS | jdvrdS | j S )zReturn the package path for a given Python package sentinel file.

    Return None if the path is not a sentinel file.

    A sentinel file is the __init__.py or its compiled variants.
    N)rE   z__init__.pycz__init__.pyo)rL   r8   )rj   r   r   r    package_path   s
   
r   
ignore_cfg	list[str]Callable[..., bool]c                 C  s   | sdd S | fdd	d
}|S )Nc                 S  s   dS )NFr   )_r   r   r    <lambda>   s    zignorer.<locals>.<lambda>	candidatestr | ParsedRequirementr   r   r   rp   c                 S  sh   |D ]/}t | tr| }nt| jj}t |tsJ |}t||r$ dS ttj||r1 dS qdS )NTF)	rM   r   r   rv   r8   fnmatchosrj   relpath)r   r   ignorecandidate_pathoptional_candidate_pathr   r   r    ignorer_function   s    
z!ignorer.<locals>.ignorer_function)r   r   r   r   r   rp   r   )r   r   r   r   r    ignorer   s
   r   c                  C  sN   t jd d \} }}|  d| d| }ttj }dt d| d| dS )N   r?   zpip-check-reqs z from z	 (python ))sysversion_infor   __file__rL   r   r   )majorminorpatchpython_versionparent_directoryr   r   r    r      s   r   )rV   r   r   rW   )r^   r_   r`   r*   r)   r*   r   rS   )rm   rn   ro   rp   rq   r   r   rr   )rt   r   r   rp   )rj   r   r   r   )r   r   r   r   )r   r   ).r%   r>   r   rg   r   loggingr   r   dataclassesr   r   importlib.utilr   pathlibr   typingr   r   r	   packaging.markersr
   packaging.utilsr   r   pip._internal.network.sessionr   pip._internal.req.constructorsr   pip._internal.req.req_filer   r    r   	getLoggerr"   rb   r   NodeVisitorr(   r]   rl   r|   rw   r   r   r   r   r   r   r    <module>   s8    

W


'

