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 6 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
24 changes: 24 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 @@ -83,6 +86,7 @@ The following parameters are available in the `python` class:
* [`manage_venv_package`](#-python--manage_venv_package)
* [`manage_pip_package`](#-python--manage_pip_package)
* [`venv`](#-python--venv)
* [`pip_package_name`](#-python--pip_package_name)
* [`gunicorn_package_name`](#-python--gunicorn_package_name)
* [`python_pips`](#-python--python_pips)
* [`python_pyvenvs`](#-python--python_pyvenvs)
Expand Down Expand Up @@ -225,6 +229,14 @@ Data type: `Python::Package::Ensure`

Default value: `'absent'`

##### <a name="-python--pip_package_name"></a>`pip_package_name`

Data type: `Optional[String[1]]`



Default value: `undef`

##### <a name="-python--gunicorn_package_name"></a>`gunicorn_package_name`

Data type: `String[1]`
Expand Down Expand Up @@ -289,6 +301,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
2 changes: 2 additions & 0 deletions data/os/FreeBSD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
python::version: '39'
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
Boolean $manage_dev_package = true,
Boolean $manage_venv_package = $python::params::manage_venv_package,
Boolean $manage_pip_package = $python::params::manage_pip_package,
Optional[String[1]] $pip_package_name = undef,
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Python::Provider] $provider = undef,
Hash $python_pips = {},
Expand All @@ -68,6 +69,13 @@
default => '',
}

$pip_package_real_name = $pip_package_name.lest || {
fact('os.family') ? {
'FreeBSD' => "py${version}-pip",
default => 'python-pip',
}
}

contain python::install
contain python::config

Expand Down
47 changes: 8 additions & 39 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,23 @@
}

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
unless $python::pip == 'absent' {
# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
include python::pip::bootstrap
contain python::pip::bootstrap

Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>

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': {
}
'pip', 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 @@ -38,6 +38,7 @@
Optional[Stdlib::Absolutepath] $python_path = undef,
) {
include python
include python::install::venv

if $ensure == 'present' {
$python_version = $version ? {
Expand Down
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 RedHat FreeBSD].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
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
32 changes: 8 additions & 24 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
it { is_expected.to contain_package('python') }

if facts[:os]['family'] == 'Archlinux'
it { is_expected.not_to contain_package('pip') }
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].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') }

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on almalinux-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on almalinux-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on centos-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on freebsd-11-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on freebsd-12-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on freebsd-13-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on oraclelinux-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on oraclelinux-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on redhat-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

python on redhat-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on almalinux-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on almalinux-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on centos-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on freebsd-11-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on freebsd-12-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on freebsd-13-amd64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on oraclelinux-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on oraclelinux-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on redhat-8-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would contain Class[python::install::venv]

Check failure on line 29 in spec/classes/python_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

python on redhat-9-x86_64 with defaults is expected to contain Class[python::install::venv] Failure/Error: it { is_expected.to contain_class('python::install::venv') } expected that the catalogue would 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
Loading