Skip to content

Commit 4cf8bee

Browse files
committed
Add python-venv installation
1 parent f87c9c2 commit 4cf8bee

File tree

14 files changed

+110
-64
lines changed

14 files changed

+110
-64
lines changed

REFERENCE.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
### Data types
2929

30-
* [`Python::Loglevel`](#pythonloglevel): A version type to match all valid loglevels for python
31-
* [`Python::Package::Ensure`](#pythonpackageensure): A version type to match all valid package ensures for python
32-
* [`Python::Provider`](#pythonprovider): A version type to match all valid provider for python
33-
* [`Python::Umask`](#pythonumask): A version type to match valid umask for python
30+
* [`Python::Loglevel`](#pythonloglevel): Match all valid loglevels for python
31+
* [`Python::Package::Ensure`](#pythonpackageensure): Match all valid package ensures for python
32+
* [`Python::Provider`](#pythonprovider): Match all valid provider for python
33+
* [`Python::Umask`](#pythonumask): Match valid umask for python
3434
* [`Python::Venv::PipVersion`](#pythonvenvpipversion): A version type to ensure a specific Pip version in a virtual env.
35-
* [`Python::Version`](#pythonversion): A version type to match all valid versions for python
35+
* [`Python::Version`](#pythonversion): Match all valid versions for python
3636

3737
## Classes
3838

@@ -77,8 +77,11 @@ The following parameters are available in the `python` class:
7777
* [`use_epel`](#use_epel)
7878
* [`manage_scl`](#manage_scl)
7979
* [`umask`](#umask)
80+
* [`manage_gunicorn`](#manage_gunicorn)
8081
* [`manage_python_package`](#manage_python_package)
82+
* [`manage_venv_package`](#manage_venv_package)
8183
* [`manage_pip_package`](#manage_pip_package)
84+
* [`venv`](#venv)
8285
* [`gunicorn_package_name`](#gunicorn_package_name)
8386
* [`python_pips`](#python_pips)
8487
* [`python_pyvenvs`](#python_pyvenvs)
@@ -175,22 +178,44 @@ The default umask for invoked exec calls.
175178

176179
Default value: ``undef``
177180

181+
##### <a name="manage_gunicorn"></a>`manage_gunicorn`
182+
183+
manage the state for package gunicorn
184+
185+
Default value: `$python::params::manage_gunicorn`
186+
178187
##### <a name="manage_python_package"></a>`manage_python_package`
179188

180189
Data type: `Boolean`
181190

182-
191+
manage the state for package python
183192

184193
Default value: `$python::params::manage_python_package`
185194

186-
##### <a name="manage_pip_package"></a>`manage_pip_package`
195+
##### <a name="manage_venv_package"></a>`manage_venv_package`
187196

188197
Data type: `Boolean`
189198

199+
manage the state for package venv
190200

201+
Default value: `$python::params::manage_venv_package`
202+
203+
##### <a name="manage_pip_package"></a>`manage_pip_package`
204+
205+
Data type: `Boolean`
206+
207+
manage the state for package pip
191208

192209
Default value: `$python::params::manage_pip_package`
193210

211+
##### <a name="venv"></a>`venv`
212+
213+
Data type: `Python::Package::Ensure`
214+
215+
216+
217+
Default value: `$python::params::venv`
218+
194219
##### <a name="gunicorn_package_name"></a>`gunicorn_package_name`
195220

196221
Data type: `String[1]`
@@ -1112,7 +1137,7 @@ Default value: `1800`
11121137

11131138
### <a name="pythonloglevel"></a>`Python::Loglevel`
11141139

1115-
A version type to match all valid loglevels for python
1140+
Match all valid loglevels for python
11161141

11171142
Alias of
11181143

@@ -1122,7 +1147,7 @@ Enum['debug', 'info', 'warning', 'error', 'critical']
11221147

11231148
### <a name="pythonpackageensure"></a>`Python::Package::Ensure`
11241149

1125-
A version type to match all valid package ensures for python
1150+
Match all valid package ensures for python
11261151

11271152
Alias of
11281153

@@ -1132,7 +1157,7 @@ Enum['absent', 'present', 'latest']
11321157

11331158
### <a name="pythonprovider"></a>`Python::Provider`
11341159

1135-
A version type to match all valid provider for python
1160+
Match all valid provider for python
11361161

11371162
Alias of
11381163

@@ -1142,7 +1167,7 @@ Enum['pip', 'scl', 'rhscl', 'anaconda', '']
11421167

11431168
### <a name="pythonumask"></a>`Python::Umask`
11441169

1145-
A version type to match valid umask for python
1170+
Match valid umask for python
11461171

11471172
Alias of
11481173

@@ -1162,7 +1187,7 @@ Pattern[/^(<|>|<=|>=|==) [0-9]*(\.[0-9]+)*$/, /\Alatest\Z/]
11621187

11631188
### <a name="pythonversion"></a>`Python::Version`
11641189

1165-
A version type to match all valid versions for python
1190+
Match all valid versions for python
11661191

11671192
Alias of
11681193

manifests/init.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
# @param use_epel to determine if the epel class is used.
1818
# @param manage_scl Whether to manage core SCL packages or not.
1919
# @param umask The default umask for invoked exec calls.
20+
# @param manage_gunicorn manage the state for package gunicorn
21+
# @param manage_python_package manage the state for package python
22+
# @param manage_venv_package manage the state for package venv
23+
# @param manage_pip_package manage the state for package pip
2024
#
2125
# @example install python from system python
2226
# class { 'python':
@@ -37,9 +41,11 @@
3741
Python::Version $version = '3',
3842
Python::Package::Ensure $pip = $python::params::pip,
3943
Python::Package::Ensure $dev = $python::params::dev,
44+
Python::Package::Ensure $venv = $python::params::venv,
4045
Python::Package::Ensure $gunicorn = $python::params::gunicorn,
4146
Boolean $manage_gunicorn = $python::params::manage_gunicorn,
4247
Boolean $manage_python_package = $python::params::manage_python_package,
48+
Boolean $manage_venv_package = $python::params::manage_venv_package,
4349
Boolean $manage_pip_package = $python::params::manage_pip_package,
4450
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
4551
Optional[Python::Provider] $provider = $python::params::provider,

manifests/install.pp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,44 @@
2323
'Suse' => "${python}-devel",
2424
}
2525

26-
$pip_ensure = $python::pip ? {
27-
true => 'present',
28-
false => 'absent',
29-
default => $python::pip,
30-
}
31-
32-
$dev_ensure = $python::dev ? {
33-
true => 'present',
34-
false => 'absent',
35-
default => $python::dev,
36-
}
37-
3826
if $python::manage_python_package {
3927
package { 'python':
4028
ensure => $python::ensure,
4129
name => $python,
4230
}
4331
}
4432

33+
if $python::manage_venv_package {
34+
##
35+
## CentOS has no extra package for venv
36+
##
37+
unless $facts['os']['name'] == 'CentOS' {
38+
package { 'python-venv':
39+
ensure => $python::venv,
40+
name => "${python}-venv",
41+
require => Package['python'],
42+
}
43+
}
44+
}
45+
4546
case $python::provider {
4647
'pip': {
4748
if $python::manage_pip_package {
4849
package { 'pip':
49-
ensure => $pip_ensure,
50+
ensure => $python::pip,
5051
require => Package['python'],
5152
}
5253
}
5354

5455
if $pythondev {
5556
package { 'python-dev':
56-
ensure => $dev_ensure,
57+
ensure => $python::dev,
5758
name => $pythondev,
5859
}
5960
}
6061

61-
# Respect the $pip_ensure setting
62-
unless $pip_ensure == 'absent' {
62+
# Respect the $python::pip setting
63+
unless $python::pip == 'absent' {
6364
# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
6465
include python::pip::bootstrap
6566

@@ -93,16 +94,16 @@
9394

9495
Package['scl-utils'] -> Package["${python}-scldevel"]
9596

96-
if $pip_ensure != 'absent' {
97+
if $python::pip != 'absent' {
9798
Package['scl-utils'] -> Exec['python-scl-pip-install']
9899
}
99100
}
100101

101102
package { "${python}-scldevel":
102-
ensure => $dev_ensure,
103+
ensure => $python::dev,
103104
}
104105

105-
if $pip_ensure != 'absent' {
106+
if $python::pip != 'absent' {
106107
exec { 'python-scl-pip-install':
107108
command => "${python::exec_prefix}easy_install pip",
108109
path => ['/usr/bin', '/bin'],
@@ -126,17 +127,13 @@
126127
tag => 'python-scl-package',
127128
}
128129

129-
Package <| title == 'virtualenv' |> {
130-
name => "${python}-python-virtualenv",
131-
}
132-
133130
package { "${python}-scldevel":
134-
ensure => $dev_ensure,
131+
ensure => $python::dev,
135132
tag => 'python-scl-package',
136133
}
137134

138135
package { "${python}-python-pip":
139-
ensure => $pip_ensure,
136+
ensure => $python::pip,
140137
tag => 'python-pip-package',
141138
}
142139

@@ -174,7 +171,7 @@
174171
} else {
175172
if $python::manage_pip_package {
176173
package { 'python-pip':
177-
ensure => $pip_ensure,
174+
ensure => $python::pip,
178175
require => Package['python'],
179176
provider => 'yum',
180177
}
@@ -183,7 +180,7 @@
183180

184181
if $pythondev {
185182
package { 'python-dev':
186-
ensure => $dev_ensure,
183+
ensure => $python::dev,
187184
name => $pythondev,
188185
alias => $pythondev,
189186
provider => 'yum',
@@ -193,14 +190,14 @@
193190
default: {
194191
if $python::manage_pip_package {
195192
package { 'pip':
196-
ensure => $pip_ensure,
193+
ensure => $python::pip,
197194
require => Package['python'],
198195
}
199196
}
200197

201198
if $pythondev {
202199
package { 'python-dev':
203-
ensure => $dev_ensure,
200+
ensure => $python::dev,
204201
name => $pythondev,
205202
alias => $pythondev,
206203
}
@@ -209,7 +206,7 @@
209206
}
210207

211208
if $facts['os']['family'] == 'RedHat' {
212-
if $pip_ensure != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) {
209+
if $python::pip != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) {
213210
require epel
214211
}
215212
}

manifests/params.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
$pip = 'present'
1414
$dev = 'absent'
1515
$virtualenv = 'absent'
16+
$venv = 'absent'
1617
$gunicorn = 'absent'
1718
$manage_gunicorn = true
1819
$manage_python_package = true
19-
$manage_virtualenv_package = true
20+
$manage_venv_package = true
2021
$manage_pip_package = true
2122
$provider = undef
2223
$valid_versions = undef

manifests/pyvenv.pp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444
$python_version_parts = split($python_version, '[.]')
4545
$normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1])
4646

47-
# Debian splits the venv module into a seperate package
48-
if ( $facts['os']['family'] == 'Debian') {
49-
$python3_venv_package = "python${normalized_python_version}-venv"
50-
ensure_packages($python3_venv_package)
51-
52-
Package[$python3_venv_package] -> File[$venv_dir]
53-
}
54-
5547
# pyvenv is deprecated since 3.6 and will be removed in 3.8
5648
if versioncmp($normalized_python_version, '3.6') >=0 {
5749
$virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv"
@@ -71,10 +63,11 @@
7163
}
7264

7365
file { $venv_dir:
74-
ensure => directory,
75-
owner => $owner,
76-
group => $group,
77-
mode => $mode,
66+
ensure => directory,
67+
owner => $owner,
68+
group => $group,
69+
mode => $mode,
70+
require => Class['python::install'],
7871
}
7972

8073
$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"

spec/acceptance/class_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class { 'python':
2323
version => '3',
2424
pip => 'present',
2525
dev => 'present',
26+
venv => 'present',
2627
}
2728
EOS
2829

spec/acceptance/pyvenv_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class { 'python':
1111
version => '3',
1212
dev => 'present',
13+
venv => 'present',
1314
}
1415
user { 'agent':
1516
ensure => 'present',
@@ -42,6 +43,7 @@ class { 'python':
4243
class { 'python':
4344
version => '3',
4445
dev => 'present',
46+
venv => 'present',
4547
}
4648
user { 'agent':
4749
ensure => 'present',
@@ -82,6 +84,7 @@ class { 'python':
8284
class { 'python':
8385
version => '3',
8486
dev => 'present',
87+
venv => 'present',
8588
}
8689
user { 'agent':
8790
ensure => 'present',
@@ -119,6 +122,7 @@ class { 'python':
119122
class { 'python':
120123
version => '3',
121124
dev => 'present',
125+
venv => 'present',
122126
}
123127
user { 'agent':
124128
ensure => 'present',
@@ -156,6 +160,7 @@ class { 'python':
156160
class { 'python':
157161
version => '3',
158162
dev => 'present',
163+
venv => 'present',
159164
}
160165
user { 'agent':
161166
ensure => 'present',

0 commit comments

Comments
 (0)