
    ܖi                     B   d 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
Z
ddlmZmZ ddlmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ  ej4                  e      Z ed
      Z e ee
j>                              Z  G d de      Z! G d de      Z" G d de      Z#y)z[
Collect the local environment's active dependencies via `pip list`, wrapped
by `pip-api`.
    N)IteratorSequence)Path)InvalidVersionVersion)DependencyFixErrorDependencySourceDependencySourceError)ResolvedFixVersion)
DependencyResolvedDependencySkippedDependency)
AuditStatez10.0.0b0c                   j    e Zd ZdZdg d e       ddedee   dededd	f
d
Zde	e
   fdZdedd	fdZy	)	PipSourcezG
    Wraps `pip` (specifically `pip list`) as a dependency source.
    F)localpathsskip_editablestater   r   r   r   returnNc                v   || _         || _        || _        || _        t        j
                  j                  dt        j                        }t	        j                  d      }|-|j                  |      st        j                  d| d| d       t        t        k  rt        j                  dt         d       yy)	aE  
        Create a new `PipSource`.

        `local` determines whether to do a "local-only" list. If `True`, the
        `DependencySource` does not expose globally installed packages.

        `paths` is a list of locations to look for installed packages. If the
        list is empty, the `DependencySource` will query the current Python
        environment.

        `skip_editable` controls whether dependencies marked as "editable" are skipped.
        By default, editable dependencies are not skipped.

        `state` is an `AuditState` to use for state callbacks.
        PIPAPI_PYTHON_LOCATIONVIRTUAL_ENVNzpip-audit will run pip against z/, but you have a virtual environment loaded at z. This may result in unintuitive audits, since your local environment will not be audited. You can forcefully override this behavior by setting PIPAPI_PYTHON_LOCATION to the location of your virtual environment's Python interpreter.zpip z is very old, and may not provide reliable dependency information! You are STRONGLY encouraged to upgrade to a newer version of pip.)_local_paths_skip_editabler   osenvirongetsys
executablegetenv
startswithloggerwarning_PIP_VERSION_MINIMUM_RELIABLE_PIP_VERSION)selfr   r   r   r   effective_pythonvenv_prefixs          d/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_dependency_source/pip.py__init__zPipSource.__init__,   s    . +
" ::>>*BCNNSii."+;+F+F{+SNN12B1C D33>- @TT 77NN|n %( ( 8    c           	   #     K   	 t        j                  | j                  t        | j                              j                         D ]  \  }}|j                  r$| j                  rt        |j                  d      }nj	 t        |j                  t        t        |j                                    }| j                  j                  d|j                   d|j                   d       |  y
# t         $ rL d|j                   d|j                   d}t"        j%                  |       t        |j                  |      }Y [w xY w# t&        $ r}t)        d	      |d
}~ww xY ww)z
        Collect all of the dependencies discovered by this `PipSource`.

        Raises a `PipSourceError` on any errors.
        )r   r   zdistribution marked as editable)nameskip_reason)r/   versionzCollecting  ()z6Package has invalid version and could not be audited: z&failed to list installed distributionsN)pip_apiinstalled_distributionsr   listr   itemseditabler   r   r/   r   r   strr1   r   update_stater   r$   debug	ExceptionPipSourceError)r(   _distdepr0   es         r+   collectzPipSource.collecti   s5    	R"::kkdkk):eg4 ==T%8%8+!YY4UC	Y0diiQTUYUaUaQbIcd

//+chhZr#++VW0XY 	' * YT#yykDLL>< $ [1/TYYKXY  	R !IJPQQ	RsO   E"A8E =A)C-&E ,E"-AE?E EE 	EEEE"fix_versionc           	      $   | j                   j                  d|j                  j                   d|j                  j                   d|j                   d       t
        j                  ddd|j                  j                   d|j                   g}	 t        j                  |d	t        j                  t        j                  
       y# t        j                  $ r5}t        d|j                  j                   d|j                         |d}~ww xY w)zA
        Fixes a dependency version in this `PipSource`.
        zFixing r2   z => r3   z-mpipinstallz==T)checkstdoutstderrzfailed to upgrade dependency z to fix version N)r   r:   r@   r/   r1   r    r!   canonical_name
subprocessrunDEVNULLCalledProcessErrorPipFixError)r(   rC   fix_cmdcpes       r+   fixzPipSource.fix   s     	

koo**+2koo.E.E-Fd;K^K^J__`a	
 NN--.b1D1D0EF
	NN!))!))	 ,, 	/0D0D/EEU&&') 	s   5C D0D

D)__name__
__module____qualname____doc__r   boolr   r   r,   r   r   rB   r   rR    r-   r+   r   r   '   s{      "#&L; ; ~	;
 ; ; 
;zR*- RB1 d r-   r   c                       e Zd ZdZy)r=   z)A `pip` specific `DependencySourceError`.NrS   rT   rU   rV   rX   r-   r+   r=   r=      s    3r-   r=   c                       e Zd ZdZy)rO   z&A `pip` specific `DependencyFixError`.NrZ   rX   r-   r+   rO   rO      s    0r-   rO   )$rV   loggingr   rK   r    collections.abcr   r   pathlibr   r4   packaging.versionr   r   pip_audit._dependency_sourcer   r	   r
   pip_audit._fixr   pip_audit._servicer   r   r   pip_audit._stater   	getLoggerrS   r$   r'   r9   PIP_VERSIONr&   r   r=   rO   rX   r-   r+   <module>rf      s   
  	  
 .   5 
 . P P '			8	$
 !(
 3  s7../0|  |~	* 		$ 	r-   