From 3224e408994d3cc4123bf1de82bf0001327a68bb Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush Date: Sat, 7 Jul 2018 13:10:19 -0400 Subject: [PATCH 1/4] Added support for providing pip provider --- README.md | 25 +++++++++++++++++++++++++ manifests/pip.pp | 9 +++++++-- manifests/requirements.pp | 6 ++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4011d693..1c54f6aa 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 provder 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..f3ab55e7 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: present +# # [*url*] # URL to install from. Default: none # @@ -66,11 +69,13 @@ # # Sergey Stankevich # Fotis Gimian +# Daniel Quackenbush # define python::pip ( $pkgname = $name, $ensure = present, $virtualenv = 'system', + $pip_proivder = 'pip', $url = false, $owner = 'root', $group = 'root', @@ -125,8 +130,8 @@ } $pip_env = $virtualenv ? { - 'system' => "${exec_prefix}pip", - default => "${exec_prefix}${virtualenv}/bin/pip", + 'system' => "${exec_prefix}${pip_proivder}", + default => "${exec_prefix}${virtualenv}/bin/${pip_proivder}", } $pypi_index = $index ? { diff --git a/manifests/requirements.pp b/manifests/requirements.pp index d2a64bf4..abf3ee2e 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -62,10 +62,12 @@ # Sergey Stankevich # Ashley Penney # Fotis Gimian +# Daniel Quackenbush # define python::requirements ( $requirements = $name, $virtualenv = 'system', + $pip_provider = 'pip', $owner = 'root', $group = 'root', $proxy = false, @@ -100,8 +102,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 ? { From 50cc338afe8c13d9a13d35c025e3df10920356b7 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush Date: Mon, 9 Jul 2018 01:35:21 -0400 Subject: [PATCH 2/4] fixed typo, comments --- README.md | 2 +- manifests/pip.pp | 2 +- manifests/requirements.pp | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1c54f6aa..544826a8 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Installs and manages packages from pip. **virtualenv** - virtualenv to run pip in. Default: system (no virtualenv) -**pip_provider** - pip provder to execute pip with. Default: pip. +**pip_provider** - pip provider to execute pip with. Default: pip. **url** - URL to install from. Default: none diff --git a/manifests/pip.pp b/manifests/pip.pp index f3ab55e7..aa08cc59 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -17,7 +17,7 @@ # virtualenv to run pip in. # # [*pip_provider*] -# version of pip you wish to use. Default: present +# version of pip you wish to use. Default: pip # # [*url*] # URL to install from. Default: none diff --git a/manifests/requirements.pp b/manifests/requirements.pp index abf3ee2e..06f0a05e 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 # From 00d3f0a689f6268b8a87385a215bdca523d6eabe Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush Date: Mon, 9 Jul 2018 01:51:41 -0400 Subject: [PATCH 3/4] Added data types --- manifests/pip.pp | 38 +++++++++++++++++++------------------- manifests/requirements.pp | 30 +++++++++++++++--------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index aa08cc59..ece8955e 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -72,25 +72,25 @@ # Daniel Quackenbush # define python::pip ( - $pkgname = $name, - $ensure = present, - $virtualenv = 'system', - $pip_proivder = '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'], + $pkgname = $name, + $ensure = present, + $virtualenv = 'system', + Enum['pip', 'pip3'] $pip_proivder = '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') diff --git a/manifests/requirements.pp b/manifests/requirements.pp index 06f0a05e..ffdfd420 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -68,21 +68,21 @@ # Daniel Quackenbush # define python::requirements ( - $requirements = $name, - $virtualenv = 'system', - $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, + $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 From f9f02c7a8155e3dd25272ceae57dbf78564357f3 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush Date: Mon, 9 Jul 2018 14:16:32 -0400 Subject: [PATCH 4/4] fixed typo, added pip rspec --- manifests/pip.pp | 6 +++--- spec/defines/pip_spec.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index ece8955e..755081a3 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -75,7 +75,7 @@ $pkgname = $name, $ensure = present, $virtualenv = 'system', - Enum['pip', 'pip3'] $pip_proivder = 'pip', + Enum['pip', 'pip3'] $pip_provider = 'pip', $url = false, $owner = 'root', $group = 'root', @@ -130,8 +130,8 @@ } $pip_env = $virtualenv ? { - 'system' => "${exec_prefix}${pip_proivder}", - default => "${exec_prefix}${virtualenv}/bin/${pip_proivder}", + 'system' => "${exec_prefix}${pip_provider}", + default => "${exec_prefix}${virtualenv}/bin/${pip_provider}", } $pypi_index = $index ? { diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index edc5fe93..345f20a1 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -37,6 +37,23 @@ it { is_expected.to contain_exec('pip_install_rpyc').with_cwd('/') } 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