Skip to content

Commit

Permalink
Merge pull request #414 from paychex/pip3-support
Browse files Browse the repository at this point in the history
support for providing pip3 provider w/ tests. Modified readme 4 examples
  • Loading branch information
bastelfreak authored Jul 9, 2018
2 parents b5c6798 + c86dd5d commit 2e94933
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 36 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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

Expand Down
45 changes: 25 additions & 20 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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 ? {
Expand Down
37 changes: 21 additions & 16 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand All @@ -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 ? {
Expand Down
20 changes: 20 additions & 0 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { {} }
Expand Down

0 comments on commit 2e94933

Please sign in to comment.