Ë
    tPêjß   ã                  óð   — d Z ddlm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 d	d
lmZ d	dlmZmZ  ej.                  e«      Z G d„ dej4                  «      Z G d„ de«      Zy)z[
Create virtual environments with a custom set of packages and inspect their dependencies.
é    )ÚannotationsN)ÚIterator)ÚPathLike)ÚNamedTemporaryFileÚTemporaryDirectoryÚ
gettempdir)ÚSimpleNamespace)ÚVersioné   )Ú
AuditState)ÚCalledProcessErrorÚrunc                  ó|   ‡ — e Zd ZdZdg  e«       f	 	 	 	 	 	 	 dˆ fd„Zd	ˆ fd„Zd
d„Zedd„«       Z	edd„«       Z
ˆ xZS )Ú
VirtualEnvaß  
    A wrapper around `EnvBuilder` that allows a custom `pip install` command to be executed, and its
    resulting dependencies inspected.

    The `pip-audit` API uses this functionality internally to deduce what the dependencies are for a
    given requirements file since this can't be determined statically.

    The `create` method MUST be called before inspecting the `installed_packages` property otherwise
    a `VirtualEnvError` will be raised.

    The expected usage is:
    ```
    # Create a virtual environment and install the `pip-api` package.
    ve = VirtualEnv(["pip-api"])
    ve.create(".venv/")
    for (name, version) in ve.installed_packages:
        print(f"Installed package {name} ({version})")
    ```
    Nc                ól   •— t         ‰| �  d¬«       || _        || _        || _        d| _        || _        y)a  
        Create a new `VirtualEnv`.

        `install_args` is the list of arguments that would be used the custom install command. For
        example, if you wanted to execute `pip install -e /tmp/my_pkg`, you would create the
        `VirtualEnv` like so:
        ```
        ve = VirtualEnv(["-e", "/tmp/my_pkg"])
        ```

        `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.
        T)Úwith_pipN)ÚsuperÚ__init__Ú_install_argsÚ
_index_urlÚ_extra_index_urlsÚ	_packagesÚ_state)ÚselfÚinstall_argsÚ	index_urlÚextra_index_urlsÚstateÚ	__class__s        €ú[/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/pip_audit/_virtual_env.pyr   zVirtualEnv.__init__,   s:   ø€ ô. 	‰Ñ $ÐÔ'Ø)ˆÔØ#ˆŒØ!1ˆÔØ;?ˆŒØˆ�ó    c                óp   •— 	 t         ‰| �  |«      S # t        $ r t        «       }t	        d|› d�«      ‚w xY w)z2
        Creates the virtual environment.
        z0Couldn't execute in a temporary directory under zÀ. This is sometimes caused by a noexec mount flag or other setting. Consider changing this setting or explicitly specifying a different temporary directory via the TMPDIR environment variable.)r   ÚcreateÚPermissionErrorr   ÚVirtualEnvError)r   Úenv_dirÚbase_tmpdirr   s      €r    r#   zVirtualEnv.createJ   sP   ø€ ð
	Ü‘7‘> 'Ó*Ð*øÜò 	ô %›,ˆKÜ!ØBÀ;À-ð PKð Kóð ð	ús   ƒ ’#5c           
     óž  — | j                   j                  d«       |j                  dddddddg}	 t        || j                   ¬«       | j                   j                  d«       t        «       5 }t        |d¬«      5 }|j                  dddddg| j                  ¢d‘d‘|j                  ‘| j                  ¢}	 t        |d| j                   ¬«       | j                   j                  d«       t        j                  |«      }|d   }g | _        |D ]3  }	|	d   }
| j                   j#                  |
d   t%        |
d   «      f«       Œ5 	 d
d
d
«       d
d
d
«       y
# t        $ r}t        d	|› �«      |‚d
}~ww xY w# t        $ r6}t        j                  d|j                  › �«       t        d|› �«      |‚d
}~ww xY w# 1 sw Y   ŒtxY w# 1 sw Y   y
xY w)ac  
        Install the custom package and populate the list of installed packages.

        This method is overridden from `EnvBuilder` to execute immediately after the virtual
        environment has been created and should not be called directly.

        We do a few things in our custom post-setup:
        - Upgrade the `pip` version. We'll be using `pip list` with the `--format json` option which
          requires a non-ancient version for `pip`.
        - Install `wheel`. When our packages install their own dependencies, they might be able
          to do so through wheels, which are much faster and don't require us to run
          setup scripts.
        - Execute the custom install command.
        - Call `pip list`, and parse the output into a list of packages to be returned from when the
          `installed_packages` property is queried.
        z1Updating pip installation in isolated environmentz-mÚpipÚinstallz	--upgradeÚwheelÚ
setuptools)r   zFailed to upgrade `pip`: Nz*Installing package in isolated environmentF)ÚdirÚdeletez
--no-inputz--keyring-provider=subprocessz	--dry-runz--reportT)Ú
log_stdoutr   zinternal pip failure: zFailed to install packages: z1Processing package list from isolated environmentÚmetadataÚnameÚversion)r   Úupdate_stateÚenv_exer   r   r%   r   r   Ú_index_url_argsr1   r   ÚloggerÚerrorÚstderrÚjsonÚloadr   Úappendr
   )r   ÚcontextÚpip_upgrade_cmdÚcpeÚve_dirÚtmpÚpackage_install_cmdÚinstall_reportÚpackage_listÚpackageÚpackage_metadatas              r    Ú
post_setupzVirtualEnv.post_setupd   s  € ð" 	�‰× Ñ Ð!TÔUð �O‰OØØØØØØØð	
ˆð	ZÜ� t§{¡{Õ3ð 	�‰× Ñ Ð!MÔNäÓ!ð +	 VÔ-?ÀFÐSXÔ-Yð +	Ð]`ð —‘ØØØØØ/ð#ð ×%Ñ%ð#ð ð#ð ð#ð —‘ð#ð ×#Ñ#ð#ÐðeÜÐ'°DÀÇÁÕLð �K‰K×$Ñ$Ð%XÔYä!ŸY™Y s›^ˆNØ)¨)Ñ4ˆLð  ˆDŒNØ'ò �Ø#*¨:Ñ#6Ð Ø—‘×%Ñ%Ø% fÑ-¬wÐ7GÈ	Ñ7RÓ/SÐTõñ÷O+	÷ +	ð +	øô "ò 	ZÜ!Ð$=¸oÐ=NÐ"OÓPÐVYÐYûð	Zûô@ &ò eä—‘Ð5°c·j±j°\ÐBÔCÜ%Ð(DÐEXÐDYÐ&ZÓ[ÐadÐdûðeú÷7+	ð +	ú÷ +	ð +	ús`   ±E Á-GÁ;;F7Â7E5ÃA4F7ÅGÅ	E2ÅE-Å-E2Å5	F4Å>1F/Æ/F4Æ4F7Æ7G 	Æ<GÇGc              #  óf   K  — | j                   €t        d«      ‚| j                   E d{  –—†  y7 Œ­w)zµ
        A property to inspect the list of packages installed in the virtual environment.

        This method can only be called after the `create` method has been called.
        NzcInvalid usage of wrapper.The `create` method must be called before inspecting `installed_packages`.)r   r%   )r   s    r    Úinstalled_packageszVirtualEnv.installed_packages¹   s4   è ø€ ð �>‰>Ð!Ü!ð]óð ð
 —>‘>×!Ò!ús   ‚'1©/ª1c                ó¤   — g }| j                   r|j                  d| j                   g«       | j                  D ]  }|j                  d|g«       Œ |S )Nz--index-urlz--extra-index-url)r   Úextendr   )r   Úargsr   s      r    r5   zVirtualEnv._index_url_argsÈ   sO   € àˆØ�?Š?Ø�K‰K˜¨¯©Ð8Ô9Ø×/Ñ/ò 	:ˆIØ�K‰KÐ,¨iÐ8Õ9ð	:àˆr!   )r   ú	list[str]r   z
str | Noner   rL   r   r   )r&   z-str | bytes | PathLike[str] | PathLike[bytes]ÚreturnÚNone)r<   r	   rM   rN   )rM   zIterator[tuple[str, Version]])rM   rL   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   rF   ÚpropertyrH   r5   Ú__classcell__)r   s   @r    r   r      st   ø„ ñð. !%Ø&(Ù&›Lðàðð ðð $ð	ð
 õõ<ó4Sðj ò"ó ð"ð òó ôr!   r   c                  ó   — e Zd ZdZy)r%   zZ
    Raised when `VirtualEnv` fails to build or inspect dependencies, for any reason.
    N)rO   rP   rQ   rR   © r!   r    r%   r%   Ò   s   „ ñð 	r!   r%   )rR   Ú
__future__r   r9   ÚloggingÚvenvÚcollections.abcr   Úosr   Útempfiler   r   r   Útypesr	   Úpackaging.versionr
   r   r   Ú_subprocessr   r   Ú	getLoggerrO   r6   Ú
EnvBuilderr   Ú	Exceptionr%   rV   r!   r    ú<module>rc      sa   ðñõ #ã Û Û Ý $Ý ß GÑ GÝ !å %å ß 0à	ˆ×	Ñ	˜8Ó	$€ôx�—‘ô xôv	�iõ 	r!   