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] 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