class PoisePython::Resources::PipRequirements::Provider

The default provider for `pip_requirements`.

@see Resource @provides pip_requirements

Public Instance Methods

action_install() click to toggle source

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

@return [void]

# File lib/poise_python/resources/pip_requirements.rb, line 93
def action_install
  install_requirements(upgrade: false)
end
action_upgrade() click to toggle source

The `upgrade` action for the `pip_requirements` resource.

@return [void]

# File lib/poise_python/resources/pip_requirements.rb, line 100
def action_upgrade
  install_requirements(upgrade: true)
end

Private Instance Methods

install_requirements(upgrade: false) click to toggle source

Run an install –requirements command and parse the output.

@param upgrade [Boolean] If we should use the –upgrade flag. @return [void]

# File lib/poise_python/resources/pip_requirements.rb, line 110
def install_requirements(upgrade: false)
  if new_resource.options
    # Use a string because we have some options.
    cmd = '-m pip.__main__ install'
    cmd << ' --upgrade' if upgrade
    cmd << " #{new_resource.options}"
    cmd << " --requirement #{Shellwords.escape(requirements_path)}"
  else
    # No options, use an array to be slightly faster.
    cmd = %w{-m pip.__main__ install}
    cmd << '--upgrade' if upgrade
    cmd << '--requirement'
    cmd << requirements_path
  end
  output = python_shell_out!(cmd, user: new_resource.user, group: new_resource.group, cwd: new_resource.cwd).stdout
  if output.include?('Successfully installed')
    new_resource.updated_by_last_action(true)
  end
end
requirements_path() click to toggle source

Find the true path to the requirements file.

@return [String]

# File lib/poise_python/resources/pip_requirements.rb, line 133
def requirements_path
  if ::File.directory?(new_resource.path)
    ::File.join(new_resource.path, 'requirements.txt')
  else
    new_resource.path
  end
end