From 53e209063fbfa386a3e0a9dcaf1f92ac9c498df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Fri, 15 Sep 2023 10:11:04 -1000 Subject: [PATCH 1/6] Install dev packages in python::install::dev --- REFERENCE.md | 5 +++++ manifests/install.pp | 18 +++--------------- manifests/install/dev.pp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 manifests/install/dev.pp diff --git a/REFERENCE.md b/REFERENCE.md index f3a382e5..e38d1bbf 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -9,6 +9,7 @@ #### Public Classes * [`python`](#python): Installs and manages python, python-dev and gunicorn. +* [`python::install::dev`](#python--install--dev): Installs python development packages * [`python::pip::bootstrap`](#python--pip--bootstrap): allow to bootstrap pip when python is managed from other module #### Private Classes @@ -289,6 +290,10 @@ Data type: `Stdlib::Absolutepath` Default value: `'/opt/python'` +### `python::install::dev` + +Installs python development packages + ### `python::pip::bootstrap` allow to bootstrap pip when python is managed from other module diff --git a/manifests/install.pp b/manifests/install.pp index c3db3d80..d07465d0 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -54,10 +54,7 @@ } if $python::manage_dev_package and $pythondev { - package { 'python-dev': - ensure => $python::dev, - name => $pythondev, - } + contain python::install::dev } # Respect the $python::pip setting @@ -180,12 +177,7 @@ } if $python::manage_dev_package and $pythondev { - package { 'python-dev': - ensure => $python::dev, - name => $pythondev, - alias => $pythondev, - provider => 'yum', - } + contain python::install::dev } } default: { @@ -197,11 +189,7 @@ } 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, + } + } + } + } + } +} From 3dbd902ad6d37bbe88d05a8cef20a3a6c9f5cfa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Fri, 15 Sep 2023 10:13:25 -1000 Subject: [PATCH 2/6] Install venv packages in python::install::venv --- REFERENCE.md | 5 +++++ manifests/install.pp | 11 +---------- manifests/install/venv.pp | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 manifests/install/venv.pp diff --git a/REFERENCE.md b/REFERENCE.md index e38d1bbf..f891c34d 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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::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 @@ -294,6 +295,10 @@ Default value: `'/opt/python'` Installs python development 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/manifests/install.pp b/manifests/install.pp index d07465d0..348aeda3 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -32,16 +32,7 @@ } 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 { diff --git a/manifests/install/venv.pp b/manifests/install/venv.pp new file mode 100644 index 00000000..3169137c --- /dev/null +++ b/manifests/install/venv.pp @@ -0,0 +1,15 @@ +# @summary Installs python virtualenv packages +class python::install::venv { + include python + + ## + ## CentOS has no extra package for venv + ## + unless $facts['os']['family'] == 'RedHat' { + package { 'python-venv': + ensure => $python::venv, + name => "${python::install::python}-venv", + require => Package['python'], + } + } +} From 0a0da14d30c82ed47869d5fe8c42f4e475b1fd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Fri, 15 Sep 2023 10:18:00 -1000 Subject: [PATCH 3/6] Install pip packages in python::install::pip --- REFERENCE.md | 5 +++++ manifests/install.pp | 16 +++------------- manifests/install/pip.pp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 manifests/install/pip.pp diff --git a/REFERENCE.md b/REFERENCE.md index f891c34d..3863c0b9 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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 @@ -295,6 +296,10 @@ Default value: `'/opt/python'` Installs python development packages +### `python::install::pip` + +Installs python pip packages + ### `python::install::venv` Installs python virtualenv packages diff --git a/manifests/install.pp b/manifests/install.pp index 348aeda3..dff77609 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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 { @@ -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 } } @@ -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 { diff --git a/manifests/install/pip.pp b/manifests/install/pip.pp new file mode 100644 index 00000000..baf24c53 --- /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': { + } + 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'], + } + } + } + } + } +} From 673e4e1d768c132c8cebc06044d08f87329ee159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Sun, 8 Oct 2023 17:05:57 -1000 Subject: [PATCH 4/6] WIP venv testing --- manifests/install/venv.pp | 6 ++--- manifests/pyvenv.pp | 1 + spec/classes/install/venv_spec.rb | 37 +++++++++++++++++++++++++++++++ spec/classes/python_spec.rb | 12 ++++------ 4 files changed, 44 insertions(+), 12 deletions(-) create mode 100644 spec/classes/install/venv_spec.rb diff --git a/manifests/install/venv.pp b/manifests/install/venv.pp index 3169137c..1b35479a 100644 --- a/manifests/install/venv.pp +++ b/manifests/install/venv.pp @@ -2,10 +2,8 @@ class python::install::venv { include python - ## - ## CentOS has no extra package for venv - ## - unless $facts['os']['family'] == 'RedHat' { + # Main python package bundle venv on some operating systems + unless $facts['os']['family'] in ['Archlinux', 'RedHat', 'FreeBSD'] { package { 'python-venv': ensure => $python::venv, name => "${python::install::python}-venv", 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..554559b5 --- /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 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: 'present') } + end + end + end + end +end diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index 54c47fc7..dcebdc89 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -23,10 +23,10 @@ it { is_expected.to contain_package('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 @@ -44,23 +44,19 @@ 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') } + it { is_expected.not_to contain_class('python::install::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' end case facts[:os]['family'] From 8491f8e32a9ec9314a21182bcafe98483f721a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 13 Dec 2023 22:23:22 -1000 Subject: [PATCH 5/6] WIP not committed --- data/os/FreeBSD.yaml | 2 ++ manifests/init.pp | 9 +++++++++ manifests/install.pp | 2 +- manifests/install/pip.pp | 2 +- spec/classes/install_pip_spec.rb | 29 +++++++++++++++++++++++++++++ spec/classes/python_spec.rb | 20 ++++---------------- 6 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 data/os/FreeBSD.yaml create mode 100644 spec/classes/install_pip_spec.rb 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..b681e7a2 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,14 @@ 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 dff77609..9c129497 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -48,7 +48,7 @@ # 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 |> diff --git a/manifests/install/pip.pp b/manifests/install/pip.pp index baf24c53..18b11468 100644 --- a/manifests/install/pip.pp +++ b/manifests/install/pip.pp @@ -15,7 +15,7 @@ } 'anaconda': { } - default: { + pip, default: { case $facts['os']['family'] { 'AIX': { unless String($python::version) =~ /^python3/ { diff --git a/spec/classes/install_pip_spec.rb b/spec/classes/install_pip_spec.rb new file mode 100644 index 00000000..458a68a6 --- /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 dcebdc89..8f43560c 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -18,9 +18,9 @@ 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].include?(facts[:os]['family']) @@ -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' @@ -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 From 04c346a5a4ff0e8cdf2a44c72fc4f7b4dffbad45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Thu, 14 Dec 2023 06:48:05 -1000 Subject: [PATCH 6/6] FIX --- REFERENCE.md | 9 +++++++++ manifests/init.pp | 1 - manifests/install/pip.pp | 2 +- manifests/install/venv.pp | 2 +- manifests/params.pp | 2 ++ spec/classes/install/venv_spec.rb | 2 +- spec/classes/install_pip_spec.rb | 6 +++--- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 3863c0b9..558ea8ff 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -86,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) @@ -228,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]` diff --git a/manifests/init.pp b/manifests/init.pp index b681e7a2..57b5e0dc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -76,7 +76,6 @@ } } - contain python::install contain python::config diff --git a/manifests/install/pip.pp b/manifests/install/pip.pp index 18b11468..14c19192 100644 --- a/manifests/install/pip.pp +++ b/manifests/install/pip.pp @@ -15,7 +15,7 @@ } 'anaconda': { } - pip, default: { + 'pip', default: { case $facts['os']['family'] { 'AIX': { unless String($python::version) =~ /^python3/ { diff --git a/manifests/install/venv.pp b/manifests/install/venv.pp index 1b35479a..c0d0abb4 100644 --- a/manifests/install/venv.pp +++ b/manifests/install/venv.pp @@ -3,7 +3,7 @@ include python # Main python package bundle venv on some operating systems - unless $facts['os']['family'] in ['Archlinux', 'RedHat', 'FreeBSD'] { + unless $facts['os']['family'] in ['Archlinux', 'FreeBSD', 'RedHat'] { package { 'python-venv': ensure => $python::venv, name => "${python::install::python}-venv", 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/spec/classes/install/venv_spec.rb b/spec/classes/install/venv_spec.rb index 554559b5..ceaae979 100644 --- a/spec/classes/install/venv_spec.rb +++ b/spec/classes/install/venv_spec.rb @@ -26,7 +26,7 @@ class { 'python': PP end - if %w[Archlinux RedHat FreeBSD].include?(facts[:os]['family']) + 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') } diff --git a/spec/classes/install_pip_spec.rb b/spec/classes/install_pip_spec.rb index 458a68a6..fc67d6c6 100644 --- a/spec/classes/install_pip_spec.rb +++ b/spec/classes/install_pip_spec.rb @@ -16,9 +16,9 @@ context 'when ensuring pip is absent' do let(:pre_condition) do <<~PP - class { 'python': - pip => absent, - } + class { 'python': + pip => absent, + } PP end