Skip to content

Commit

Permalink
Install venv packages in python::install::venv
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Dec 15, 2023
1 parent b08bf1a commit 52c3355
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
5 changes: 5 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,6 +295,10 @@ Default value: `'/opt/python'`

Installs python development 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
11 changes: 1 addition & 10 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
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
12 changes: 4 additions & 8 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 @@ -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']
Expand Down

0 comments on commit 52c3355

Please sign in to comment.