From e05c5d80d01e7bb35cdfa6bccc870ec9bb89811e Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Thu, 7 Nov 2013 17:17:54 -0800 Subject: [PATCH 1/3] allow users to override the python package names. This is important with AWS Opsworks, the package `python` installs python 2.6, if you want to install python 2.7 you have to use the package named `python27` --- attributes/default.rb | 25 +++++++++++++++++++------ recipes/package.rb | 11 +---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 85c96eb..8334478 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,4 +1,4 @@ -# + # # Author:: Seth Chisamore () # Cookbook Name:: python # Attribute:: default @@ -19,14 +19,27 @@ # default['python']['install_method'] = 'package' - +major_version = platform_version.split('.').first.to_i if python['install_method'] == 'package' + default['python']['prefix_dir'] = '/usr' case platform - when "smartos" - default['python']['prefix_dir'] = '/opt/local' - else - default['python']['prefix_dir'] = '/usr' + when "debian" + default['python']['python_pkgs'] = ["python","python-dev"] + when "rhel" + if major_version < 6 + default['python']['python_pkgs'] = ["python26", "python26-devel"] + else + default['python']['python_pkgs'] = ["python","python-devel"] + end + when "freebsd" + default['python']['python_pkgs'] = ["python"] + when "smartos" + default['python']['prefix_dir'] = '/opt/local' + default['python']['python_pkgs'] = ["python27"] + else + default['python']['python_pkgs'] = ["python","python-dev"] end + else default['python']['prefix_dir'] = '/usr/local' end diff --git a/recipes/package.rb b/recipes/package.rb index 18c1a00..66d69ac 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -24,19 +24,10 @@ # repo & package if platform_family?('rhel') && major_version < 6 include_recipe 'yum::epel' - python_pkgs = ["python26", "python26-devel"] node.default['python']['binary'] = "/usr/bin/python26" -else - python_pkgs = value_for_platform_family( - "debian" => ["python","python-dev"], - "rhel" => ["python","python-devel"], - "freebsd" => ["python"], - "smartos" => ["python27"], - "default" => ["python","python-dev"] - ) end -python_pkgs.each do |pkg| +node['python']['python_pkgs'].each do |pkg| package pkg do action :install end From 810997f6d8581b0cb7b7a1e8415ad3d3d9fa24c4 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Fri, 8 Nov 2013 12:31:17 -0800 Subject: [PATCH 2/3] Update default.rb --- attributes/default.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 8334478..555be58 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -43,8 +43,8 @@ else default['python']['prefix_dir'] = '/usr/local' end - -default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python" +default['python']['binary_name'] = 'python' +default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" default['python']['url'] = 'http://www.python.org/ftp/python' default['python']['version'] = '2.7.5' From f4e343a74489f871709e2973f0eb7563b16c3822 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Fri, 8 Nov 2013 13:43:15 -0800 Subject: [PATCH 3/3] update to use a dynamic python binary path (the prefix and the binary name can be changed using attributes) --- attributes/default.rb | 4 ++-- recipes/package.rb | 1 - recipes/pip.rb | 9 +++++---- recipes/source.rb | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 555be58..49cc23c 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,6 +18,7 @@ # limitations under the License. # +default['python']['binary_name'] = 'python' default['python']['install_method'] = 'package' major_version = platform_version.split('.').first.to_i if python['install_method'] == 'package' @@ -27,6 +28,7 @@ default['python']['python_pkgs'] = ["python","python-dev"] when "rhel" if major_version < 6 + default['python']['binary_name'] = 'python26' default['python']['python_pkgs'] = ["python26", "python26-devel"] else default['python']['python_pkgs'] = ["python","python-devel"] @@ -43,8 +45,6 @@ else default['python']['prefix_dir'] = '/usr/local' end -default['python']['binary_name'] = 'python' -default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" default['python']['url'] = 'http://www.python.org/ftp/python' default['python']['version'] = '2.7.5' diff --git a/recipes/package.rb b/recipes/package.rb index 66d69ac..1b5aa6e 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -24,7 +24,6 @@ # repo & package if platform_family?('rhel') && major_version < 6 include_recipe 'yum::epel' - node.default['python']['binary'] = "/usr/bin/python26" end node['python']['python_pkgs'].each do |pkg| diff --git a/recipes/pip.rb b/recipes/pip.rb index 1f89070..cef3c6e 100644 --- a/recipes/pip.rb +++ b/recipes/pip.rb @@ -32,11 +32,12 @@ else pip_binary = "/usr/local/bin/pip" end +python_binary = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" cookbook_file "#{Chef::Config[:file_cache_path]}/ez_setup.py" do source 'ez_setup.py' mode "0644" - not_if "#{node['python']['binary']} -c 'import setuptools'" + not_if "#{python_binary} -c 'import setuptools'" end cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do @@ -48,15 +49,15 @@ execute "install-setuptools" do cwd Chef::Config[:file_cache_path] command <<-EOF - #{node['python']['binary']} ez_setup.py + #{python_binary} ez_setup.py EOF - not_if "#{node['python']['binary']} -c 'import setuptools'" + not_if "#{python_binary} -c 'import setuptools'" end execute "install-pip" do cwd Chef::Config[:file_cache_path] command <<-EOF - #{node['python']['binary']} get-pip.py + #{python_binary} get-pip.py EOF not_if { ::File.exists?(pip_binary) } end diff --git a/recipes/source.rb b/recipes/source.rb index 1409ab6..ee24990 100644 --- a/recipes/source.rb +++ b/recipes/source.rb @@ -60,9 +60,10 @@ # Link install as the default python, to support Python 3.x # Otherwise the pip and virtualenv recipes won't work properly -link node['python']['binary'] do +python_binary = "#{node['python']['prefix_dir']}/bin/#{node['python']['binary_name']}" +link python_binary do to install_path - not_if { ::File.exists?(node['python']['binary']) } + not_if { ::File.exists?(python_binary) } end