Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split package installation in multiple classes #670

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#### Public Classes

* [`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

#### Private Classes
Expand Down Expand Up @@ -289,6 +292,18 @@ Data type: `Stdlib::Absolutepath`

Default value: `'/opt/python'`

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

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

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

allow to bootstrap pip when python is managed from other module
Expand Down
45 changes: 7 additions & 38 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,17 @@
}

if $python::manage_venv_package {
##
## CentOS has no extra package for venv
##
unless $facts['os']['family'] == 'RedHat' {
package { 'python-venv':
ensure => $python::venv,
name => "${python}-venv",
require => Package['python'],
}
}
contain python::install::venv
}

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 {
package { 'python-dev':
ensure => $python::dev,
name => $pythondev,
}
contain python::install::dev
}

# Respect the $python::pip setting
Expand Down Expand Up @@ -171,37 +156,21 @@
}
} else {
if $python::manage_pip_package {
package { 'python-pip':
ensure => $python::pip,
require => Package['python'],
provider => 'yum',
}
contain python::install::pip
}
}

if $python::manage_dev_package and $pythondev {
package { 'python-dev':
ensure => $python::dev,
name => $pythondev,
alias => $pythondev,
provider => 'yum',
}
contain python::install::dev
}
}
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 {
package { 'python-dev':
ensure => $python::dev,
name => $pythondev,
alias => $pythondev,
}
contain python::install::dev
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions manifests/install/dev.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @summary Installs python development packages
class python::install::dev {
include python

case $python::provider {
'pip': {
package { 'python-dev':
ensure => $python::dev,
name => $python::install::pythondev,
}
}
'scl': {
}
'rhscl': {
}
'anaconda': {
}
default: {
case $facts['os']['family'] {
'AIX': {
package { 'python-dev':
ensure => $python::dev,
name => $python::install::pythondev,
alias => $python::install::pythondev,
provider => 'yum',
}
}
default: {
package { 'python-dev':
ensure => $python::dev,
name => $python::install::pythondev,
alias => $python::install::pythondev,
}
}
}
}
}
}
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'],
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions manifests/install/venv.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @summary Installs python virtualenv packages
class python::install::venv {
include python

# Main python package bundle venv on some operating systems
unless $facts['os']['family'] in ['Archlinux', 'FreeBSD', 'RedHat'] {
package { 'python-venv':
ensure => $python::venv,
name => "${python::install::python}-venv",
require => Package['python'],
}
}
}
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
}
$manage_venv_package = $facts['os']['family'] ? {
'Archlinux' => false,
'FreeBSD' => false,
'RedHat' => false,
default => true,
}
}
1 change: 1 addition & 0 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Python::Venv::PipVersion $pip_version = 'latest',
) {
include python
include python::install::venv

if $ensure == 'present' {
$python_version = $version ? {
Expand Down
29 changes: 29 additions & 0 deletions spec/classes/install/dev_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::dev' 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('python-dev').with(ensure: 'absent') }
end

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

it { is_expected.to contain_package('python-dev').with(ensure: 'present') }
end
end
end
end
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
37 changes: 37 additions & 0 deletions spec/classes/install/venv_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require 'spec_helper'

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

context 'with default settings' do
if %w[Archlinux FreeBSD RedHat].include?(facts[:os]['family'])
it { is_expected.not_to contain_package('python-venv') }
else
it { is_expected.to contain_package('python-venv').with(ensure: 'absent') }
end
end

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

if %w[Archlinux FreeBSD RedHat].include?(facts[:os]['family'])
it { is_expected.not_to contain_package('python-venv') }
else
it { is_expected.to contain_package('python-venv').with(ensure: 'present') }
end
end
end
end
end
34 changes: 9 additions & 25 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
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 RedHat].include?(facts[:os]['family'])
it { is_expected.not_to contain_package('python-venv') }
if %w[Archlinux FreeBSD RedHat].include?(facts[:os]['family'])
it { is_expected.not_to contain_class('python::install::venv') }
else
it { is_expected.to contain_package('python-venv') }
it { is_expected.to contain_class('python::install::venv') }
end
end

Expand All @@ -43,24 +43,8 @@
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_package('python-venv') }
end

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

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

it { is_expected.to contain_package('python-venv').with(ensure: 'present') } unless facts[:os]['family'] == 'RedHat'
it { is_expected.not_to contain_class('python::install::pip') }
it { is_expected.not_to contain_class('python::install::venv') }
end

case facts[:os]['family']
Expand All @@ -72,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