From 1fea7f60803fe313df172633dfe6976645085279 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Wed, 24 Feb 2016 10:36:00 +0200 Subject: [PATCH 1/5] python: Lint fixes, reindent --- python/manifests/init.pp | 128 +++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/python/manifests/init.pp b/python/manifests/init.pp index c60fa56..474265a 100644 --- a/python/manifests/init.pp +++ b/python/manifests/init.pp @@ -2,21 +2,21 @@ # class python { - package { "python": - ensure => installed, - notify => $::operatingsystem ? { - "openbsd" => Exec["python-links"], - default => undef, - }, - } + package { "python": + ensure => installed, + notify => $::operatingsystem ? { + "openbsd" => Exec["python-links"], + default => undef, + }, + } - exec { "python-links": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", - command => "pkg_info python | egrep '^[ ]*ln -sf' | sh", - user => "root", - group => "wheel", - refreshonly => true, - } + exec { "python-links": + path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + command => "pkg_info python | egrep '^[ ]*ln -sf' | sh", + user => "root", + group => "wheel", + refreshonly => true, + } } @@ -25,11 +25,11 @@ class python { # class python::python26 { - if $::operatingsystem in ["CentOS","RedHat"] and versioncmp($::operatingsystemrelease, "6") < 0 { - package { "python26": - ensure => installed, - } + if $::operatingsystem in ["CentOS","RedHat"] and versioncmp($::operatingsystemrelease, "6") < 0 { + package { "python26": + ensure => installed, } + } } @@ -38,14 +38,14 @@ class python::python26 { # class python::m2crypto { - package { "m2crypto": - ensure => installed, - name => $::operatingsystem ? { - "debian" => "python-m2crypto", - "ubuntu" => "python-m2crypto", - default => "m2crypto", - } + package { "m2crypto": + ensure => installed, + name => $::operatingsystem ? { + "debian" => "python-m2crypto", + "ubuntu" => "python-m2crypto", + default => "m2crypto", } + } } @@ -54,12 +54,12 @@ class python::m2crypto { # # === Parameters # -# $name: -# Source directory. -# $python: -# Python executable name. Defaults to python. -# $source: -# Source path to package archive. +# $name: +# Source directory. +# $python: +# Python executable name. Defaults to python. +# $source: +# Source path to package archive. # # === Sample usage # @@ -68,37 +68,37 @@ class python::m2crypto { # } # define python::setup::install( - $python="python", - $source=undef, + $python="python", + $source=undef, ) { - if $source { - $filename = basename($source) - file { "/usr/local/src/${filename}": - ensure => present, - mode => "0644", - owner => "root", - group => $::operatingsystem ? { - "openbsd" => "wheel", - default => "root", - }, - source => $source, - } - util::extract::tar { $name: - ensure => latest, - strip => "1", - source => "/usr/local/src/${filename}", - require => File["/usr/local/src/${filename}"], - before => Exec["python-setup-install-${name}"], - } + if $source { + $filename = basename($source) + file { "/usr/local/src/${filename}": + ensure => present, + mode => "0644", + owner => "root", + group => $::operatingsystem ? { + "openbsd" => "wheel", + default => "root", + }, + source => $source, } + util::extract::tar { $name: + ensure => latest, + strip => "1", + source => "/usr/local/src/${filename}", + require => File["/usr/local/src/${filename}"], + before => Exec["python-setup-install-${name}"], + } + } - exec { "python-setup-install-${name}": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", - cwd => $name, - command => "/bin/sh -c 'umask 022; ${python} setup.py install && mkdir -p build'", - creates => "${name}/build", - } + exec { "python-setup-install-${name}": + path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + cwd => $name, + command => "/bin/sh -c 'umask 022; ${python} setup.py install && mkdir -p build'", + creates => "${name}/build", + } } @@ -107,8 +107,8 @@ define python::setup::install( # # === Parameters # -# $name: -# File name to compile. +# $name: +# File name to compile. # # === Sample usage # @@ -116,9 +116,9 @@ define python::setup::install( # define python::compile() { - exec { "python -c \"import py_compile; py_compile.compile('${name}')\"": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", - onlyif => "test '${name}' -nt '${name}c'", - } + exec { "python -c \"import py_compile; py_compile.compile('${name}')\"": + path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + onlyif => "test '${name}' -nt '${name}c'", + } } From 4a30785106d81324a034c4629e7cae9cfdcb6337 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Wed, 24 Feb 2016 10:45:06 +0200 Subject: [PATCH 2/5] python: Lint fixes --- python/manifests/init.pp | 57 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/python/manifests/init.pp b/python/manifests/init.pp index 474265a..c933810 100644 --- a/python/manifests/init.pp +++ b/python/manifests/init.pp @@ -2,19 +2,19 @@ # class python { - package { "python": + package { 'python': ensure => installed, notify => $::operatingsystem ? { - "openbsd" => Exec["python-links"], + 'openbsd' => Exec['python-links'], default => undef, }, } - exec { "python-links": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", - command => "pkg_info python | egrep '^[ ]*ln -sf' | sh", - user => "root", - group => "wheel", + exec { 'python-links': + path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', + command => 'pkg_info python | egrep "^[ ]*ln -sf" | sh', + user => 'root', + group => 'wheel', refreshonly => true, } @@ -25,8 +25,8 @@ class python { # class python::python26 { - if $::operatingsystem in ["CentOS","RedHat"] and versioncmp($::operatingsystemrelease, "6") < 0 { - package { "python26": + if $::operatingsystem in ['CentOS','RedHat'] and versioncmp($::operatingsystemrelease, '6') < 0 { + package { 'python26': ensure => installed, } } @@ -38,13 +38,20 @@ class python::python26 { # class python::m2crypto { - package { "m2crypto": - ensure => installed, - name => $::operatingsystem ? { - "debian" => "python-m2crypto", - "ubuntu" => "python-m2crypto", - default => "m2crypto", + case $::operatingsystem { + 'debian','ubuntu': { + $package = 'python-m2crypto' } + 'openbsd': { + $package = 'py-M2Crypto' + } + default: { + $package = 'm2crypto' + } + } + + package { $package: + ensure => installed, } } @@ -63,12 +70,12 @@ class python::m2crypto { # # === Sample usage # -# python::setup::install { "/usr/local/src/moin-1.8.8": -# source => "puppet:///files/packages/moin-1.8.8.tar.gz", +# python::setup::install { '/usr/local/src/moin-1.8.8': +# source => 'puppet:///files/packages/moin-1.8.8.tar.gz', # } # define python::setup::install( - $python="python", + $python='python', $source=undef, ) { @@ -76,17 +83,17 @@ define python::setup::install( $filename = basename($source) file { "/usr/local/src/${filename}": ensure => present, - mode => "0644", - owner => "root", + mode => '0644', + owner => 'root', group => $::operatingsystem ? { - "openbsd" => "wheel", - default => "root", + 'openbsd' => 'wheel', + default => 'root', }, source => $source, } util::extract::tar { $name: ensure => latest, - strip => "1", + strip => '1', source => "/usr/local/src/${filename}", require => File["/usr/local/src/${filename}"], before => Exec["python-setup-install-${name}"], @@ -94,7 +101,7 @@ define python::setup::install( } exec { "python-setup-install-${name}": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', cwd => $name, command => "/bin/sh -c 'umask 022; ${python} setup.py install && mkdir -p build'", creates => "${name}/build", @@ -117,7 +124,7 @@ define python::setup::install( define python::compile() { exec { "python -c \"import py_compile; py_compile.compile('${name}')\"": - path => "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin", + path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', onlyif => "test '${name}' -nt '${name}c'", } From bed8b2e7774f756bc9c390c18c8d9d1a3b52c196 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Wed, 24 Feb 2016 15:21:40 +0200 Subject: [PATCH 3/5] python: Add support for installing packages with pip --- python/manifests/init.pp | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/python/manifests/init.pp b/python/manifests/init.pp index c933810..f572bb5 100644 --- a/python/manifests/init.pp +++ b/python/manifests/init.pp @@ -129,3 +129,67 @@ define python::compile() { } } + + +# Install pip. +# +class python::pip { + + case $::operatingsystem { + 'openbsd': { + $package = 'py-pip' + } + default: { + $package = 'python-pip' + } + } + + package { $package: + ensure => installed, + } + +} + + +# Install python package using pip. +# +# === Parameters +# +# $name: +# Package name. +# +# $source: +# Optional source path to package archive. +# +define python::pip::install($source=undef) { + + require python::pip + + if $source { + $filename = basename($name) + + file { "/usr/local/src/${filename}": + ensure => present, + mode => '0644', + owner => 'root', + group => $::operatingsystem ? { + 'openbsd' => 'wheel', + default => 'root', + }, + source => $source, + } + + exec { "pip-install-${filename}": + refreshonly => true, + path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', + command => "pip install --no-deps --no-index --upgrade /usr/local/src/${filename}", + subscribe => File["/usr/local/src/${filename}"], + } + } else { + package { $name: + ensure => installed, + provider => 'pip', + } + } + +} From f8a6139159728a552386488b2de03784409cc0d5 Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Fri, 26 Feb 2016 12:17:41 +0200 Subject: [PATCH 4/5] python: Add comment for pip-install exec --- python/manifests/init.pp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/manifests/init.pp b/python/manifests/init.pp index f572bb5..4287ef6 100644 --- a/python/manifests/init.pp +++ b/python/manifests/init.pp @@ -179,6 +179,9 @@ define python::pip::install($source=undef) { source => $source, } + # Use exec to install from local files, pip package provider does not + # support extra arguments. --no-deps --no-index stops pip from accessing + # pypi. exec { "pip-install-${filename}": refreshonly => true, path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', From 20938ae27bb9a73a8633ba25f9aadcebd6e6c9bf Mon Sep 17 00:00:00 2001 From: Ossi Salmi Date: Mon, 29 Feb 2016 16:48:44 +0200 Subject: [PATCH 5/5] python: --no-deps for pip should not be necessary --- python/manifests/init.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/manifests/init.pp b/python/manifests/init.pp index 4287ef6..fed9d0c 100644 --- a/python/manifests/init.pp +++ b/python/manifests/init.pp @@ -180,12 +180,12 @@ define python::pip::install($source=undef) { } # Use exec to install from local files, pip package provider does not - # support extra arguments. --no-deps --no-index stops pip from accessing + # support extra arguments. --no-index stops pip from accessing # pypi. exec { "pip-install-${filename}": refreshonly => true, path => '/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin', - command => "pip install --no-deps --no-index --upgrade /usr/local/src/${filename}", + command => "pip install --no-index --upgrade /usr/local/src/${filename}", subscribe => File["/usr/local/src/${filename}"], } } else {