class PoisePython::PythonProviders::Base

Public Class Methods

default_inversion_options(node, new_resource) click to toggle source

Set default inversion options.

@api private

Calls superclass method
# File lib/poise_python/python_providers/base.rb, line 29
def self.default_inversion_options(node, new_resource)
  super.merge({
    get_pip_url: new_resource.get_pip_url,
    pip_version: new_resource.pip_version,
    setuptools_version: new_resource.setuptools_version,
    version: new_resource.version,
    virtualenv_version: new_resource.virtualenv_version,
    wheel_version: new_resource.wheel_version,
  })
end

Public Instance Methods

action_install() click to toggle source

The `install` action for the `python_runtime` resource.

@return [void]

# File lib/poise_python/python_providers/base.rb, line 43
def action_install
  # First inner converge for the Python install.
  notifying_block do
    install_python
  end
  # Second inner converge for the support tools. This is needed because
  # we run a python command to check if venv is available.
  notifying_block do
    install_pip
    install_setuptools
    install_wheel
    install_virtualenv
  end
end
action_uninstall() click to toggle source

The `uninstall` action for the `python_runtime` resource.

@abstract @return [void]

# File lib/poise_python/python_providers/base.rb, line 62
def action_uninstall
  notifying_block do
    uninstall_python
  end
end
python_binary() click to toggle source

The path to the `python` binary. This is an output property.

@abstract @return [String]

# File lib/poise_python/python_providers/base.rb, line 72
def python_binary
  raise NotImplementedError
end
python_environment() click to toggle source

The environment variables for this Python. This is an output property.

@return [Hash<String, String>]

# File lib/poise_python/python_providers/base.rb, line 79
def python_environment
  {}
end

Private Instance Methods

install_pip() click to toggle source

Install pip in to the Python runtime.

@return [void]

# File lib/poise_python/python_providers/base.rb, line 104
def install_pip
  pip_version_or_url = options[:pip_version]
  return unless pip_version_or_url
  # If there is a : in the version, use it as a URL and ignore the actual
  # URL option.
  if pip_version_or_url.is_a?(String) && pip_version_or_url.include?(':')
    pip_version = nil
    pip_url = pip_version_or_url
  else
    pip_version = pip_version_or_url
    pip_url = options[:get_pip_url]
  end
  Chef::Log.debug("[#{new_resource}] Installing pip #{pip_version || 'latest'}")
  # Install or bootstrap pip.
  python_runtime_pip new_resource.name do
    parent new_resource
    # If the version is `true`, don't pass it at all.
    version pip_version if pip_version.is_a?(String)
    get_pip_url pip_url
  end
end
install_python() click to toggle source

Install the Python runtime. Must be implemented by subclass.

@abstract @return [void]

# File lib/poise_python/python_providers/base.rb, line 89
def install_python
  raise NotImplementedError
end
install_setuptools() click to toggle source

Install setuptools in to the Python runtime. This is very similar to the {#install_wheel} and {#install_virtualenv} methods but they are kept separate for the benefit of subclasses being able to override them individually.

@return [void]

# File lib/poise_python/python_providers/base.rb, line 132
def install_setuptools
  # Captured because #options conflicts with Chef::Resource::Package#options.
  setuptools_version = options[:setuptools_version]
  return unless setuptools_version
  Chef::Log.debug("[#{new_resource}] Installing setuptools #{setuptools_version == true ? 'latest' : setuptools_version}")
  # Install setuptools via pip.
  python_package 'setuptools' do
    parent_python new_resource
    version setuptools_version if setuptools_version.is_a?(String)
  end
end
install_virtualenv() click to toggle source

Install virtualenv in to the Python runtime.

@return [void]

# File lib/poise_python/python_providers/base.rb, line 162
def install_virtualenv
  # Captured because #options conflicts with Chef::Resource::Package#options.
  virtualenv_version = options[:virtualenv_version]
  return unless virtualenv_version
  # Check if the venv module exists.
  cmd = poise_shell_out([python_binary, '-m', 'venv', '-h'], environment: python_environment)
  return unless cmd.error?
  Chef::Log.debug("[#{new_resource}] Installing virtualenv #{virtualenv_version == true ? 'latest' : virtualenv_version}")
  # Install virtualenv via pip.
  python_package 'virtualenv' do
    parent_python new_resource
    version virtualenv_version if virtualenv_version.is_a?(String)
  end
end
install_wheel() click to toggle source

Install wheel in to the Python runtime.

@return [void]

# File lib/poise_python/python_providers/base.rb, line 147
def install_wheel
  # Captured because #options conflicts with Chef::Resource::Package#options.
  wheel_version = options[:wheel_version]
  return unless wheel_version
  Chef::Log.debug("[#{new_resource}] Installing wheel #{wheel_version == true ? 'latest' : wheel_version}")
  # Install wheel via pip.
  python_package 'wheel' do
    parent_python new_resource
    version wheel_version if wheel_version.is_a?(String)
  end
end
uninstall_python() click to toggle source

Uninstall the Python runtime. Must be implemented by subclass.

@abstract @return [void]

# File lib/poise_python/python_providers/base.rb, line 97
def uninstall_python
  raise NotImplementedError
end