Skip to content

Instantly share code, notes, and snippets.

@ba0918
Last active August 29, 2015 13:57
Show Gist options
  • Save ba0918/9543541 to your computer and use it in GitHub Desktop.
Save ba0918/9543541 to your computer and use it in GitHub Desktop.
pythonインスコするレシピ
default[:python][:versions] = ['2.7.6', '3.2.5', '3.3.5']
default[:python][:use_version] = '2.7.6'
#
# Cookbook Name:: python
# Recipe:: default
#
# Copyright 2014, ba0918
#
# pyenvをcloneする
git '/usr/local/pyenv' do
repository 'https://github.com/yyuu/pyenv.git'
revision 'master'
action :sync
end
# pyenv-virtualenvをcloneする
git '/usr/local/pyenv/plugins/pyenv-virtualenv' do
repository 'https://github.com/yyuu/pyenv-virtualenv.git'
revision 'master'
action :sync
end
# 必要なディレクトリを作っておく
directory '/usr/local/pyenv/shims' do
action :create
end
directory '/usr/local/pyenv/versions' do
action :create
end
# pyenv用の環境変数を設定
bash 'setting pyenv configuration' do
code <<-EOH
echo 'export PYENV_ROOT="/usr/local/pyenv"' >> /etc/profile.d/pyenv.sh
echo 'export PATH=$PYENV_ROOT/bin:$PATH' >> /etc/profile.d/pyenv.sh
echo 'eval "$(pyenv init -)"' >> /etc/profile.d/pyenv.sh
. /etc/profile.d/pyenv.sh
EOH
creates '/etc/profile.d/pyenv.sh'
end
# 依存ライブラリをインストールする
%w{zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel}.each do |name|
package name do
action :install
end
end
# pythonインストール
node[:python][:versions].each do |version|
bash 'install python ' + version do
code <<-EOH
. /etc/profile.d/pyenv.sh
pyenv install #{version}
pyenv virtualenv #{version} global-#{version}
EOH
creates '/usr/local/pyenv/versions/#{version}'
end
end
# 普段使うpythonのバージョン設定
bash 'set global python version' do
code <<-EOH
. /etc/profile.d/pyenv.sh
pyenv global #{node[:python][:use_version]}
EOH
not_if "pyenv glogal | grep #{node[:python][:use_version]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment