Skip to content

Commit

Permalink
Add python-venv installation
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymind1337 committed Dec 15, 2020
1 parent d9c51a8 commit 342788a
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 43 deletions.
48 changes: 35 additions & 13 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

### 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::Version`](#pythonversion): A version type to match all valid versions 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::Version`](#pythonversion): Match all valid versions for python

## Classes

Expand Down Expand Up @@ -116,6 +116,14 @@ Desired installation state for the virtualenv package

Default value: `$python::params::virtualenv`

##### `venv`

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

Desired installation state for the virtualenv package

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

##### `gunicorn`

Data type: `Python::Package::Ensure`
Expand Down Expand Up @@ -164,27 +172,41 @@ The default umask for invoked exec calls.

Default value: ``undef``

##### `manage_gunicorn`

manage the state for package gunicorn

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

##### `manage_python_package`

Data type: `Boolean`


manage the state for package python

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

##### `manage_virtualenv_package`

Data type: `Boolean`


manage the state for package virtualenv

Default value: `$python::params::manage_virtualenv_package`

##### `manage_pip_package`
##### `manage_venv_package`

Data type: `Boolean`

manage the state for package venv

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

##### `manage_pip_package`

Data type: `Boolean`

manage the state for package pip

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

Expand Down Expand Up @@ -1202,31 +1224,31 @@ Default value: ``undef``

### `Python::Loglevel`

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

Alias of `Enum['debug', 'info', 'warning', 'error', 'critical']`

### `Python::Package::Ensure`

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

Alias of `Enum['absent', 'present', 'latest']`

### `Python::Provider`

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

Alias of `Enum['pip', 'scl', 'rhscl', 'anaconda', '']`

### `Python::Umask`

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

Alias of `Pattern[/[0-7]{1,4}/]`

### `Python::Version`

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

Alias of `Pattern[/\A(python)?[0-9](\.?[0-9])*/, /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/]`

8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
# @param pip Desired installation state for the python-pip package.
# @param dev Desired installation state for the python-dev package.
# @param virtualenv Desired installation state for the virtualenv package
# @param venv Desired installation state for the virtualenv package
# @param gunicorn Desired installation state for Gunicorn.
# @param manage_gunicorn Allow Installation / Removal of Gunicorn.
# @param provider What provider to use for installation of the packages, except gunicorn and Python itself.
# @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_virtualenv_package manage the state for package virtualenv
# @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 @@ -41,10 +47,12 @@
Python::Package::Ensure $pip = $python::params::pip,
Python::Package::Ensure $dev = $python::params::dev,
Python::Package::Ensure $virtualenv = $python::params::virtualenv,
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_virtualenv_package = $python::params::manage_virtualenv_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
44 changes: 20 additions & 24 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,7 @@
'Gentoo' => undef,
}

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

$venv_ensure = $python::virtualenv ? {
true => 'present',
false => 'absent',
default => $python::virtualenv,
}

if $venv_ensure == 'present' {
if $python::virtualenv == 'present' {
$dev_ensure = 'present'

unless $python::dev {
Expand All @@ -59,17 +47,25 @@

if $python::manage_virtualenv_package {
package { 'virtualenv':
ensure => $venv_ensure,
ensure => $python::virtualenv,
name => "${python}-virtualenv",
require => Package['python'],
}
}

if $python::manage_venv_package {
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'],
}
}
Expand All @@ -81,8 +77,8 @@
}
}

# 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 @@ -129,7 +125,7 @@

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

if $pip_ensure != 'absent' {
if $python::pip != 'absent' {
Package['scl-utils'] -> Exec['python-scl-pip-install']
}
}
Expand All @@ -138,7 +134,7 @@
ensure => $dev_ensure,
}

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 Down Expand Up @@ -172,7 +168,7 @@
}

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

Expand Down Expand Up @@ -210,7 +206,7 @@
} else {
if $python::manage_pip_package {
package { 'python-pip':
ensure => $pip_ensure,
ensure => $python::pip,
require => Package['python'],
provider => 'yum',
}
Expand All @@ -229,7 +225,7 @@
default: {
if $python::manage_pip_package {
package { 'pip':
ensure => $pip_ensure,
ensure => $python::pip,
require => Package['python'],
}
}
Expand All @@ -246,11 +242,11 @@

case $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
}

if $venv_ensure != 'absent' and $facts['os']['release']['full'] =~ /^6/ and $python::use_epel {
if $python::virtualenv != 'absent' and $facts['os']['release']['full'] =~ /^6/ and $python::use_epel {
require epel
}

Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
$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
4 changes: 3 additions & 1 deletion spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
{
manage_python_package: false,
manage_virtualenv_package: false,
manage_pip_package: false
manage_pip_package: false,
manage_venv_package: false
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('python') }
it { is_expected.not_to contain_package('virtualenv') }
it { is_expected.not_to contain_package('pip') }
it { is_expected.not_to contain_package('python-venv') }
end

case facts[:os]['family']
Expand Down
2 changes: 1 addition & 1 deletion types/loglevel.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary A version type to match all valid loglevels for python
# @summary Match all valid loglevels for python
#
type Python::Loglevel = Enum['debug', 'info', 'warning', 'error', 'critical']
2 changes: 1 addition & 1 deletion types/package/ensure.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary A version type to match all valid package ensures for python
# @summary Match all valid package ensures for python
#
type Python::Package::Ensure = Enum['absent', 'present', 'latest']
2 changes: 1 addition & 1 deletion types/provider.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary A version type to match all valid provider for python
# @summary Match all valid provider for python
#
type Python::Provider = Enum['pip', 'scl', 'rhscl', 'anaconda', '']
2 changes: 1 addition & 1 deletion types/umask.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @summary A version type to match valid umask for python
# @summary Match valid umask for python
#
type Python::Umask = Pattern[/[0-7]{1,4}/]
2 changes: 1 addition & 1 deletion types/version.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @summary A version type to match all valid versions for python
# @summary Match all valid versions for python
#
type Python::Version = Pattern[
/\A(python)?[0-9](\.?[0-9])*/,
Expand Down

0 comments on commit 342788a

Please sign in to comment.