a ì)gþwã@sœddlmZmZmZeZdZdZdZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZdZzddlmZdZWney¦d Ze ¡ZYn0dd lmZdd lmZmZmZdd lm Z dd 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(„Z7Gd)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~=cCs 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_url3srcCs| ¡ tt ¡ƒ¡ S)z?Test whether the name is a package name or a version specifier.)ÚlstripÚ startswithÚtupleÚop_dictÚkeysrrrrÚ_is_package_name8sr!cCs–g}|D]}| | d¡¡q|}g}g}d}|D]N}t|ƒrZ|sZ|rV| d |¡¡g}d|vrfd}|rvd|vrvd}| |¡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_namesZ in_bracketsrrrrÚ_recover_package_name=s&   r+cCsV|d}| |¡\}}}|dkr8|jd|||fd�| ¡ ¡}dd„|Dƒ}|S)Nz --helprz Could not get output from %s: %s©ÚmsgcSsg|]}| d¡r|‘qS)z--©r)Ú.0ÚxrrrÚ ióz$_get_cmd_options..)Ú run_commandÚ fail_jsonÚstripr&)ÚmoduleÚcmdZthiscmdÚrcÚstdoutÚstderrÚwordsZ cmd_optionsrrrÚ_get_cmd_optionsbs r<c Cs‚|ddg}t|ƒ}|||dœ}|j|||d�\}}}|dkrr|dg}|j||d�\}}}|dkrrt||||ƒd |¡||fS) z.Return results of pip command to get packages.Úlistz--format=freeze)ÚLANGÚLC_ALLÚ LC_MESSAGES)ÚcwdZenviron_updaterZfreeze©rAú )r r3Ú_failr() r6rÚchdirZcommandÚlocaleZlang_envr8ÚoutÚerrrrrÚ _get_packagesms   rIcCsL|D]B}d|vr| d¡\}}t |¡}nq||jkr| |¡rdSqdS)z+Return whether or not package is installed.rTF)r&ÚPackageÚcanonicalize_nameÚ package_nameÚis_satisfied_by)r6ZreqZinstalled_pkgsZ pkg_commandÚpkgÚpkg_nameZ pkg_versionrrrÚ _is_presents rPc Cs.d}tr d}d}|dur2tj |¡r*|}qT|f}n"|durT|durTtƒrTtjddg}|du�r|dur¦g}|D]}| |d|¡}|durnq¤qn|jdd  |¡d�nrtj  |d ¡}|d d f}|D]0}tj  ||¡}tj  |¡rÄt |ƒrÄ|}�qqÄ|jd |d d  |¡dd�t |t ƒ�s*|g}|S)N)Zpip2r)Zpip3z-mz pip.__main__Fz"r2z#setup_virtualenv..)Zpyvenvz-m venvz-p%sz_virtualenv_python should not be used when using the venv module or pyvenv as virtualenv_commandr,rB)Ú check_modeÚ exit_jsonÚshlexr&rrrRrSr]rXr'r<Úanyr rVrWr4r3rD) r6r[rErGrHr7Zcmd_optsrqr8Zout_venvZerr_venvrrtrÚsetup_virtualenv s6      ÿ  rzc@sLeZdZdZe d¡Zddd„Zedd„ƒZ dd „Z e d d „ƒZ d d „Z dS)rJzÊPython distribution package metadata wrapper. A wrapper class for Requirement, which provides API to parse package name, version specifier, test whether a package is already satisfied. z[-_.]+Nc Cs´d|_||_d|_|r@| ¡}|d ¡r.dnd}| ||f¡}zJt |¡|_|jjdkrrd|vrrd|_d|j_nt   |jj¡|_d|_Wn$t y®}z WYd}~n d}~00dS)NFrrrCZ distributerT) Ú_plain_packagerLÚ _requirementrÚisdigitr(rÚparseZ project_namerJrKÚ ValueError)ÚselfZ name_stringZversion_stringÚ separatorÚerrrÚ__init__Is    zPackage.__init__cCs|jrt|jjƒSdS)NF)r{rcr|Úspecs©r€rrrÚhas_version_specifier^s zPackage.has_version_specifiercsX|js dSz|jjjˆdd�WStyRtˆƒ‰t‡fdd„|jjDƒƒYS0dS)NFT)Z prereleasesc3s$|]\}}t|ˆt|ƒƒVqdS©N)rr)r/ÚopZver©Úversion_to_testrrrulsÿz*Package.is_satisfied_by..)r{r|Z specifierÚcontainsÚAttributeErrorrÚallr„)r€rŠrr‰rrMds  þzPackage.is_satisfied_bycCstj d|¡ ¡S)Nú-)rJÚ_CANONICALIZE_REÚsubÚlowerrrrrrKqszPackage.canonicalize_namecCs|jrt|jƒS|jSr‡)r{rr|rLr…rrrÚ__str__vs zPackage.__str__)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rÚcompiler�rƒÚpropertyr†rMÚ staticmethodrKr’rrrrrJ?s     rJc!CsÎtdgddgddggd¢d�}tttddt| ¡ƒd �td dd �tdd �tdd �td d �tddd�td dd�tdd �tdd �tddd�td d �td d �tdd �d� ddggddgddggdd�}tsÖ|jtdƒtd�|jd}|jd}|jd}|jd}|jd}|jd}|jd}|jd} d} | �rD|�rDt j   || ¡} |�r”t |t ƒ�s”zt |dƒ}Wn.t�y’|jd tt ¡d!ƒd"�Yn0d} |du�r¬t  |¡} �z|d#k�rÐ|du�rÐ|jd$d%�|du�rât ¡}d&} d&} | �r"t j  t j   | d'd(¡¡�s"d} t|| || | ƒ\} } t|| |jdƒ}|||}d}| �rXt j   | d'¡}d}|�rì|D] }|�rft|ƒ�rfd}�qˆ�qfd)d*„t|ƒDƒ}|du�rìt|ƒd!k�r¾|jd+d%�|d,j�rÖ|jd-d%�tt|d,ƒ|ƒ|d,<|jd.�r*g}|�r | d/¡}d0|v�r*| d0¡d/  |¡}|�r@| t  |¡¡|�r\| d1d2„|Dƒ¡n&|�rr| d3|g¡n|j!dd4gd5�|j"�rª|�s¦|�s¦|d#k�s¦|�s²|j!dd6�t#|||ƒ\}}}| |7} | |7} d}|�r˜d7d*„|  d8¡Dƒ}| $d9¡�rTd:|v�sd|v�rTd;D]<}||v�rt%||| ƒ}|du�r| |¡| d<|7} �q|D]>}t&||||ƒ}|dk�rz|�rŠ|d=k�rX|�rXd}�q˜�qX|j!||| | d>�d}|�sº|�rÌt#|||ƒ\}}}|j'|||d?�\}}}| |7} | |7} |d!k�r|d=k�rd@|v�s4d@|v�rn|d,k�r4t(||| | ƒ|d=k�rHdA|v}n.|du�r\dB|v}nt#|||ƒ\}} }|| k}|�p~| }|j!||||||| | | dC� W| du�rÊt  | ¡n| du�rÈt  | ¡0dS)DNÚinstallZ uninstallz-yú-U)ršr›z--force-reinstall)ÚpresentÚabsentÚlatestZforcereinstallÚstrrœ)ÚtypeÚdefaultÚchoicesr=)r Úelements)r rSrcF)r r¡Ú virtualenv) ÚstaterÚversionÚ requirementsr¤rprorqÚ extra_argsÚeditablerErWÚumaskrr§rWT)Z argument_specZrequired_one_ofZmutually_exclusiveZsupports_check_moder)r-Ú exceptionr¥r¦r¨rErªézumask must be an octal integeré)r-Údetailsržz)version is incompatible with state=latestr,rhrQZactivatecSsg|] }t|ƒ‘qSr)rJ)r/rNrrrr1Ür2zmain..zœ'version' argument is ambiguous when installing multiple package distributions. Please specify version restrictions next to each package in 'name' argument.rz¥The 'version' argument conflicts with any version specifier provided along with a package name. Please keep the version specifier, but remove the 'version' argument.r©rCz-ecss|]}t|ƒVqdSr‡r©r/Úprrrruùr2zmain..z-rz)No valid name or requirements file found.)rnÚwarningsrmcSs(g|] }| d¡s| d¡s|r|‘qS)z You are usingzYou should considerr.r¯rrrr1 r2Ú z freezerrz%s r�)rnr7r9r:)Ú path_prefixrAz not installedzSuccessfully uninstalledzSuccessfully installed) rnr7rr¦r¥r§r¤r9r:))Údictr r=r ÚHAS_SETUPTOOLSr4r ÚSETUPTOOLS_IMP_ERRrrrRrSr(rZÚintrdrrVÚexc_inforªÚtempfileZ gettempdirrYrzr_rr+Úlenr†rJr&r'r%rxrwrvrIÚendswithrlrPr3rD)!Z state_mapr6r¥rr¦r§r¨rErªr[Z venv_createdZ old_umaskrHrGrr7r³Zhas_vcsrNZpackagesZ args_listZpkg_cmdZout_pipZerr_piprnZpkg_listrkrjZ is_presentZout_freeze_beforeÚ_r8Zout_freeze_afterrrrÚmain|s0ü    óî ÿ         ÿ        ÿ ÿ     þ         ÿÿ       þ  ÿ r½Ú__main__)NN)N);Z __future__rrrr Z __metaclass__Z DOCUMENTATIONZEXAMPLESZRETURNrRrrVr¹ÚoperatorrxÚ tracebackÚtypesZ#ansible.module_utils.compat.versionrr¶Z pkg_resourcesrrµrbÚ format_excZansible.module_utils._textrZansible.module_utils.basicr r r Z"ansible.module_utils.common.localer Zansible.module_utils.sixr rir—rÚgeÚleÚgtÚltÚeqÚnerrr!r+r<rIrPr_rUrDrlrzrJr½r“rrrrÚs`a      ÿ  ÿ%  ; 6=F