Last active
August 29, 2015 13:57
-
-
Save ba0918/9543541 to your computer and use it in GitHub Desktop.
pythonインスコするレシピ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default[:python][:versions] = ['2.7.6', '3.2.5', '3.3.5'] | |
default[:python][:use_version] = '2.7.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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