
    ܖio                    &   d Z ddlm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 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 ddlmZmZ  ej@                  e!      Z" G d de      Z# G d de      Z$ G d de      Z%y)z3
Collect dependencies from `pyproject.toml` files.
    )annotationsN)Iterator)Path)NamedTemporaryFileTemporaryDirectory)Requirement)SpecifierSet)DependencyFixErrorDependencySourceDependencySourceError)ResolvedFixVersion)
DependencyResolvedDependency)
AuditState)
VirtualEnvVirtualEnvErrorc                  L    e Zd ZdZdg  e       f	 	 	 	 	 	 	 	 	 ddZddZddZy)	PyProjectSourcezN
    Wraps `pyproject.toml` dependency resolution as a dependency source.
    Nc                     || _         || _        y)a.  
        Create a new `PyProjectSource`.

        `filename` provides a path to a `pyproject.toml` file

        `index_url` is the base URL of the package index.

        `extra_index_urls` are the extra URLs of package indexes.

        `state` is an `AuditState` to use for state callbacks.
        N)filenamestate)selfr   	index_urlextra_index_urlsr   s        j/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/pip_audit/_dependency_source/pyproject.py__init__zPyProjectSource.__init__$   s    $ !
    c           	   #    K   | j                   j                  d      5 }t        j                  |      }|j	                  d      }|t        d| j                    d      |j	                  d      }|-t        j                  d| j                    d       	 ddd       yt               5 }t        |d	      5 }|j                  t        j                  j                  |      j                                |j                          t!        d
|j"                  g| j$                        }	 |j'                  |       |j,                  D ]  \  }	}
t/        |	|
        	 ddd       ddd       ddd       y# t(        $ r}t        t+        |            |d}~ww xY w# 1 sw Y   @xY w# 1 sw Y   DxY w# 1 sw Y   yxY ww)z
        Collect all of the dependencies discovered by this `PyProjectSource`.

        Raises a `PyProjectSourceError` on any errors.
        rbprojectNpyproject file # does not contain `project` sectiondependencies% does not contain `dependencies` listF)dirdeletez-r)install_argsr   )nameversion)r   opentomliloadgetPyProjectSourceErrorloggerwarningr   r   writeoslinesepjoinencodeflushr   r(   r   creater   strinstalled_packagesr   )r   fpyproject_datar    depsve_dirreq_fileveexcr(   r)   s              r   collectzPyProjectSource.collect9   s     ]]% *	I"ZZ]N$((3G*%dmm_4WX  ;;~.D|%dmm_4YZ *	I *	I, #$I(."ve<I@H rzzt4;;=>   dHMM-B$**UBIIf%
 &(%:%: IMD',$HHI)I I+*	I *	IJ ' B.s3x8cAB!I I I I+*	I *	Is~   GA9F5	G 
F5*F)8A0F)E7:#FF)&F5.	G7	F	 F	F	FF&"F))F2	.F55F>:Gc                F   | j                   j                  d      5 }t        dd      5 }t        j                  |      }|j                  d      }|t        d| j                    d      |j                  d      }|5t        j                  d| j                    d	       	 ddd       ddd       y|D cg c]  }t        |       }}t        t        |            D ]  }	||	   }
|
j                  |j                  j                  k(  r|
j                  j                  |j                  j                         rP|
j                  j                  |j                         s+t#        d
|j                          |
_        t%        |
      ||	<   |
j&                  |
j&                  j)                         rJ  t+        j,                  ||       ddd       ddd       t/        j0                  j                  | j                          yc c}w # 1 sw Y   AxY w# 1 sw Y   ExY w)zH
        Fixes a dependency version for this `PyProjectSource`.
        zrb+F)moder&   r    Nr!   r"   r#   r$   z==)r   r*   r   r+   r,   r-   PyProjectFixErrorr/   r0   r   rangelenr(   dep	specifiercontainsr)   r	   r8   markerevaluatetomli_wdumpr2   replace)r   fix_versionr:   tmpr;   r    r<   rG   reqsireqs              r   fixzPyProjectSource.fixl   s   
 ]]&  	.!-?USX-Y  	.]`"ZZ]N$((3G'%dmm_4WX  ;;~.D|%dmm_4YZ  	.  	.  	." 155K$5D53t9% C 1gHH 4 44..{/F/FGMM22;3F3FG$02k6I6I5J1K$LCM!#hDGzz)SZZ-@-@-BBBC LL-A 	.  	.F 	

388T]]+% 6# 	.  	.  	.  	.sN   HA9H#H4H8H
CHH2HHHH	HH )
r   r   r   z
str | Noner   z	list[str]r   r   returnNone)rU   zIterator[Dependency])rO   r   rU   rV   )__name__
__module____qualname____doc__r   r   rA   rT    r   r   r   r      sU     !%&(&L  $	
  
*1If(,r   r   c                      e Zd ZdZy)r.   z4A `pyproject.toml` specific `DependencySourceError`.NrW   rX   rY   rZ   r[   r   r   r.   r.      s    >r   r.   c                      e Zd ZdZy)rD   z1A `pyproject.toml` specific `DependencyFixError`.Nr]   r[   r   r   rD   rD      s    ;r   rD   )&rZ   
__future__r   loggingr2   collections.abcr   pathlibr   tempfiler   r   r+   rL   packaging.requirementsr   packaging.specifiersr	   pip_audit._dependency_sourcer
   r   r   pip_audit._fixr   pip_audit._servicer   r   pip_audit._stater   pip_audit._virtual_envr   r   	getLoggerrW   r/   r   r.   rD   r[   r   r   <module>rl      s~    #  	 $  ;   . - 
 . = ' >			8	$u,& u,p	0 		* 	r   