class PoisePython::Resources::PythonVirtualenv::Provider

The default provider for `python_virtualenv`.

@see Resource @provides python_virtualenv

Public Instance Methods

python_binary() click to toggle source
# File lib/poise_python/resources/python_virtualenv.rb, line 100
def python_binary
  if node.platform_family?('windows')
    ::File.join(new_resource.path, 'Scripts', 'python.exe')
  else
    ::File.join(new_resource.path, 'bin', 'python')
  end
end
python_environment() click to toggle source
# File lib/poise_python/resources/python_virtualenv.rb, line 108
def python_environment
  if new_resource.parent_python
    new_resource.parent_python.python_environment
  else
    {}
  end
end

Private Instance Methods

create_virtualenv(driver) click to toggle source

Create a virtualenv using virtualenv or venv.

@param driver [Array<String>] Command snippet to actually make it. @return [void]

# File lib/poise_python/resources/python_virtualenv.rb, line 153
def create_virtualenv(driver)
  cmd = %w{-m} + driver
  cmd << '--system-site-packages' if new_resource.system_site_packages
  cmd << new_resource.path
  python_shell_out!(cmd, environment: {
    # Use the environment variables to cope with older virtualenv not
    # supporting --no-wheel. The env var will be ignored if unsupported.
    'VIRTUALENV_NO_PIP' => '1',
    'VIRTUALENV_NO_SETUPTOOLS' => '1',
    'VIRTUALENV_NO_WHEEL' => '1',
  }, group: new_resource.group, user: new_resource.user)
end
install_python() click to toggle source
# File lib/poise_python/resources/python_virtualenv.rb, line 118
def install_python
  return if ::File.exist?(python_binary)

  cmd = python_shell_out(%w{-m venv -h})
  if cmd.error?
    converge_by("Creating virtualenv at #{new_resource.path}") do
      create_virtualenv(%w{virtualenv})
    end
  else
    converge_by("Creating venv at #{new_resource.path}") do
      use_withoutpip = cmd.stdout.include?('--without-pip')
      create_virtualenv(use_withoutpip ? %w{venv --without-pip} : %w{venv})
    end
  end
end
install_virtualenv() click to toggle source

Don't install virtualenv inside virtualenv.

@api private @return [void]

# File lib/poise_python/resources/python_virtualenv.rb, line 145
def install_virtualenv
  # This space left intentionally blank.
end
uninstall_python() click to toggle source
# File lib/poise_python/resources/python_virtualenv.rb, line 134
def uninstall_python
  directory new_resource.path do
    action :delete
    recursive true
  end
end