Skip to content

Commit

Permalink
Merge pull request #579 from crazymind1337/fix/python-venv/installation
Browse files Browse the repository at this point in the history
Add python-venv installation
  • Loading branch information
bastelfreak authored Mar 8, 2022
2 parents f87c9c2 + 4cf8bee commit 96b887f
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 64 deletions.
49 changes: 37 additions & 12 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

### Data types

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

## Classes

Expand Down Expand Up @@ -77,8 +77,11 @@ The following parameters are available in the `python` class:
* [`use_epel`](#use_epel)
* [`manage_scl`](#manage_scl)
* [`umask`](#umask)
* [`manage_gunicorn`](#manage_gunicorn)
* [`manage_python_package`](#manage_python_package)
* [`manage_venv_package`](#manage_venv_package)
* [`manage_pip_package`](#manage_pip_package)
* [`venv`](#venv)
* [`gunicorn_package_name`](#gunicorn_package_name)
* [`python_pips`](#python_pips)
* [`python_pyvenvs`](#python_pyvenvs)
Expand Down Expand Up @@ -175,22 +178,44 @@ The default umask for invoked exec calls.

Default value: ``undef``

##### <a name="manage_gunicorn"></a>`manage_gunicorn`

manage the state for package gunicorn

Default value: `$python::params::manage_gunicorn`

##### <a name="manage_python_package"></a>`manage_python_package`

Data type: `Boolean`


manage the state for package python

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

##### <a name="manage_pip_package"></a>`manage_pip_package`
##### <a name="manage_venv_package"></a>`manage_venv_package`

Data type: `Boolean`

manage the state for package venv

Default value: `$python::params::manage_venv_package`

##### <a name="manage_pip_package"></a>`manage_pip_package`

Data type: `Boolean`

manage the state for package pip

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

##### <a name="venv"></a>`venv`

Data type: `Python::Package::Ensure`



Default value: `$python::params::venv`

##### <a name="gunicorn_package_name"></a>`gunicorn_package_name`

Data type: `String[1]`
Expand Down Expand Up @@ -1112,7 +1137,7 @@ Default value: `1800`

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

A version type to match all valid loglevels for python
Match all valid loglevels for python

Alias of

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

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

A version type to match all valid package ensures for python
Match all valid package ensures for python

Alias of

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

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

A version type to match all valid provider for python
Match all valid provider for python

Alias of

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

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

A version type to match valid umask for python
Match valid umask for python

Alias of

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

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

A version type to match all valid versions for python
Match all valid versions for python

Alias of

Expand Down
6 changes: 6 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# @param use_epel to determine if the epel class is used.
# @param manage_scl Whether to manage core SCL packages or not.
# @param umask The default umask for invoked exec calls.
# @param manage_gunicorn manage the state for package gunicorn
# @param manage_python_package manage the state for package python
# @param manage_venv_package manage the state for package venv
# @param manage_pip_package manage the state for package pip
#
# @example install python from system python
# class { 'python':
Expand All @@ -37,9 +41,11 @@
Python::Version $version = '3',
Python::Package::Ensure $pip = $python::params::pip,
Python::Package::Ensure $dev = $python::params::dev,
Python::Package::Ensure $venv = $python::params::venv,
Python::Package::Ensure $gunicorn = $python::params::gunicorn,
Boolean $manage_gunicorn = $python::params::manage_gunicorn,
Boolean $manage_python_package = $python::params::manage_python_package,
Boolean $manage_venv_package = $python::params::manage_venv_package,
Boolean $manage_pip_package = $python::params::manage_pip_package,
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Python::Provider] $provider = $python::params::provider,
Expand Down
57 changes: 27 additions & 30 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,44 @@
'Suse' => "${python}-devel",
}

$pip_ensure = $python::pip ? {
true => 'present',
false => 'absent',
default => $python::pip,
}

$dev_ensure = $python::dev ? {
true => 'present',
false => 'absent',
default => $python::dev,
}

if $python::manage_python_package {
package { 'python':
ensure => $python::ensure,
name => $python,
}
}

if $python::manage_venv_package {
##
## CentOS has no extra package for venv
##
unless $facts['os']['name'] == 'CentOS' {
package { 'python-venv':
ensure => $python::venv,
name => "${python}-venv",
require => Package['python'],
}
}
}

case $python::provider {
'pip': {
if $python::manage_pip_package {
package { 'pip':
ensure => $pip_ensure,
ensure => $python::pip,
require => Package['python'],
}
}

if $pythondev {
package { 'python-dev':
ensure => $dev_ensure,
ensure => $python::dev,
name => $pythondev,
}
}

# Respect the $pip_ensure setting
unless $pip_ensure == 'absent' {
# 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

Expand Down Expand Up @@ -93,16 +94,16 @@

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

if $pip_ensure != 'absent' {
if $python::pip != 'absent' {
Package['scl-utils'] -> Exec['python-scl-pip-install']
}
}

package { "${python}-scldevel":
ensure => $dev_ensure,
ensure => $python::dev,
}

if $pip_ensure != 'absent' {
if $python::pip != 'absent' {
exec { 'python-scl-pip-install':
command => "${python::exec_prefix}easy_install pip",
path => ['/usr/bin', '/bin'],
Expand All @@ -126,17 +127,13 @@
tag => 'python-scl-package',
}

Package <| title == 'virtualenv' |> {
name => "${python}-python-virtualenv",
}

package { "${python}-scldevel":
ensure => $dev_ensure,
ensure => $python::dev,
tag => 'python-scl-package',
}

package { "${python}-python-pip":
ensure => $pip_ensure,
ensure => $python::pip,
tag => 'python-pip-package',
}

Expand Down Expand Up @@ -174,7 +171,7 @@
} else {
if $python::manage_pip_package {
package { 'python-pip':
ensure => $pip_ensure,
ensure => $python::pip,
require => Package['python'],
provider => 'yum',
}
Expand All @@ -183,7 +180,7 @@

if $pythondev {
package { 'python-dev':
ensure => $dev_ensure,
ensure => $python::dev,
name => $pythondev,
alias => $pythondev,
provider => 'yum',
Expand All @@ -193,14 +190,14 @@
default: {
if $python::manage_pip_package {
package { 'pip':
ensure => $pip_ensure,
ensure => $python::pip,
require => Package['python'],
}
}

if $pythondev {
package { 'python-dev':
ensure => $dev_ensure,
ensure => $python::dev,
name => $pythondev,
alias => $pythondev,
}
Expand All @@ -209,7 +206,7 @@
}

if $facts['os']['family'] == 'RedHat' {
if $pip_ensure != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) {
if $python::pip != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) {
require epel
}
}
Expand Down
3 changes: 2 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
$pip = 'present'
$dev = 'absent'
$virtualenv = 'absent'
$venv = 'absent'
$gunicorn = 'absent'
$manage_gunicorn = true
$manage_python_package = true
$manage_virtualenv_package = true
$manage_venv_package = true
$manage_pip_package = true
$provider = undef
$valid_versions = undef
Expand Down
17 changes: 5 additions & 12 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
$python_version_parts = split($python_version, '[.]')
$normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1])

# Debian splits the venv module into a seperate package
if ( $facts['os']['family'] == 'Debian') {
$python3_venv_package = "python${normalized_python_version}-venv"
ensure_packages($python3_venv_package)

Package[$python3_venv_package] -> File[$venv_dir]
}

# pyvenv is deprecated since 3.6 and will be removed in 3.8
if versioncmp($normalized_python_version, '3.6') >=0 {
$virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv"
Expand All @@ -71,10 +63,11 @@
}

file { $venv_dir:
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
ensure => directory,
owner => $owner,
group => $group,
mode => $mode,
require => Class['python::install'],
}

$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class { 'python':
version => '3',
pip => 'present',
dev => 'present',
venv => 'present',
}
EOS

Expand Down
5 changes: 5 additions & 0 deletions spec/acceptance/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class { 'python':
version => '3',
dev => 'present',
venv => 'present',
}
user { 'agent':
ensure => 'present',
Expand Down Expand Up @@ -42,6 +43,7 @@ class { 'python':
class { 'python':
version => '3',
dev => 'present',
venv => 'present',
}
user { 'agent':
ensure => 'present',
Expand Down Expand Up @@ -82,6 +84,7 @@ class { 'python':
class { 'python':
version => '3',
dev => 'present',
venv => 'present',
}
user { 'agent':
ensure => 'present',
Expand Down Expand Up @@ -119,6 +122,7 @@ class { 'python':
class { 'python':
version => '3',
dev => 'present',
venv => 'present',
}
user { 'agent':
ensure => 'present',
Expand Down Expand Up @@ -156,6 +160,7 @@ class { 'python':
class { 'python':
version => '3',
dev => 'present',
venv => 'present',
}
user { 'agent':
ensure => 'present',
Expand Down
Loading

0 comments on commit 96b887f

Please sign in to comment.