diff --git a/REFERENCE.md b/REFERENCE.md index f3a382e5..558ea8ff 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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 @@ -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) @@ -225,6 +229,14 @@ Data type: `Python::Package::Ensure` Default value: `'absent'` +##### `pip_package_name` + +Data type: `Optional[String[1]]` + + + +Default value: `undef` + ##### `gunicorn_package_name` Data type: `String[1]` @@ -289,6 +301,18 @@ Data type: `Stdlib::Absolutepath` Default value: `'/opt/python'` +### `python::install::dev` + +Installs python development packages + +### `python::install::pip` + +Installs python pip packages + +### `python::install::venv` + +Installs python virtualenv packages + ### `python::pip::bootstrap` allow to bootstrap pip when python is managed from other module diff --git a/data/os/FreeBSD.yaml b/data/os/FreeBSD.yaml new file mode 100644 index 00000000..b2c066ad --- /dev/null +++ b/data/os/FreeBSD.yaml @@ -0,0 +1,2 @@ +--- +python::version: '39' diff --git a/manifests/init.pp b/manifests/init.pp index b457edbd..57b5e0dc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 = {}, @@ -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 diff --git a/manifests/install.pp b/manifests/install.pp index c3db3d80..9c129497 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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 |> @@ -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 } } } diff --git a/manifests/install/dev.pp b/manifests/install/dev.pp new file mode 100644 index 00000000..a8a5103d --- /dev/null +++ b/manifests/install/dev.pp @@ -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, + } + } + } + } + } +} diff --git a/manifests/install/pip.pp b/manifests/install/pip.pp new file mode 100644 index 00000000..14c19192 --- /dev/null +++ b/manifests/install/pip.pp @@ -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'], + } + } + } + } + } +} diff --git a/manifests/install/venv.pp b/manifests/install/venv.pp new file mode 100644 index 00000000..c0d0abb4 --- /dev/null +++ b/manifests/install/venv.pp @@ -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'], + } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index 49bfdeac..c61b1b5d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -40,6 +40,8 @@ } $manage_venv_package = $facts['os']['family'] ? { 'Archlinux' => false, + 'FreeBSD' => false, + 'RedHat' => false, default => true, } } diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 5bfc2103..4e0a91d5 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -38,6 +38,7 @@ Optional[Stdlib::Absolutepath] $python_path = undef, ) { include python + include python::install::venv if $ensure == 'present' { $python_version = $version ? { diff --git a/spec/classes/install/venv_spec.rb b/spec/classes/install/venv_spec.rb new file mode 100644 index 00000000..ceaae979 --- /dev/null +++ b/spec/classes/install/venv_spec.rb @@ -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 diff --git a/spec/classes/install_pip_spec.rb b/spec/classes/install_pip_spec.rb new file mode 100644 index 00000000..fc67d6c6 --- /dev/null +++ b/spec/classes/install_pip_spec.rb @@ -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 diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index 54c47fc7..8f43560c 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -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') } end end @@ -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'] @@ -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