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	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mZ dd
lmZ ddlmZ er`ddlmZ e e!Z"ed$ddZ#d%ddZ$d&d'd"d#Z%dS )(zFind extra requirements.    )annotationsN)cache)Path)TYPE_CHECKINGCallableIterable)mock)NormalizedNamecanonicalize_name)_PackageInfosearch_packages_info)common)version_info)ParsedRequirementreturnlist[_PackageInfo]c                  C  sZ   dd t j D } tjtjddi tt	| dW  d    S 1 s&w   Y  d S )Nc                 S  s   g | ]}|j d  qS )Name)metadata).0dist r   u/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pip_check_reqs/find_extra_reqs.py
<listcomp>%   s    
z%get_packages_info.<locals>.<listcomp>_PIP_USE_IMPORTLIB_METADATAFalse)query)
	importlibr   distributionsr   patchdictosenvironlistr   )all_pkgsr   r   r   get_packages_info#   s   $r$   requirements_filenamer   pathsIterable[Path]ignore_files_functionCallable[[str], bool]ignore_modules_functionignore_requirements_function)Callable[[str | ParsedRequirement], bool]skip_incompatiblebool	list[str]c              
     sl  t j|||d}i }t }t  }	|D ]\}
|
j}|
j}g }|
jp"g D ]&}t|| }| }z||	}W n t	yA   |}Y nw |
t| q#td|| |D ]}t|| }| }|||< t j|d}|ro|||< qSqtt | D ]*\}}|j|v rt||j }td|||j   | 
| qztd||j qzt j||| d} fdd|D S )	N)r&   r(   r*   zinstalled package: %s (at %s))pathz!used module: %s (from package %s)z8used module: %s (from file %s, assuming stdlib or local))r+   r-   r%   c                   s   g | ]}| vr|qS r   r   )r   nameusedr   r   r      s    z#find_extra_reqs.<locals>.<listcomp>)r   find_imported_modulesr$   r   resolver1   locationfilesrelative_to
ValueErrorappendstrlogdebugpackage_pathcollectionsdefaultdictr"   itemsfilenamer
   find_required_modules)r%   r&   r(   r*   r+   r-   used_modulesinstalled_filespackages_infoherepackagepackage_namepackage_locationpackage_filesitemitem_location_relitem_locationrelative_item_locationpackage_filer0   r>   modnameinfo	used_nameexplicitr   r2   r   find_extra_reqs0   sr   

rU   	argumentslist[str] | NoneNonec                 C  s  d}t |}|jdtdd |jddtdtdd	d
 |jddddg dd |jddddg dd |jddddg dd |jddddddd |jdd d!ddd"d |jd#d$d%ddd&d |jd'd(d)ddd*d || }|jrtjt	 d+  t
d, |js|d- tj|jd.}tj|jd.}tj|jd.}tjd/d0 |jrtj}n
|jrtj}ntj}t| tj| tt	  t|j|j||||jd1}|rtd2 |D ]}	|	 d3|j }
t|
 q|rt
d4 d5S d5S )6zpip-extra-reqs entry point.z+usage: %prog [options] files or directoriesr&   *)typenargsz--requirements-filer%   PATHzrequirements.txtz>path to the requirements file (defaults to "requirements.txt"))destrZ   metavardefaulthelpz-fz--ignore-fileignore_filesr:   zfile paths globs to ignore)r]   actionr_   r`   z-mz--ignore-moduleignore_modsz*used module names (globs are ok) to ignorez-rz--ignore-requirementignore_reqszreqs in requirements to ignorez-sz--skip-incompatibler-   
store_trueFz<skip requirements that have incompatible environment markersz-vz	--verboseverbosezbe more verbosez-dz--debugr=   zbe *really* verbosez-Vz	--versionversionzdisplay version information
r   z(no source files or directories specified)
ignore_cfgz%(message)s)format)r%   r&   r(   r*   r+   r-   zExtra requirements:z in    N) argparseArgumentParseradd_argumentr   
parse_argsrg   sysstdoutwriter   exitr&   errorr   ignorerra   rc   rd   loggingbasicConfigr=   DEBUGrf   INFOWARNr<   setLevelrR   rU   r%   r-   warning)rV   usageparserparse_resultra   rc   rd   levelextrasr1   messager   r   r   main   s   
	
	


	
r   )r   r   )r%   r   r&   r'   r(   r)   r*   r)   r+   r,   r-   r.   r   r/   )N)rV   rW   r   rX   )&__doc__
__future__r   rl   r?   importlib.metadatar   rv   r    rp   	functoolsr   pathlibr   typingr   r   r   unittestr   packaging.utilsr	   r
   pip._internal.commands.showr   r   pip_check_reqsr   pip_check_reqs.commonr   pip._internal.req.req_filer   	getLogger__name__r<   r$   rU   r   r   r   r   r   <module>   s.    

Z