Skip to content

Commit

Permalink
Install pip packages in python::install::pip
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Dec 15, 2023
1 parent 52c3355 commit a16c61b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
5 changes: 5 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

* [`python`](#python): Installs and manages python, python-dev and gunicorn.
* [`python::install::dev`](#python--install--dev): Installs python development packages
* [`python::install::pip`](#python--install--pip): Installs python pip packages
* [`python::install::venv`](#python--install--venv): Installs python virtualenv packages
* [`python::pip::bootstrap`](#python--pip--bootstrap): allow to bootstrap pip when python is managed from other module

Expand Down Expand Up @@ -295,6 +296,10 @@ Default value: `'/opt/python'`

Installs python development packages

### <a name="python--install--pip"></a>`python::install::pip`

Installs python pip packages

### <a name="python--install--venv"></a>`python::install::venv`

Installs python virtualenv packages
Expand Down
16 changes: 3 additions & 13 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
case $python::provider {
'pip': {
if $python::manage_pip_package {
package { 'pip':
ensure => $python::pip,
require => Package['python'],
}
contain python::install::pip
}

if $python::manage_dev_package and $pythondev {
Expand Down Expand Up @@ -159,11 +156,7 @@
}
} else {
if $python::manage_pip_package {
package { 'python-pip':
ensure => $python::pip,
require => Package['python'],
provider => 'yum',
}
contain python::install::pip
}
}

Expand All @@ -173,10 +166,7 @@
}
default: {
if $python::manage_pip_package {
package { 'pip':
ensure => $python::pip,
require => Package['python'],
}
contain python::install::pip
}

if $python::manage_dev_package and $pythondev {
Expand Down
38 changes: 38 additions & 0 deletions manifests/install/pip.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @summary Installs python pip packages
class python::install::pip {
include python

case $python::provider {
'pip': {
package { 'pip':
ensure => $python::pip,
require => Package['python'],
}
}
'scl': {
}
'rhscl': {
}
'anaconda': {
}
default: {
case $facts['os']['family'] {
'AIX': {
unless String($python::version) =~ /^python3/ {
package { 'python-pip':
ensure => $python::pip,
require => Package['python'],
provider => 'yum',
}
}
}
default: {
package { 'pip':
ensure => $python::pip,
require => Package['python'],
}
}
}
}
}
}
29 changes: 29 additions & 0 deletions spec/classes/install/pip_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'python::install::pip' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end

context 'with default settings' do
it { is_expected.to contain_package('pip').with(ensure: 'present') }
end

context 'when ensuring pip is absent' do
let(:pre_condition) do
<<~PP
class { 'python':
pip => absent,
}
PP
end

it { is_expected.to contain_package('pip').with(ensure: 'absent') }
end
end
end
end
22 changes: 5 additions & 17 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_package('python') }

if facts[:os]['family'] == 'Archlinux'
it { is_expected.not_to contain_package('pip') }
if %w[Archlinux].include?(facts[:os]['family'])
it { is_expected.not_to contain_class('python::install::pip') }
else
it { is_expected.to contain_package('pip') }
it { is_expected.to contain_class('python::install::pip') }
end

if %w[Archlinux FreeBSD RedHat].include?(facts[:os]['family'])
Expand All @@ -43,22 +43,10 @@
it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('python') }
it { is_expected.not_to contain_package('python-dev') }
it { is_expected.not_to contain_package('pip') }
it { is_expected.not_to contain_class('python::install::pip') }
it { is_expected.not_to contain_class('python::install::venv') }
end

context 'with packages present' do
let :params do
{
manage_pip_package: true,
pip: 'present',
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('pip').with(ensure: 'present') }
end

case facts[:os]['family']
when 'Debian'

Expand All @@ -68,7 +56,7 @@
# Base debian packages.
it { is_expected.to contain_package('python') }
it { is_expected.to contain_package('python-dev') }
it { is_expected.to contain_package('pip') }
it { is_expected.to contain_class('python::install::pip') }

describe 'with python::version' do
context 'python3.7' do
Expand Down

0 comments on commit a16c61b

Please sign in to comment.