From c86dd5d4d93557e1241eb874194c3382779459e3 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush Date: Mon, 9 Jul 2018 16:51:00 -0400 Subject: [PATCH] support for providing pip3 provider w/ tests. Modified readme 4 examples --- README.md | 25 ++++++++++++++++++++++ manifests/pip.pp | 45 ++++++++++++++++++++++----------------- manifests/requirements.pp | 37 ++++++++++++++++++-------------- spec/defines/pip_spec.rb | 20 +++++++++++++++++ 4 files changed, 91 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 4011d693..544826a8 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic **use_epel** - Boolean to determine if the epel class is used. Default: true on RHEL like systems, false otherwise +*Install Python from system python* ```puppet class { 'python' : version => 'system', @@ -66,6 +67,15 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic gunicorn => 'absent', } ``` +*Install Python 3 from the scl repo* +```puppet + class { 'python' : + ensure => 'present', + version => 'rh-python36-python', + dev => 'present', + virtualenv => 'present', + } +``` ### python::pip @@ -77,6 +87,8 @@ Installs and manages packages from pip. **virtualenv** - virtualenv to run pip in. Default: system (no virtualenv) +**pip_provider** - pip provider to execute pip with. Default: pip. + **url** - URL to install from. Default: none **owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root @@ -94,6 +106,8 @@ Installs and manages packages from pip. **uninstall_args** - String of additional flags to pass to pip during uninstall. Default: none **timeout** - Timeout for the pip install command. Defaults to 1800. + +*Install cx_Oracle with pip* ```puppet python::pip { 'cx_Oracle' : pkgname => 'cx_Oracle', @@ -106,6 +120,17 @@ Installs and manages packages from pip. timeout => 1800, } ``` +*Install Requests with pip3* +```puppet + python::pip { 'requests' : + ensure => 'present', + pkgname => 'requests', + pip_provider => 'pip3', + virtualenv => '/var/www/project1', + owner => 'root', + timeout => 1800 + } +``` ### python::requirements diff --git a/manifests/pip.pp b/manifests/pip.pp index fde7dc7e..755081a3 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -16,6 +16,9 @@ # [*virtualenv*] # virtualenv to run pip in. # +# [*pip_provider*] +# version of pip you wish to use. Default: pip +# # [*url*] # URL to install from. Default: none # @@ -66,26 +69,28 @@ # # Sergey Stankevich # Fotis Gimian +# Daniel Quackenbush # define python::pip ( - $pkgname = $name, - $ensure = present, - $virtualenv = 'system', - $url = false, - $owner = 'root', - $group = 'root', - $umask = undef, - $index = false, - $proxy = false, - $egg = false, - $editable = false, - $environment = [], - $extras = [], - $install_args = '', - $uninstall_args = '', - $timeout = 1800, - $log_dir = '/tmp', - $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], + $pkgname = $name, + $ensure = present, + $virtualenv = 'system', + Enum['pip', 'pip3'] $pip_provider = 'pip', + $url = false, + $owner = 'root', + $group = 'root', + $umask = undef, + $index = false, + $proxy = false, + $egg = false, + $editable = false, + $environment = [], + $extras = [], + $install_args = '', + $uninstall_args = '', + $timeout = 1800, + $log_dir = '/tmp', + $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'], ) { $python_provider = getparam(Class['python'], 'provider') $python_version = getparam(Class['python'], 'version') @@ -125,8 +130,8 @@ } $pip_env = $virtualenv ? { - 'system' => "${exec_prefix}pip", - default => "${exec_prefix}${virtualenv}/bin/pip", + 'system' => "${exec_prefix}${pip_provider}", + default => "${exec_prefix}${virtualenv}/bin/${pip_provider}", } $pypi_index = $index ? { diff --git a/manifests/requirements.pp b/manifests/requirements.pp index d2a64bf4..ffdfd420 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -10,6 +10,9 @@ # [*virtualenv*] # virtualenv to run pip in. Default: system-wide # +# [*pip_provider*] +# version of pip you wish to use. Default: pip +# # [*owner*] # The owner of the virtualenv being manipulated. Default: root # @@ -62,22 +65,24 @@ # Sergey Stankevich # Ashley Penney # Fotis Gimian +# Daniel Quackenbush # define python::requirements ( - $requirements = $name, - $virtualenv = 'system', - $owner = 'root', - $group = 'root', - $proxy = false, - $src = false, - $environment = [], - $forceupdate = false, - $cwd = undef, - $extra_pip_args = '', - $manage_requirements = true, - $fix_requirements_owner = true, - $log_dir = '/tmp', - $timeout = 1800, + $requirements = $name, + $virtualenv = 'system', + Enum['pip', 'pip3'] $pip_provider = 'pip', + $owner = 'root', + $group = 'root', + $proxy = false, + $src = false, + $environment = [], + $forceupdate = false, + $cwd = undef, + $extra_pip_args = '', + $manage_requirements = true, + $fix_requirements_owner = true, + $log_dir = '/tmp', + $timeout = 1800, ) { include ::python @@ -100,8 +105,8 @@ } $pip_env = $virtualenv ? { - 'system' => "${::python::exec_prefix} pip", - default => "${::python::exec_prefix} ${virtualenv}/bin/pip", + 'system' => "${::python::exec_prefix} ${pip_provider}", + default => "${::python::exec_prefix} ${virtualenv}/bin/${pip_provider}", } $proxy_flag = $proxy ? { diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index edc5fe93..a040beec 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -38,6 +38,26 @@ end end + describe 'pip_provide as' do + context 'defaults to pip' do + let(:params) { {} } + + it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip}) } + it { is_expected.not_to contain_exec('pip_install_rpyc').with_command(%r{pip3}) } + end + context 'use pip instead of pip3 when specified' do + let(:params) { { pip_provider: 'pip' } } + + it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip}) } + it { is_expected.not_to contain_exec('pip_install_rpyc').with_command(%r{pip3}) } + end + context 'use pip3 instead of pip when specified' do + let(:params) { { pip_provider: 'pip3' } } + + it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip3}) } + end + end + describe 'proxy as' do context 'defaults to empty' do let(:params) { {} }