관리-도구
편집 파일: pip.cpython-39.pyc
a �)g�w � @ s� d dl mZmZmZ eZdZdZdZd dl Z d dl Z d dlZd dlZd dl Z d dlZd dlZd dlZd dlmZ dZzd dlmZ dZW n ey� d Ze�� ZY n0 d d lmZ d dlmZmZmZ d dlm Z d d l!m"Z" ddd�Z#e �$d�Z%e j&e j'e j(e j)e j*e j+e j&d�Z,dd� Z-dd� Z.dd� Z/dd� Z0dd� Z1dd� Z2d.dd �Z3d!d"� Z4d#d$� Z5d/d%d&�Z6d'd(� Z7G d)d*� d*�Z8d+d,� Z9e:d-k�r�e9� dS )0� )�absolute_import�division�print_functiona� --- module: pip short_description: Manages Python library dependencies description: - "Manage Python library dependencies. To use this module, one of the following keys is required: C(name) or C(requirements)." version_added: "0.7" options: name: description: - The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package. - This can be a list (since 2.2) and contain version specifiers (since 2.7). type: list elements: str version: description: - The version number to install of the Python library specified in the I(name) parameter. type: str requirements: description: - The path to a pip requirements file, which should be local to the remote system. File can be specified as a relative path if using the chdir option. type: str virtualenv: description: - An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv. type: path virtualenv_site_packages: description: - Whether the virtual environment will inherit packages from the global site-packages directory. Note that if this setting is changed on an already existing virtual environment it will not have any effect, the environment must be deleted and newly created. type: bool default: "no" version_added: "1.0" virtualenv_command: description: - The command or a pathname to the command to create the virtual environment with. For example C(pyvenv), C(virtualenv), C(virtualenv2), C(~/bin/virtualenv), C(/usr/local/bin/virtualenv). type: path default: virtualenv version_added: "1.1" virtualenv_python: description: - The Python executable used for creating the virtual environment. For example C(python3.5), C(python2.7). When not specified, the Python version used to run the ansible module is used. This parameter should not be used when C(virtualenv_command) is using C(pyvenv) or the C(-m venv) module. type: str version_added: "2.0" state: description: - The state of module - The 'forcereinstall' option is only available in Ansible 2.1 and above. type: str choices: [ absent, forcereinstall, latest, present ] default: present extra_args: description: - Extra arguments passed to pip. type: str version_added: "1.0" editable: description: - Pass the editable flag. type: bool default: 'no' version_added: "2.0" chdir: description: - cd into this directory before running the command type: path version_added: "1.3" executable: description: - The explicit executable or pathname for the pip executable, if different from the Ansible Python interpreter. For example C(pip3.3), if there are both Python 2.7 and 3.3 installations in the system and you want to run pip for the Python 3.3 installation. - Mutually exclusive with I(virtualenv) (added in 2.1). - Does not affect the Ansible Python interpreter. - The setuptools package must be installed for both the Ansible Python interpreter and for the version of Python specified by this option. type: path version_added: "1.3" umask: description: - The system umask to apply before installing the pip package. This is useful, for example, when installing on systems that have a very restrictive umask by default (e.g., "0077") and you want to pip install packages which are to be used by all users. Note that this requires you to specify desired umask mode as an octal string, (e.g., "0022"). type: str version_added: "2.1" extends_documentation_fragment: - action_common_attributes attributes: check_mode: support: full diff_mode: support: none platform: platforms: posix notes: - Python installations marked externally-managed (as defined by PEP668) cannot be updated by pip versions >= 23.0.1 without the use of a virtual environment or setting the environment variable ``PIP_BREAK_SYSTEM_PACKAGES=1``. - The virtualenv (U(http://www.virtualenv.org/)) must be installed on the remote host if the virtualenv parameter is specified and the virtualenv needs to be created. - Although it executes using the Ansible Python interpreter, the pip module shells out to run the actual pip command, so it can use any pip version you specify with I(executable). By default, it uses the pip version for the Ansible Python interpreter. For example, pip3 on python 3, and pip2 or pip on python 2. - The interpreter used by Ansible (see R(ansible_python_interpreter, ansible_python_interpreter)) requires the setuptools package, regardless of the version of pip set with the I(executable) option. requirements: - pip - virtualenv - setuptools author: - Matt Wright (@mattupstate) ad - name: Install bottle python package ansible.builtin.pip: name: bottle - name: Install bottle python package on version 0.11 ansible.builtin.pip: name: bottle==0.11 - name: Install bottle python package with version specifiers ansible.builtin.pip: name: bottle>0.10,<0.20,!=0.11 - name: Install multi python packages with version specifiers ansible.builtin.pip: name: - django>1.11.0,<1.12.0 - bottle>0.10,<0.20,!=0.11 - name: Install python package using a proxy ansible.builtin.pip: name: six environment: http_proxy: 'http://127.0.0.1:8080' https_proxy: 'https://127.0.0.1:8080' # You do not have to supply '-e' option in extra_args - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+,svn+) ansible.builtin.pip: name: svn+http://myrepo/svn/MyApp#egg=MyApp - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+) ansible.builtin.pip: name: git+http://myrepo/app/MyApp - name: Install MyApp from local tarball ansible.builtin.pip: name: file:///path/to/MyApp.tar.gz - name: Install bottle into the specified (virtualenv), inheriting none of the globally installed modules ansible.builtin.pip: name: bottle virtualenv: /my_app/venv - name: Install bottle into the specified (virtualenv), inheriting globally installed modules ansible.builtin.pip: name: bottle virtualenv: /my_app/venv virtualenv_site_packages: yes - name: Install bottle into the specified (virtualenv), using Python 2.7 ansible.builtin.pip: name: bottle virtualenv: /my_app/venv virtualenv_command: virtualenv-2.7 - name: Install bottle within a user home directory ansible.builtin.pip: name: bottle extra_args: --user - name: Install specified python requirements ansible.builtin.pip: requirements: /my_app/requirements.txt - name: Install specified python requirements in indicated (virtualenv) ansible.builtin.pip: requirements: /my_app/requirements.txt virtualenv: /my_app/venv - name: Install specified python requirements and custom Index URL ansible.builtin.pip: requirements: /my_app/requirements.txt extra_args: -i https://example.com/pypi/simple - name: Install specified python requirements offline from a local directory with downloaded packages ansible.builtin.pip: requirements: /my_app/requirements.txt extra_args: "--no-index --find-links=file:///my_downloaded_packages_dir" - name: Install bottle for Python 3.3 specifically, using the 'pip3.3' executable ansible.builtin.pip: name: bottle executable: pip3.3 - name: Install bottle, forcing reinstallation if it's already installed ansible.builtin.pip: name: bottle state: forcereinstall - name: Install bottle while ensuring the umask is 0022 (to ensure other users can use it) ansible.builtin.pip: name: bottle umask: "0022" become: True a� cmd: description: pip command used by the module returned: success type: str sample: pip2 install ansible six name: description: list of python modules targeted by pip returned: success type: list sample: ['ansible', 'six'] requirements: description: Path to the requirements file returned: success, if a requirements file was provided type: str sample: "/srv/git/project/requirements.txt" version: description: Version of the package specified in 'name' returned: success, if a name and version were provided type: str sample: "2.5.1" virtualenv: description: Path to the virtualenv returned: success, if a virtualenv path was provided type: str sample: "/tmp/virtualenv" N)�LooseVersion)�RequirementTF�� to_native)� AnsibleModule� is_executable�missing_required_lib)�get_best_parsable_locale)�PY3z0import setuptools; print(setuptools.__version__)zJimport pkg_resources; print(pkg_resources.get_distribution("pip").version)�� setuptools�pipz(svn|git|hg|bzr)\+)z>=z<=�>�<�==z!=z~=c C s t �t| �S )z(Test whether a name is a vcs url or not.)�re�match�_VCS_RE��name� r �7/usr/lib/python3.9/site-packages/ansible/modules/pip.py�_is_vcs_url3 s r c C s | � � �tt�� �� S )z?Test whether the name is a package name or a version specifier.)�lstrip� startswith�tuple�op_dict�keysr r r r �_is_package_name8 s r! c C s� g }| D ]}|� |�d�� q|} g }g }d}| D ]N}t|�rZ|sZ|rV|�d�|�� g }d|v rfd}|rvd|v rvd}|�|� q2|�d�|�� |S )a� Recover package names as list from user's raw input. :input: a mixed and invalid list of names or version specifiers :return: a list of valid package name eg. input: ['django>1.11.1', '<1.11.3', 'ipaddress', 'simpleproject>1.1.0', '<2.0.0'] return: ['django>1.11.1,<1.11.3', 'ipaddress', 'simpleproject>1.1.0,<2.0.0'] input: ['django>1.11.1,<1.11.3,ipaddress', 'simpleproject>1.1.0,<2.0.0'] return: ['django>1.11.1,<1.11.3', 'ipaddress', 'simpleproject>1.1.0,<2.0.0'] �,F�[T�])�extend�splitr! �append�join)�names�tmpZone_lineZ name_partsZ package_namesZin_bracketsr r r r �_recover_package_name= s&