diff modules/python/manifests/install.pp @ 387:66c075c5f54a

Update to newer Python module
author IBBoard <dev@ibboard.co.uk>
date Mon, 03 Jan 2022 17:13:06 +0000
parents c42fb28cff86
children adf6fe9bbc17
line wrap: on
line diff
--- a/modules/python/manifests/install.pp	Mon Jan 03 17:09:39 2022 +0000
+++ b/modules/python/manifests/install.pp	Mon Jan 03 17:13:06 2022 +0000
@@ -5,7 +5,6 @@
 #  include python::install
 #
 class python::install {
-
   $python = $python::version ? {
     'system'                 => 'python',
     'pypy'                   => 'pypy',
@@ -16,11 +15,12 @@
   }
 
   $pythondev = $facts['os']['family'] ? {
-    'AIX'    => "${python}-devel",
-    'RedHat' => "${python}-devel",
-    'Debian' => "${python}-dev",
-    'Suse'   => "${python}-devel",
-    'Gentoo' => undef,
+    'AIX'     => "${python}-devel",
+    'Debian'  => "${python}-dev",
+    'FreeBSD' => undef,
+    'Gentoo'  => undef,
+    'RedHat'  => "${python}-devel",
+    'Suse'    => "${python}-devel",
   }
 
   $pip_ensure = $python::pip ? {
@@ -29,44 +29,26 @@
     default => $python::pip,
   }
 
-  $venv_ensure = $python::virtualenv ? {
+  $dev_ensure = $python::dev ? {
     true    => 'present',
     false   => 'absent',
-    default => $python::virtualenv,
+    default => $python::dev,
   }
 
-  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.
-      notify { 'Python virtual environment is dependent on python dev': }
+  if $python::manage_python_package {
+    package { 'python':
+      ensure => $python::ensure,
+      name   => $python,
     }
-  } else {
-    $dev_ensure = $python::dev ? {
-      true    => 'present',
-      false   => 'absent',
-      default => $python::dev,
-    }
-  }
-
-  package { 'python':
-    ensure => $python::ensure,
-    name   => $python,
-  }
-
-  package { 'virtualenv':
-    ensure  => $venv_ensure,
-    name    => "${python}-virtualenv",
-    require => Package['python'],
   }
 
   case $python::provider {
     'pip': {
-
-      package { 'pip':
-        ensure  => $pip_ensure,
-        require => Package['python'],
+      if $python::manage_pip_package {
+        package { 'pip':
+          ensure  => $pip_ensure,
+          require => Package['python'],
+        }
       }
 
       if $pythondev {
@@ -79,7 +61,7 @@
       # 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 |>
 
@@ -87,18 +69,6 @@
           name     => 'pip',
           provider => 'pip',
         }
-        if $pythondev {
-          Package <| title == 'virtualenv' |> {
-            name     => 'virtualenv',
-            provider => 'pip',
-            require  => Package['python-dev'],
-          }
-        } else {
-          Package <| title == 'virtualenv' |> {
-            name     => 'virtualenv',
-            provider => 'pip',
-          }
-        }
       }
     }
     'scl': {
@@ -115,6 +85,7 @@
           ensure => $install_scl_repo_package,
           before => Package['scl-utils'],
         }
+
         package { 'scl-utils':
           ensure => 'present',
           before => Package['python'],
@@ -127,14 +98,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",
@@ -147,6 +114,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',
@@ -177,8 +145,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'
@@ -202,15 +169,18 @@
         'AIX': {
           if String($python::version) =~ /^python3/ {
             class { 'python::pip::bootstrap':
-                    version => 'pip3',
+              version => 'pip3',
             }
           } else {
-            package { 'python-pip':
-              ensure   => $pip_ensure,
-              require  => Package['python'],
-              provider => 'yum',
+            if $python::manage_pip_package {
+              package { 'python-pip':
+                ensure   => $pip_ensure,
+                require  => Package['python'],
+                provider => 'yum',
+              }
             }
           }
+
           if $pythondev {
             package { 'python-dev':
               ensure   => $dev_ensure,
@@ -219,13 +189,15 @@
               provider => 'yum',
             }
           }
-
         }
         default: {
-          package { 'pip':
-            ensure  => $pip_ensure,
-            require => Package['python'],
+          if $python::manage_pip_package {
+            package { 'pip':
+              ensure  => $pip_ensure,
+              require => Package['python'],
+            }
           }
+
           if $pythondev {
             package { 'python-dev':
               ensure => $dev_ensure,
@@ -233,57 +205,46 @@
               alias  => $pythondev,
             }
           }
-
         }
       }
 
-      case $facts['os']['family'] {
-        'RedHat': {
-          if $pip_ensure != 'absent' {
-            if $python::use_epel == true {
-              include 'epel'
-              Class['epel'] -> Package['pip']
-            }
-          }
-          if ($venv_ensure != 'absent') and ($facts['os']['release']['full'] =~ /^6/) {
-            if $python::use_epel == true {
-              include 'epel'
-              Class['epel'] -> Package['virtualenv']
-            }
-          }
-
-          $virtualenv_package = "${python}-virtualenv"
-        }
-        'Debian': {
-          if fact('lsbdistcodename') == 'trusty' {
-            $virtualenv_package = 'python-virtualenv'
-          } else {
-            $virtualenv_package = 'virtualenv'
-          }
-        }
-        'Gentoo': {
-          $virtualenv_package = 'virtualenv'
-        }
-        default: {
-          $virtualenv_package = 'python-virtualenv'
+      if $facts['os']['family'] == 'RedHat' {
+        if $pip_ensure != 'absent' and $python::use_epel and ($python::manage_pip_package or $python::manage_python_package) {
+          require epel
         }
       }
 
       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'], '8') >= 0) {
+        $pip_category = undef
+        $pip_package  = 'python3-pip'
+        $pip_provider = pip3
       } 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'] == 'FreeBSD' {
+        $pip_category = undef
+        $pip_package  = "py${python::version}-pip"
+        $pip_provider = 'pip'
       } elsif $facts['os']['family'] == 'Gentoo' {
         $pip_category = 'dev-python'
-        $pip_package = 'pip'
+        $pip_package  = 'pip'
         $pip_provider = 'pip'
+      } elsif ($facts['os']['name'] == 'Ubuntu') and (versioncmp($facts['os']['release']['major'], '20.04') >= 0) {
+        $pip_category = undef
+        $pip_package  = 'python3-pip'
+        $pip_provider = 'pip3'
+      } elsif ($facts['os']['name'] == 'Debian') and (versioncmp($facts['os']['release']['major'], '11') >= 0) {
+        $pip_category = undef
+        $pip_package  = 'python3-pip'
+        $pip_provider = 'pip3'
       } else {
         $pip_category = undef
-        $pip_package = 'python-pip'
+        $pip_package  = 'python-pip'
         $pip_provider = 'pip'
       }
 
@@ -291,14 +252,6 @@
         name     => $pip_package,
         category => $pip_category,
       }
-
-      Python::Pip <| |> {
-        pip_provider => $pip_provider,
-      }
-
-      Package <| title == 'virtualenv' |> {
-        name => $virtualenv_package,
-      }
     }
   }