Skip to content

Commit

Permalink
Merge pull request #580 from crazymind1337/general_linting_and_syntax
Browse files Browse the repository at this point in the history
General linting/indent/syntax
  • Loading branch information
igalic authored Nov 18, 2020
2 parents 4c44d18 + 7520a85 commit 5e09d61
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 426 deletions.
449 changes: 241 additions & 208 deletions REFERENCE.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Python::Virtualenv <| |> -> Python::Pip <| |>

if $python::manage_gunicorn {
if $python::gunicorn != 'absent' {
unless $python::gunicorn == 'absent' {
Class['python::install'] -> Python::Gunicorn <| |>

Python::Gunicorn <| |> ~> Service['gunicorn']
Expand Down
10 changes: 5 additions & 5 deletions manifests/dotfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#
define python::dotfile (
Enum['absent', 'present'] $ensure = 'present',
String[1] $filename = $title,
String[1] $owner = 'root',
String[1] $group = 'root',
Stdlib::Filemode $mode = '0644',
Hash $config = {},
Stdlib::Absolutepath $filename = $title,
String[1] $owner = 'root',
String[1] $group = 'root',
Stdlib::Filemode $mode = '0644',
Hash $config = {},
) {
$parent_dir = dirname($filename)

Expand Down
41 changes: 21 additions & 20 deletions manifests/gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@
# }
#
define python::gunicorn (
Stdlib::Absolutepath $dir,
Enum['present', 'absent'] $ensure = present,
$config_dir = '/etc/gunicorn.d',
$manage_config_dir = false,
$virtualenv = false,
Enum['wsgi', 'django'] $mode = 'wsgi',
$bind = false,
$environment = false,
$owner = 'www-data',
$group = 'www-data',
$appmodule = 'app:app',
$osenv = false,
$timeout = 30,
$workers = false,
$access_log_format = false,
$accesslog = false,
$errorlog = false,
Enum['debug', 'info', 'warning', 'error', 'critical'] $log_level = 'error',
$template = 'python/gunicorn.erb',
$args = [],
Stdlib::Absolutepath $dir,
Enum['present', 'absent'] $ensure = present,
Stdlib::Absolutepath $config_dir = '/etc/gunicorn.d',
Booloean $manage_config_dir = false,
Variant[Boolean,Stdlib::Absolutepath] $virtualenv = false,
Enum['wsgi', 'django'] $mode = 'wsgi',
Variant[String[1],Boolean] $bind = false,
Variant[String[1],Boolean] $environment = false,
String[1] $owner = 'www-data',
String[1] $group = 'www-data',
String[1] $appmodule = 'app:app',
Variant[Boolean,Hash] $osenv = false,
Integer $timeout = 30,
Variant[Boolean,Integer] $workers = false,
Variant[Boolean,String[1]] $access_log_format = false,
Variant[Boolean,Stdlib::Absolutepath] $accesslog = false,
Variant[Boolean,Stdlib::Absolutepath] $errorlog = false,
Python::Loglevel $log_level = 'error',
String[1] $template = 'python/gunicorn.erb',
Array $args = [],
) {
if $manage_config_dir {
file { $config_dir:
Expand All @@ -62,6 +62,7 @@
owner => 'root',
group => 'root',
}

file { "${config_dir}/${name}":
ensure => $ensure,
mode => '0644',
Expand Down
62 changes: 25 additions & 37 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,45 @@
# }
#
class python (
Enum['absent', 'present', 'latest'] $ensure = $python::params::ensure,
$version = $python::params::version,
Enum['absent', 'present', 'latest'] $pip = $python::params::pip,
Enum['absent', 'present', 'latest'] $dev = $python::params::dev,
Enum['absent', 'present', 'latest'] $virtualenv = $python::params::virtualenv,
Enum['absent', 'present', 'latest'] $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_pip_package = $python::params::manage_pip_package,
$gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']] $provider = $python::params::provider,
$valid_versions = $python::params::valid_versions,
Hash $python_pips = {},
Hash $python_virtualenvs = {},
Hash $python_pyvenvs = {},
Hash $python_requirements = {},
Hash $python_dotfiles = {},
Boolean $use_epel = $python::params::use_epel,
$rhscl_use_public_repository = $python::params::rhscl_use_public_repository,
Stdlib::Httpurl $anaconda_installer_url = $python::params::anaconda_installer_url,
Stdlib::Absolutepath $anaconda_install_path = $python::params::anaconda_install_path,
Boolean $manage_scl = $python::params::manage_scl,
Optional[Pattern[/[0-7]{1,4}/]] $umask = undef,
Python::Package::Ensure $ensure = $python::params::ensure,
Python::Version $version = $python::params::version,
Python::Package::Ensure $pip = $python::params::pip,
Python::Package::Ensure $dev = $python::params::dev,
Python::Package::Ensure $virtualenv = $python::params::virtualenv,
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_pip_package = $python::params::manage_pip_package,
String[1] $gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Python::Provider] $provider = $python::params::provider,
Hash $python_pips = {},
Hash $python_virtualenvs = {},
Hash $python_pyvenvs = {},
Hash $python_requirements = {},
Hash $python_dotfiles = {},
Boolean $use_epel = $python::params::use_epel,
Boolean $rhscl_use_public_repository = $python::params::rhscl_use_public_repository,
Stdlib::Httpurl $anaconda_installer_url = $python::params::anaconda_installer_url,
Stdlib::Absolutepath $anaconda_install_path = $python::params::anaconda_install_path,
Boolean $manage_scl = $python::params::manage_scl,
Optional[Python::Umask] $umask = undef,
) inherits python::params {
$exec_prefix = $provider ? {
'scl' => "/usr/bin/scl enable ${version} -- ",
'rhscl' => "/usr/bin/scl enable ${version} -- ",
default => '',
}

unless $version =~ Pattern[/\A(python)?[0-9](\.?[0-9])*/,
/\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/] {
fail("version needs to be pypy, system or a version string like '36', '3.6' or 'python3.6' )")
}

# Module compatibility check
$compatible = ['Debian', 'RedHat', 'Suse', 'Gentoo', 'AIX']
if ! ($facts['os']['family'] in $compatible) {
fail("Module is not compatible with ${facts['os']['name']}")
}

contain python::install
contain python::config

Class['python::install']
-> Class['python::config']

# Set default umask.
if $umask != undef {
Exec { umask => $umask }
exec { default:
umask => $umask
}

# Allow hiera configuration of python resources
Expand Down
41 changes: 18 additions & 23 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

if $venv_ensure == 'present' {
$dev_ensure = 'present'

unless $python::dev {
# Error: python2-devel is needed by (installed) python-virtualenv-15.1.0-2.el7.noarch
# Python dev is required for virtual environment, but python environment is not required for python dev.
Expand Down Expand Up @@ -83,14 +84,15 @@
# Respect the $pip_ensure setting
unless $pip_ensure == 'absent' {
# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
include 'python::pip::bootstrap'
include python::pip::bootstrap

Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>

Package <| title == 'pip' |> {
name => 'pip',
provider => 'pip',
}

if $pythondev {
Package <| title == 'virtualenv' |> {
name => 'virtualenv',
Expand Down Expand Up @@ -119,6 +121,7 @@
ensure => $install_scl_repo_package,
before => Package['scl-utils'],
}

package { 'scl-utils':
ensure => 'present',
before => Package['python'],
Expand All @@ -131,14 +134,10 @@
}
}

# This gets installed as a dependency anyway
# package { "${python::version}-python-virtualenv":
# ensure => $venv_ensure,
# require => Package['scl-utils'],
# }
package { "${python}-scldevel":
ensure => $dev_ensure,
}

if $pip_ensure != 'absent' {
exec { 'python-scl-pip-install':
command => "${python::exec_prefix}easy_install pip",
Expand All @@ -151,6 +150,7 @@
# rhscl is RedHat SCLs from softwarecollections.org
if $python::rhscl_use_public_repository {
$scl_package = "rhscl-${python::version}-epel-${facts['os']['release']['major']}-${facts['os']['architecture']}"

package { $scl_package:
source => "https://www.softwarecollections.org/en/scls/rhscl/${python::version}/epel-${facts['os']['release']['major']}-${facts['os']['architecture']}/download/${scl_package}.noarch.rpm",
provider => 'rpm',
Expand Down Expand Up @@ -181,8 +181,7 @@
-> Package <| tag == 'python-scl-package' |>
}

Package <| tag == 'python-scl-package' |>
-> Package <| tag == 'python-pip-package' |>
Package <| tag == 'python-scl-package' |> -> Package <| tag == 'python-pip-package' |>
}
'anaconda': {
$installer_path = '/var/tmp/anaconda_installer.sh'
Expand Down Expand Up @@ -217,6 +216,7 @@
}
}
}

if $pythondev {
package { 'python-dev':
ensure => $dev_ensure,
Expand All @@ -233,6 +233,7 @@
require => Package['python'],
}
}

if $pythondev {
package { 'python-dev':
ensure => $dev_ensure,
Expand All @@ -245,18 +246,12 @@

case $facts['os']['family'] {
'RedHat': {
if $pip_ensure != 'absent' {
if $python::use_epel == true {
include 'epel'
if $python::manage_pip_package { Class['epel'] -> Package['pip'] }
if $python::manage_python_package { Class['epel'] -> Package['python'] }
}
if $pip_ensure != '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/) {
if $python::use_epel == true {
include 'epel'
Class['epel'] -> Package['virtualenv']
}

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

$virtualenv_package = "${python}-virtualenv"
Expand All @@ -278,19 +273,19 @@

if String($python::version) =~ /^python3/ {
$pip_category = undef
$pip_package = "${python}-pip"
$pip_package = "${python}-pip"
$pip_provider = $python.regsubst(/^.*python3\.?/,'pip3.').regsubst(/\.$/,'')
} elsif ($facts['os']['family'] == 'RedHat') and (versioncmp($facts['os']['release']['major'], '7') >= 0) {
$pip_category = undef
$pip_package = 'python2-pip'
$pip_package = 'python2-pip'
$pip_provider = pip2
} elsif $facts['os']['family'] == 'Gentoo' {
$pip_category = 'dev-python'
$pip_package = 'pip'
$pip_package = 'pip'
$pip_provider = 'pip'
} else {
$pip_category = undef
$pip_package = 'python-pip'
$pip_package = 'python-pip'
$pip_provider = 'pip'
}

Expand Down
53 changes: 26 additions & 27 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@
# The python Module default configuration settings.
#
class python::params {
$ensure = 'present'
$version = 'system'
$pip = 'present'
$dev = 'absent'
$virtualenv = 'absent'
$gunicorn = 'absent'
$manage_gunicorn = true
$manage_python_package = true
$manage_virtualenv_package = true
$manage_pip_package = true
$provider = undef
$valid_versions = undef
$manage_scl = true
# Module compatibility check
unless $facts['os']['family'] in ['Debian', 'RedHat', 'Suse', 'Gentoo', 'AIX',] {
fail("Module is not compatible with ${facts['os']['name']}")
}

$ensure = 'present'
$version = 'system'
$pip = 'present'
$dev = 'absent'
$virtualenv = 'absent'
$gunicorn = 'absent'
$manage_gunicorn = true
$manage_python_package = true
$manage_virtualenv_package = true
$manage_pip_package = true
$provider = undef
$valid_versions = undef
$manage_scl = true
$rhscl_use_public_repository = true
$anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh'
$anaconda_install_path = '/opt/python'

if $facts['os']['family'] == 'RedHat' {
if $facts['os']['name'] != 'Fedora' {
$use_epel = true
} else {
$use_epel = false
}
if $facts['os']['family'] == 'RedHat' and $facts['os']['name'] != 'Fedora' {
$use_epel = true
} else {
$use_epel = false
$use_epel = false
}

$group = $facts['os']['family'] ? {
Expand All @@ -34,17 +38,12 @@
}

$pip_lookup_path = $facts['os']['family'] ? {
'AIX' => ['/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/'],
default => ['/bin', '/usr/bin', '/usr/local/bin']
'AIX' => ['/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/',],
default => ['/bin', '/usr/bin', '/usr/local/bin',]
}

$gunicorn_package_name = $facts['os']['family'] ? {
'RedHat' => 'python-gunicorn',
default => 'gunicorn',
}

$rhscl_use_public_repository = true

$anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh'
$anaconda_install_path = '/opt/python'
}
Loading

0 comments on commit 5e09d61

Please sign in to comment.