Sha256: 92e1afcf1f8405d1a5da2302273cef1c47cf9b38cf45003c1a8639678937ff8c

Contents?: true

Size: 1.55 KB

Versions: 2

Compression:

Stored size: 1.55 KB

Contents

namespace :pyenv do
  task :validate do
    on release_roles(fetch(:pyenv_roles)) do |host|
      pyenv_python = fetch(:pyenv_python)
      if pyenv_python.nil?
        info 'pyenv: pyenv_python is not set; python version will be defined by the remote hosts via pyenv'
      end

      # don't check the pyenv_python_dir if :pyenv_python is not set (it will always fail)
      unless pyenv_python.nil? || (test "[ -d #{fetch(:pyenv_python_dir)} ]")
        warn "pyenv: #{pyenv_python} is not installed or not found in #{fetch(:pyenv_python_dir)} on #{host}"
        exit 1
      end
    end
  end

  task :map_bins do
    SSHKit.config.default_env.merge!(pyenv_root: fetch(:pyenv_path), pyenv_version: fetch(:pyenv_python))
    pyenv_prefix = fetch(:pyenv_prefix, proc { "#{fetch(:pyenv_path)}/bin/pyenv exec" })
    SSHKit.config.command_map[:pyenv] = "#{fetch(:pyenv_path)}/bin/pyenv"

    fetch(:pyenv_map_bins).uniq.each do |command|
      SSHKit.config.command_map.prefix[command.to_sym].unshift(pyenv_prefix)
    end
  end
end

Capistrano::DSL.stages.each do |stage|
  after stage, 'pyenv:validate'
  after stage, 'pyenv:map_bins'
end

namespace :load do
  task :defaults do
    set :pyenv_path, -> {
      pyenv_path = fetch(:pyenv_custom_path)
      pyenv_path ||
        if fetch(:pyenv_type, :user) == :system
          '/usr/local/pyenv'
        else
          '$HOME/.pyenv'
        end
    }

    set :pyenv_roles, fetch(:pyenv_roles, :all)
    set :pyenv_python_dir, -> { "#{fetch(:pyenv_path)}/versions/#{fetch(:pyenv_python)}" }
    set :pyenv_map_bins, %w{pipenv}
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano3-pipenv-0.2.0 lib/capistrano3/pyenv/tasks/pyenv.cap
capistrano3-pipenv-0.1.4 lib/capistrano3/pyenv/tasks/pyenv.cap