HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/pip.cpython-310.pyc
o

�N�g���@sdZddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
Z	ddlZ	ddlZ	ddl
Z	ddlZ	ddlZ	ddlZ	ddlmZmZe�e�ZddiZgd�Ze�dej�Ze�dej�Zd	d
�Zdd�Zd6d
d�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&dd�Z'																																					 								d7d!d"�Z(									 	d8d#d$�Z)d9d%d&�Z*	d:d'd(�Z+d:d)d�Z,d;d*d+�Z-d;d,d-�Z.d;d.d/�Z/d;d0d1�Z0d<d2d3�Z1								d=d4d5�Z2dS)>a

Install Python packages with pip to either the system or a virtualenv

Windows Support
===============

.. versionadded:: 2014.7.4

Salt now uses a portable python. As a result the entire pip module is now
functional on the salt installation itself. You can pip install dependencies
for your custom modules. You can even upgrade salt itself using pip. For this
to work properly, you must specify the Current Working Directory (``cwd``) and
the Pip Binary (``bin_env``) salt should use.  The variable ``pip_bin`` can be
either a virtualenv path or the path to the pip binary itself.

For example, the following command will list all software installed using pip
to your current salt environment:

.. code-block:: bat

   salt <minion> pip.list cwd='C:\salt\bin\Scripts' bin_env='C:\salt\bin\Scripts\pip.exe'

Specifying the ``cwd`` and ``bin_env`` options ensures you're modifying the
salt environment. If these are omitted, it will default to the local
installation of python. If python is not installed locally it will fail saying
it couldn't find pip.

State File Support
------------------

This functionality works in states as well. If you need to pip install colorama
with a state, for example, the following will work:

.. code-block:: yaml

   install_colorama:
     pip.installed:
       - name: colorama
       - cwd: 'C:\salt\bin\scripts'
       - bin_env: 'C:\salt\bin\scripts\pip.exe'
       - upgrade: True

Upgrading Salt using Pip
------------------------

You can now update salt using pip to any version from the 2014.7 branch
forward. Previous version require recompiling some of the dependencies which is
painful in windows.

To do this you just use pip with git to update to the version you want and then
restart the service. Here is a sample state file that upgrades salt to the head
of the 2015.5 branch:

.. code-block:: yaml

   install_salt:
     pip.installed:
       - cwd: 'C:\salt\bin\scripts'
       - bin_env: 'C:\salt\bin\scripts\pip.exe'
       - editable: git+https://github.com/saltstack/salt@2015.5#egg=salt
       - upgrade: True

   restart_service:
     service.running:
       - name: salt-minion
       - enable: True
       - watch:
         - pip: install_salt

.. note::
   If you're having problems, you might try doubling the back slashes. For
   example, cwd: 'C:\\salt\\bin\\scripts'. Sometimes python thinks the single
   back slash is an escape character.

   There is a known incompatibility between Python2 pip>=10.* and Salt <=2018.3.0.
   The issue is described here: https://github.com/saltstack/salt/issues/46163

�N)�CommandExecutionError�CommandNotFoundError�list_�list)�http�https�ftp�filez"(?:-r\s|--requirement[=\s])(.*)\n?z
(?:^|\s+)#.*$cCsdS)z�
    There is no way to verify that pip is installed without inspecting the
    entire filesystem.  If it's not installed in a conventional location, the
    user is required to provide the location of pip each time it is used.
    �pip�rrr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pip.py�__virtual__osr
cCs<tjj��r|dur|durdtj�|�vrtj�|�}|S)z�
    Binary builds need to have the 'cwd' set when using pip on Windows. This will
    set cwd if pip is being used in 'bin_env', 'cwd' is None and salt is on windows.
    Nr
)�salt�utils�platform�
is_windows�os�path�basename�dirname)�cwd�bin_envrrr�_pip_bin_envxs rcCs*d}|dur
|�d|��}t�|d�dS)z'
    Remove the cached pip version
    �pip.versionN�.)�__context__�pop)r�
contextkeyrrr�_clear_context�srcCsttd�rdSdS)z[
    Gather run-time information to indicate if we are running from source or bundled.
    �RELENVTF)�hasattr�sysrrrr�_check_bundled�s
r"cs:|s!t�rt�d�ttjd�gSt�d�tj�tj	�ddgSt
jj�
�r)dnd��fdd	�}tj�|�ri||�D]&}tj�|�rat�|tj�r[t�d
|�tj�|�ddgSt�d|�q;td|����t�|tj�r�tj�|�r�dtj�|�vr�tj�|�ddgStj�|�gStd
|����td|�d���)z�
    Locate the pip binary, either from `bin_env` as a virtualenv, as the
    executable itself, or from searching conventional filesystem locations
    zpip: Using pip from bundled appzsalt-pipz,pip: Using pip from currently-running Pythonz-mr
z
python.exe�pythonc
sDg}|D]}|�tj�|��tj�|d��tj�|d��g�q|S)N�bin�Scripts)�extendrr�join)Zbasedirs�retr�Z
python_binrr�
_search_paths�s��z#_get_pip_bin.<locals>._search_pathszpip: Found python binary: %sz=pip: Found python binary by name but it is not executable: %sz*Could not find a pip binary in virtualenv z#Could not find a pip binary within zAccess denied to z, could not find a pip binary)r"�logger�debug�strr!rrr�normpath�
executablerrrr�isdir�isfile�access�X_OKrrr)rr*Zbin_pathrr)r�_get_pip_bin�s>


���
�r4cCs|tjj�|�\}}|r
|}|td|�vrdStd||�}|s'td||�}td||�td||�kr<td||�}|S)zO
    Get the location of a cached requirements file; caching if necessary.
    zcp.list_masterFzcp.is_cachedz
cp.cache_filezcp.hash_file)rr�url�parse�__salt__)�requirements�saltenv�req_fileZsenv�cached_requirementsrrr�_get_cached_requirements�s�r<cCs^|std��tj�|�r+tjj��rtj�|dd�}ntj�|dd�}tj�	|�r+|Std��)z0
    Return the path to the activate binary
    z"Could not find a `activate` binaryr%zactivate.batr$Zactivate)
rrrr0rrrrr'r1)rZactivate_binrrr�_get_env_activate�sr=cs�t�d|�tjj�|��}tjj�|���}Wd�n1s!wYt	�
d|�}t�|�}t
j�|���fdd�|D�}|S)Nz_find_req -- link = %s�csg|]	}tj��|��qSr)rrr')�.0�d��	base_pathrr�
<listcomp>sz_find_req.<locals>.<listcomp>)r+�inforr�files�fopen�stringutils�
to_unicode�read�rex_pip_reqs_comment�sub�rex_pip_chain_read�findallrrr)�linkZfh_linkZreqs_contentZchild_linksrrAr�	_find_req�s�
rOcCs>g}t|t�r
|g}|D]}|�|�|�tt|���q|S)z�
    Return an array of requirements file paths that can be used to complete
    the no_chown==False && user != None conundrum
    )�
isinstancer-�appendr&�_resolve_requirements_chainrO)r8�chainr:rrrrR
s

rRcCs�g}|du�r;t|t�rdd�|�d�D�}n	t|t�s td��d}|D�]}t�d|�|�d�rIt||�}|sGdd	�	|�d
�}	d|	fS|}|�r"|sRt
��}td||d�t
jj��ritd||d
d�d}
|
sttj�tj�}
t�d||�|dur�|}|}tj�|�}
tj�|
�}tj�|�}t�d||||�t�|�t|�}t�|
�t�d|�|D]m}tj�|�s�tj�||�}t�d|||�tj�|tj�|��}t�d|�t�d|�tj�|�}tj�|�s�tj|dd�td||d�tj�|��st�d||�td||�t�d||�td||d�q�|�r,tj�||�n|}|�d|g�q$|� |�t�d|�|dfS)z+
    Process the requirements argument
    NcS�g|]}|���qSr��strip)r?�rrrrrC'�z)_process_requirements.<locals>.<listcomp>�,z%requirements must be a string or listzTREQ IS: %szsalt://Fz$pip requirements file '{}' not found)�result�commentz
file.chownzdacl.set_permissionsZread_execute)Zobj_nameZ	principalZpermissionsz;_process_requirements from directory, %s -- requirement: %sz'
	cwd: %s -> %s
	requirement: %s -> %s
zrequest files: %szTREQ N CWD: %s -- %s -- for %szS: %szT: %si�)�modezCopying %s to %sz	file.copyz9Changing ownership of requirements file '%s' to user '%s'z
--requirementzCLEANUP_REQUIREMENTS: %s)!rPr-�splitr�	TypeErrorr+r,�
startswithr<�format�tempfileZmkdtempr7rrrrZ	__utils__rr�abspath�curdirrDrr�chdirrR�isabsr'�exists�makedirsr&rQ)r8�cmdrr9�user�cleanup_requirementsZtreq�requirementr;r(Zcurrent_directoryrW�cZrequirement_abspathZreqsr:�target_pathZtarget_baseZreq_argsrrr�_process_requirementss�





�����

�
rncCshi}|r2t|t�r*|��D]\}}t|t�st|�}t|t�s#t|�}|||<q
|Std|�d���|S)Nz	env_vars z is not a dictionary)rP�dict�itemsr-r)�env_varsr(�key�valrrr�_format_env_vars�s



�rtF�basec-G
Ks�	t||�}t|�}.|.�d�t||.||$|d�\}/}0|0r|0St|||d�}1|rPd}2d}3tjjj|1d|2d�}4tjjj|1d|3d�}5|4sB|5rKt	�
d	|2|3|1�n|.�d
�|r|d}2d}3tjjj|1d|2d�}4tjjj|1d|3d�}5|4sn|5rwt	�
d|2|3|1�n|.�d�|+r�d
}2tjjj|1d|2d�}4|4r�t	�
d|2|1�nt|+t�r�d�
|+�}+|.�d|+g�|r�tj�|�r�td|�d���tj�|�s�tj�|�}6tj�|6�s�td|�d|6�d���t�|6tj�s�td|�d|6�d���nt�|tj�s�td|�d���|.�d|g�t}7|�r|.�d|g�n5|du�r=|7�d��r=|7�d��r=|7�d��r.|7�d��r.djdji|7��}8nd jdji|7��}8|.�d|8g�|�rhzt|t��rKtd!��t|�Wnt�y`td|�d"���w|.�d#|g�|	�r�t|	t��r{d$d%�|	�d�D�}	|	D]"}9tjj� |9t!��s�tj�|9��s�t"d|9�d&���|.�d'|9g��q}|�r�|
�s�|�r�t"d(��|
�r�tjj� |
t!��s�t"d|
�d)���|.�d*|
g�|�r�tjj� |t!��s�t"d|�d)���|.�d+|g�|�r�|.�d,�|
�r-tjjj|1d-d
d��r�t"d.��t|
t��r
d/d%�|
�d�D�}
|.�d0�|
D]}:|:�#d1��s$t"d|:�d)���|.�d2|:g��q|,�r6|.�d3g�|�r@|.�d4|g�tj$�d5d6�};|d6u�rS|;d6u�rS|;}|�r]|.�d7|g�|�rg|.�d8|g�|�sm|*�r�|.�tjjj|1d-d9d��r|d:nd;|�p�|*g�|�r�|.�d<|g�|�r�|.�d=�|�r�|.�d>�|�r�|.�d?�|�r�|�%�d@v�r�t"dA�|���|.�dB|g�|�r�|.�dC�|�r�|.�dD�|�r�|.�dE�|(�r�|.�dF�|�r�|1}<tjjj|<d-dd��r�|.�dG�|�r�|.�dH|g�|�rt|t��rdId%�|�d�D�}|D]
}=|.�dJ|=g��q|�r=t|t��r0dKd%�|�d�D�}|D]
}=|.�dL|=g��q2|�r�t|t��sizdMd%�|�d�D�}Wnt&�yhdNd%�t|��d�D�}Ynwtjj'�(tjj'�)|��}|.�dOd%�|D��nt*||g��s�dPdQdR�S|�r�t+�,dS�}>t|t��r�dTd%�|�d�D�}|D]'}?|?dUk�s�|?�#dV��s�|>�-|?�}@|@�r�|@�.dW��s�t"dX��|.�dY|?g��q�| �r�|.�dZ�|!�r�t|!t��r�d[d%�|!�d�D�}!|!D]
}A|.�d\|Ag��q�|"�rt|"t��r	d]d%�|"�d�D�}"|"D]
}A|.�d^|Ag��q|#�r|.�d_�|'�r(|.�d`|'g�|)�rZ|)D],}Bt|Bt/��rS|B�0�\}C}Dt|Dt/tf��rJt1da|C����|.�|C|Dg��q-|.�|B��q-t/|$|&|db�}E|-�ri|E�2|-�|%�rw|E�3dci��2t4|%��zH|�r||Edd<|�r�tj�|��r�||E�3dci�de<t	�5df|.|E�t6dg|.fdhdi|E��Wt7|�did%�|/D�D]}Ftj�|F��r�t8�9|F��q�St7|�did%�|/D�D]}Ftj�|F��r�t8�9|F��q�w)kaZ
    Install packages with pip

    Install packages individually or from a pip requirements file. Install
    packages globally or to a virtualenv.

    pkgs
        Comma separated list of packages to install

    requirements
        Path to requirements

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

        .. note::

            For Windows, if the pip module is being used to upgrade the pip
            package, bin_env should be the path to the virtualenv or to the
            python binary that should be used.  The pip command is unable to
            upgrade itself in Windows.

    use_wheel
        Prefer wheel archives (requires pip>=1.4)

    no_use_wheel
        Force to not use wheel archives (requires pip>=1.4,<10.0.0)

    no_binary
        Force to not use binary packages (requires pip >= 7.0.0)
        Accepts either :all: to disable all binary packages, :none: to empty the set,
        or one or more package names with commas between them

    log
        Log file where a complete (maximum verbosity) record will be kept.
        If this file doesn't exist and the parent directory is writeable,
        it will be created.

    proxy
        Specify a proxy in the form ``user:passwd@proxy.server:port``. Note
        that the ``user:password@`` is optional and required only if you are
        behind an authenticated proxy. If you provide
        ``user@proxy.server:port`` then you will be prompted for a password.

        .. note::
            If the Minion has a globaly configured proxy - it will be used
            even if no proxy was set here. To explicitly disable proxy for pip
            you should pass ``False`` as a value.

    timeout
        Set the socket timeout (default 15 seconds)

    editable
        install something editable (e.g.
        ``git+https://github.com/worldcompany/djangoembed.git#egg=djangoembed``)

    find_links
        URL to search for packages

    index_url
        Base URL of Python Package Index

    extra_index_url
        Extra URLs of package indexes to use in addition to ``index_url``

    no_index
        Ignore package index

    mirrors
        Specific mirror URL(s) to query (automatically adds --use-mirrors)

        .. warning::

            This option has been deprecated and removed in pip version 7.0.0.
            Please use ``index_url`` and/or ``extra_index_url`` instead.

    build
        Unpack packages into ``build`` dir

    target
        Install packages into ``target`` dir

    download
        Download packages into ``download`` instead of installing them

    download_cache | cache_dir
        Cache downloaded packages in ``download_cache`` or ``cache_dir`` dir

    source
        Check out ``editable`` packages into ``source`` dir

    upgrade
        Upgrade all packages to the newest available version

    force_reinstall
        When upgrading, reinstall all packages even if they are already
        up-to-date.

    ignore_installed
        Ignore the installed packages (reinstalling instead)

    exists_action
        Default action when a path already exists: (s)witch, (i)gnore, (w)ipe,
        (b)ackup

    no_deps
        Ignore package dependencies

    no_install
        Download and unpack all packages, but don't actually install them

    no_download
        Don't download any packages, just install the ones already downloaded
        (completes an install run with ``--no-install``)

    install_options
        Extra arguments to be supplied to the setup.py install command (e.g.
        like ``--install-option='--install-scripts=/usr/local/bin'``).  Use
        multiple --install-option options to pass multiple options to setup.py
        install. If you are using an option with a directory path, be sure to
        use absolute path.

    global_options
        Extra global options to be supplied to the setup.py call before the
        install command.

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    pre_releases
        Include pre-releases in the available versions

    cert
        Provide a path to an alternate CA bundle

    allow_all_external
        Allow the installation of all externally hosted files

    allow_external
        Allow the installation of externally hosted files (comma separated
        list)

    allow_unverified
        Allow the installation of insecure and unverifiable files (comma
        separated list)

    process_dependency_links
        Enable the processing of dependency links

    env_vars
        Set environment variables that some builds will depend on. For example,
        a Python C-module may have a Makefile that needs INCLUDE_PATH set to
        pick up a header file while compiling.  This must be in the form of a
        dictionary or a mapping.

        Example:

        .. code-block:: bash

            salt '*' pip.install django_app env_vars="{'CUSTOM_PATH': '/opt/django_app'}"

    trusted_host
        Mark this host as trusted, even though it does not have valid or any
        HTTPS.

    use_vt
        Use VT terminal emulation (see output while installing)

    no_cache_dir
        Disable the cache.

    extra_args
        pip keyword and positional arguments not yet implemented in salt

        .. code-block:: yaml

            salt '*' pip.install pandas extra_args="[{'--latest-pip-kwarg':'param'}, '--latest-pip-arg']"

        .. warning::

            If unsupported options are passed here that are not supported in a
            minion's version of pip, a `No such option error` will be thrown.

    Will be translated into the following pip command:

    .. code-block:: bash

        pip install pandas --latest-pip-kwarg param --latest-pip-arg

    disable_version_check
        Pip may periodically check PyPI to determine whether a new version of
        pip is available to download. Passing True for this option disables
        that check.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.install <package name>,<package2 name>
        salt '*' pip.install requirements=/path/to/requirements.txt
        salt '*' pip.install <package name> bin_env=/path/to/virtualenv
        salt '*' pip.install <package name> bin_env=/path/to/pip_bin

    Complicated CLI Example:

    .. code-block:: bash

        salt '*' pip.install markdown,django                 editable=git+https://github.com/worldcompany/djangoembed.git#egg=djangoembed upgrade=True no_deps=True

    �install)r8rhrr9ri�riz1.4z9.0.3�<�Zver1ZoperZver2�>z�The --use-wheel option is only supported in pip between %s and %s. The version of pip detected is %s. This option will be ignored.z--use-wheelz�The --no-use-wheel option is only supported in pip between %s and %s. The version of pip detected is %s. This option will be ignored.z--no-use-wheelz7.0.0z}The --no-binary option is only supported in pip %s and newer. The version of pip detected is %s. This option will be ignored.rYz--no-binary�'z(' is a directory. Use --log path_to_filezTrying to create 'z' but parent directory 'z' does not exist.z' is not writeable.�' is not writeable�--log�--proxyF�
proxy_host�
proxy_port�proxy_username�proxy_password�Bhttp://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}� http://{proxy_host}:{proxy_port}�Timeout cannot be a float�,' is not a valid timeout, must be an integer�	--timeoutcSrTrrU)r?�lrrrrC rXzinstall.<locals>.<listcomp>z' is not a valid URL or pathz--find-linkszI'no_index' and ('index_url' or 'extra_index_url') are mutually exclusive.�' is not a valid URL�--index-url�--extra-index-urlz
--no-index�>=z[pip >= 7.0.0 does not support mirror argument: use index_url and/or extra_index_url insteadcSrTrrU)r?�mrrrrCDrXz
--use-mirrorszhttp://z	--mirrorsz--disable-pip-version-checkz--buildZVENV_PIP_TARGETNz--targetz
--downloadz6.0z--cache-dirz--download-cachez--sourcez	--upgradez--force-reinstallz--ignore-installed)�s�i�w�bzXThe exists_action pip option only supports the values s, i, w, and b. '{}' is not valid.z--exists-actionz	--no-depsz--no-installz
--no-downloadz--no-cache-dirz--prez--certcSrTrrU)r?ZgorrrrC�rXz--global-optioncSrTrrU)r?�iorrrrC�rXz--install-optioncSrTrrU�r?�prrrrC�rXcSrTrrUr�rrrrC�rXcSsg|]}|�dd��qS)�;rY)�replacer�rrrrC��rzNo packages to install.)�retcode�stdoutz(?:#|#.*?&)egg=([^&]*)cSrTrrU)r?�errrrC�rXr)zfile://�/�z)You must specify an egg for this editablez
--editablez--allow-all-externalcSrTrrUr�rrrrC�rXz--allow-externalcSrTrrUr�rrrrC�rXz--allow-unverifiedz--process-dependency-linksz--trusted-hostzToo many levels in: )r9�use_vt�runas�envr�VIRTUAL_ENVz8TRY BLOCK: end of pip.install -- cmd: %s, cmd_kwargs: %s�cmd.run_all�python_shellcSsg|]}|dur|�qS�Nr)r?ZcrrrrrCr�r):rr4rQrn�versionrr�versions�comparer+�errorrPrr'r&rrr0�OSErrorrfrr2�W_OK�__opts__�getr`�float�
ValueError�intr-r]r5�validate�VALID_PROTOSrr_�environ�lower�AttributeError�dataZ	stringifyZdecode_list�any�re�compile�search�groupro�popitemr^�update�
setdefaultrtr,r7r�shutil�rmtree)G�pkgsr8rZ	use_wheelZno_use_wheel�log�proxy�timeoutZeditableZ
find_links�	index_url�extra_index_urlZno_indexZmirrors�build�target�downloadZdownload_cache�source�upgradeZforce_reinstall�ignore_installedZ
exists_actionZno_depsZ
no_installZno_download�global_options�install_optionsrirZpre_releases�certZallow_all_externalZallow_externalZallow_unverifiedZprocess_dependency_linksr9rqr�Ztrusted_hostZno_cache_dir�
extra_argsZ	cache_dirZ	no_binaryZdisable_version_check�kwargsrhrjr��cur_version�min_versionZmax_versionZtoo_lowZtoo_high�parent�config�http_proxy_urlrNZmirrorZ
target_env�pip_version�optZ	egg_match�entry�match�pkg�argrrrs�
cmd_kwargsZtempdirrrrrv�s



����
	���
	��

���"���
��
�
����



�




�


�


�
���
��rvc
Cs�t||�}t|�}
|
�ddg�t||
|||d�\}}|r|S|r@ztj�|�Wnty8td|�d���w|
�d|g�t}
|rL|
�d|g�n0|dur||
�	d	�r||
�	d
�r||
�	d�rm|
�	d�rmd
j
di|
��}ndj
di|
��}|
�d|g�|r�zt|t�r�t
d��t|�Wnt
y�t
d|�d���w|
�d|g�|r�t|t�r�dd�|�d�D�}|r�|D]@}tjj�|��/}|D]$}tjj�|�}z|�d�\}}||vr�|�|�Wq�t
y�Yq�wWd�n1s�wYq�|
�|�td||||	d�}|�rtj�|��rd|i|d<z,td|
fi|��Wt|�|D]}|�rBzt�|�W�q)t�yAY�q)w�q)St|�|D]}|�rdzt�|�W�qKt�ycY�qKw�qKw)av
    Uninstall packages individually or from a pip requirements file

    pkgs
        comma separated list of packages to install

    requirements
        Path to requirements file

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    log
        Log file where a complete (maximum verbosity) record will be kept

    proxy
        Specify a proxy in the format ``user:passwd@proxy.server:port``. Note
        that the ``user:password@`` is optional and required only if you are
        behind an authenticated proxy.  If you provide
        ``user@proxy.server:port`` then you will be prompted for a password.

        .. note::
            If the Minion has a globaly configured proxy - it will be used
            even if no proxy was set here. To explicitly disable proxy for pip
            you should pass ``False`` as a value.

    timeout
        Set the socket timeout (default 15 seconds)

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    use_vt
        Use VT terminal emulation (see output while installing)

    CLI Example:

    .. code-block:: bash

        salt '*' pip.uninstall <package name>,<package2 name>
        salt '*' pip.uninstall requirements=/path/to/requirements.txt
        salt '*' pip.uninstall <package name> bin_env=/path/to/virtualenv
        salt '*' pip.uninstall <package name> bin_env=/path/to/pip_bin
    �	uninstallz-y)r8rhr9rirr{r|r}r~Frr�r�r�r�r�r�r�r�cSrTrrUr�rrrrCzrXzuninstall.<locals>.<listcomp>rY�==N)r�r�rr9r�r�r�r�r)rr4r&rnrrrfr�r�r�r`rPr�r�r�r-r]rrrErFrGrH�removeror0r7r)r�r8rr�r�r�rirr9r�rhrjr�r�r�rkZrq_ZreqZreq_pkg�_r�rrrr�
s�
?

���
�

�����
	
��������r�cKs�t||�}t|�}|�d�d}t||�}tjjj|d|d�r't�	d||�n|�d�t
|||dd�}	|r>|	jdi|��|rLtj
�|�rLd	|i|	d
<|rY|	�d
i��t|��td|fi|	��}
|
drot|
d
|
d��|
d��S)a4
    Return a list of installed packages either globally or in the specified
    virtualenv

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    .. note::
        If the version of pip available is older than 8.0.3, the list will not
        include the packages ``pip``, ``wheel``, ``setuptools``, or
        ``distribute`` even if they are installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.freeze bin_env=/home/code/path/to/virtualenv
    �freezez8.0.3rxryz�The version of pip installed is %s, which is older than %s. The packages pip, wheel, setuptools, and distribute will not be included in the output of pip.freezez--allF)r�rr�r�r�r�r�r��stderr�rDr�Nr)rr4rQr�rrr�r�r+�warningror�rrr0r�rtr7r�
splitlines)rrirr�rqr�rhr�r�r�rZrrrr��s.


�
r�c
Ks�t||�}i}|dusd�|�rt||�|d<td||||d�|��D]�}|�d�s/|�d�r0q#|�d�r6q#|�d�r~|�d�d	}d
|vrN|�d
�\}}	ngt|�d��dkrf|�d�d
}	|�d�d	}nOt|�d��dkr}|�d�d
}	|�d�d	}n7t|�d��dkr�|�d�d
}	|�d�d	}nt|�d��dkr�|�d�d
}	|�d�d	}nt�d|�q#|r�|	���|���r�|||	<q#|||	<q#|S)aa
    .. versionadded:: 3006.0

    Filter list of installed apps from ``freeze`` and check to see if
    ``prefix`` exists in the list of packages installed.

    .. note::

        If the version of pip available is older than 8.0.3, the packages
        ``wheel``, ``setuptools``, and ``distribute`` will not be reported by
        this function even if they are installed. Unlike :py:func:`pip.freeze
        <salt.modules.pip.freeze>`, this function always reports the version of
        pip which is installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.list_freeze_parse salt
    Nr
)rrirrqz-f�#z-e hg+not trustz-ez-e r�z#egg=z===�rr�zCan't parse line '%s'r)	rr_r�r�r]�lenr+r�r�)
�prefixrrirrqr��packages�line�version_�namerrr�list_freeze_parse�sL
�
�

��
r�cKshi}t||�}t|||d�}d}tjjj|d|d�r'td|||||d�|��St|�}	|	�ddg�t	||dd	�}
|rC|
j
di|��|rQtj�
|�rQd
|i|
d<|r^|
�di��
t|��td|	fi|
��}|d
rtt|d|d��z
tjjj|ddd�}Wn
ty�td|d��w|D] }
|r�|
d���|���r�|
d||
d<q�|
d||
d<q�|S)a�
    .. versionchanged:: 3006.0

    Output list of installed apps from ``pip list`` in JSON format and check to
    see if ``prefix`` exists in the list of packages installed.

    .. note::

        If the version of pip available is older than 9.0.0, parsing the
        ``freeze`` function output will be used to determine the name and
        version of installed modules.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.list salt
    rw�9.0rxry)r�rrirrqr�
--format=jsonF�rr�r�r�r�r�r�r�r�r���strict�Invalid JSONr�r�Nr)rr�rrr�r�r�r4r&ror�rrr0r�rtr7r�json�loadsr�r�r_)r�rrirrqr�r�r�r�rhr�rZr�r�rrrrsL
��	��cCs�t||�}d}|dur|�d|��}|tvrt|St|�dd�}|�d�td|||dd�}|dr9td	��z
t�d
|d��d�}Wnt	yQd}Ynw|t|<|S)
a�
    .. versionadded:: 0.17.0

    Returns the version of pip. Use ``bin_env`` to specify the path to a
    virtualenv and get the version of pip in that virtualenv.

    If unable to detect the pip version, returns ``None``.

    .. versionchanged:: 3001.1
        The ``user`` parameter was added, to allow specifying the user who runs
        the version command.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.version

    rNrz	--versionr�Fr�r�zCould not find a `pip` binaryz
^pip (\S+)r�r�)
rrr4rQr7rr�r�r�r�)rrrirrhr(r�rrrr�as$

�r�cCs�t||�}t|�}|�ddg�t|||d�}d}tjjj|d|d�r(|�d�t	||d�}|r<t
j�|�r<d	|i|d
<t
d|fi|��}|drRt|d
|d��i}tjjj|ddd�r�tjjj|ddd�rst�d�t�d�}	n
t�d�t�d�}	|d��D]}
|	�|
�}|r�|��\}}
nt�d|
�q�|
||<q�|St�d�z
tjjj|ddd�}Wn
ty�td|d��w|D]}d�|d|d�||d<q�|S) z�
    Check whether or not an upgrade is available for all packages

    CLI Example:

    .. code-block:: bash

        salt '*' pip.list_upgrades
    rz
--outdatedrwr�r�ryr�)rr�r�r�r�r�r�r�rxz9.0.0z8.0.0zpip module: Old output formatz(\S*)\s+\(.*Latest:\s+(.*)\)zpip module: New output formatz#(\S*)\s+\(.*\)\s+-\s+Latest:\s+(.*)r�zCan't parse line %rzpip module: JSON output formatFr�r�z{} [{}]Zlatest_versionZlatest_filetyper�)rr4r&r�rrr�r�rQrorrr0r7rr+r,r�r�r�r��groupsr�r�r�r�r`)rrirrhr�r�r�rZr��patr�r�r�r�r�r�rrr�
list_upgrades�sN



	



���r�cCs>t||�}t||||d�}|D]
}|��|��krdSqdS)a

    .. versionadded:: 2018.3.0
    .. versionchanged:: 3006.0

    Filter list of installed modules and return True if ``pkgname`` exists in
    the list of packages installed.

    CLI Example:

    .. code-block:: bash

        salt '*' pip.is_installed salt
    )r�rrirTF)rrr�)Zpkgnamerrirr�r�rrr�is_installed�s
�r�cCst||�}|t|||d�vS)z�
    .. versionadded:: 2015.5.0

    Check whether or not an upgrade is available for a given package

    CLI Example:

    .. code-block:: bash

        salt '*' pip.upgrade_available <package name>
    �rrir)rr�)r�rrirrrr�upgrade_available�s

r�cCst||�}iddd�}t|�}|�ddg�t|||d�}t|||d�}|r2tj�|�r2d|i|d	<d
}t|||d�D]0}	|	dkrHt	j
j��rHq;t
d||	gfi|��}
|
d
dkr]d}d|
vrk|d|
d7<q;|rrd
|d<t|�t|||d�}t	j
j�||�|d<|S)a�
    .. versionadded:: 2015.5.0

    Upgrades outdated pip packages.

    .. note::
        On Windows you can't update salt from pip using salt, so salt will be
        skipped

    Returns a dict containing the changes.

        {'<package>':  {'old': '<old-version>',
                        'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pip.upgrade
    Tr>)�changesrZr[rvz-Ur�)rr�r�r�r�Frr�r�rr�r[rZr�)rr4r&rrorrr0r�rrrrr7rr�Z
compare_dicts)rrirr�r(rh�oldr��errorsr�rZ�newrrrr�s8
��r�c	s�t||�}t|�}	t|||d�}
tjjj|
ddd�r(t�d�}|	�	dd|g�ntjjj|
ddd�r7|	�
d	�t�d
�}|	�	d|�d�g�|r_tjj�|t
�sXtd
|�d���|	�	d|g�|rxtjj�|t
�sqtd
|�d���|	�	d|g�t||ddd�}|r�tj�|�r�d|i|d<td|	fi|��}
g}|s�|�
d�|s�|�
d�|s�|�
d�|r�t�d�d�|����nt�d��g}|
d��D]!}|�|�}|r�fdd�|�d ��d!�D�}|jtjd"�nq�|s�d#S|S)$a�
    .. versionadded:: 2017.7.3

    List all available versions of a pip package

    pkg
        The package to check

    bin_env
        Path to pip (or to a virtualenv). This can be used to specify the path
        to the pip to use when more than one Python release is installed (e.g.
        ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a directory path is
        specified, it is assumed to be a virtualenv.

    include_alpha
        Include alpha versions in the list

    include_beta
        Include beta versions in the list

    include_rc
        Include release candidates versions in the list

    user
        The user under which to run pip

    cwd
        Directory from which to run pip

    index_url
        Base URL of Python Package Index
        .. versionadded:: 2019.2.0

    extra_index_url
        Additional URL of Python Package Index
        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

       salt '*' pip.list_all_versions <package name>
    )rrrir�z21.2ryz\s*Available versions: (.*)�indexr�z20.3z --use-deprecated=legacy-resolverz5\s*Could not find a version.* \(from versions: (.*)\)rvz
==versionsr{r�r�r��quietT)rr�Zoutput_loglevel�redirect_stderrr�r�r��ar��rcz^((?!{}).)*$�|r>r�csg|]}|r��|�r|�qSr)r�)r?�v�ZexcludesrrrC�s���z%list_all_versions.<locals>.<listcomp>r�z, )rrN)rr4r�rrr�r�r�r�r&rQr5r�r�rrorrr0r7r`r'r�r�r�r]�sort�
pkg_resourcesZ
parse_version)r�rZ
include_alphaZinclude_betaZ
include_rcrirr�r�rhr�Zregexr�rZZfilteredr�r�r�rrr�list_all_versions>s^
6


�





��r
r�)-NNNFFNNNNNNNFNNNNNNFFFNFFFNNNNFNFNNFruNFNFNNNF)
NNNNNNNNruF)NNNFN)NNNNN)NNN)NNNF)NFFFNNNN)3�__doc__�loggingrr�r�r!rar	Zsalt.utils.datarZsalt.utils.filesZsalt.utils.jsonZsalt.utils.localesZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.urlZsalt.utils.versionsZsalt.exceptionsrr�	getLogger�__name__r+Z__func_alias__r�r��	MULTILINErLrJr
rrr"r4r<r=rOrRrnrtrvr�r�r�rr�r�r�r�r�r
rrrr�<module>s�O
	


	;s
�q
�
?
�
F
C
-
M

;�