#
# Cookbook:: irrigate-python
# Recipe:: poetry
#
# All rights reserved - Do Not Redistribute
#

if platform_family?('rhel')
  installer_url   = node['poetry']['installer_script_url']
  poetry_home     = node['poetry']['poetry_home']
  poetry_version  = node['poetry']['poetry_version']
  python_path     = node['python']['python_path']

  # Create poetry directory to install in
  directory poetry_home do
    owner 'root'
    group 'root'
    mode '0755'
  end

  # Copy get-poetry.py script and run install_poetry
  remote_file '/usr/local/get-poetry.py' do
    source installer_url
    owner 'root'
    group 'root'
    action :create
  end

  # Execute get-poetry.py, if the lib directory doesn't exist.
  execute 'install_poetry' do
    command "#{python_path} /usr/local/get-poetry.py -f --version #{poetry_version}"
    environment('POETRY_HOME' => poetry_home)
    action :run
  end

  # chmod the poetry binary to allow execute across all users
  file "#{poetry_home}/bin/poetry" do
    mode '0755'
  end

  # Simplest way to avoid munging PATH
  link '/usr/local/bin/poetry' do
    to "#{poetry_home}/bin/poetry"
  end

elsif platform_family?('debian')
  package 'python3-poetry'
end
