Skip to content

Commit

Permalink
added recipe to install from source and refactored based on PyCon fee…
Browse files Browse the repository at this point in the history
…dback.
  • Loading branch information
schisamo committed Mar 17, 2011
1 parent 39658d2 commit c8b3887
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 47 deletions.
37 changes: 34 additions & 3 deletions python/README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
Description Description
=========== ===========


Installs and configures Python 2.6. Also includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments. Installs and configures Python. Also includes LWRPs for managing python packages with `pip` and `virtualenv` isolated Python environments.


Requirements Requirements
============ ============
Expand All @@ -15,10 +15,17 @@ Platform
Cookbooks Cookbooks
--------- ---------


* build-essential

Attributes Attributes
========== ==========


None at this time. * `node["python"]["install_method"]` = method to install python with, default `package`.

The file also contains the following attribute types:

* platform specific locations and settings.
* source installation settings


Resource/Provider Resource/Provider
================= =================
Expand Down Expand Up @@ -109,7 +116,31 @@ Install packages using the new hotness in Python package management...[`pip`](ht
Usage Usage
===== =====


Simply include the recipe where you want Python 2.6 installed. default
-------

Include default recipe in a run list, to get `python`, `pip` and `virtualenv`. Installs python by package or source depending on the platform.

package
-------

Installs Python from packages.

source
------

Installs Python from source.

pip
---

Installs `pip` from source.

virtualenv
----------

Installs virtualenv using the `python_pip` resource.



License and Author License and Author
================== ==================
Expand Down
28 changes: 28 additions & 0 deletions python/attributes/default.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: python
# Attribute:: default
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

default['python']['install_method'] = 'package'

default['python']['url'] = 'http://www.python.org/ftp/python'
default['python']['version'] = '2.7.1'
default['python']['checksum'] = '80e387bcf57eae8ce26726753584fd63e060ec11682d1145af921e85fd612292'
default['python']['prefix_dir'] = '/usr/local'

default['python']['configure_options'] = %W{--prefix=#{python['prefix_dir']}}
13 changes: 10 additions & 3 deletions python/metadata.json
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
{ {
"name": "python", "name": "python",
"description": "Installs python packages. Includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments.", "description": "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments.",
"long_description": "", "long_description": "",
"maintainer": "Opscode, Inc.", "maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com", "maintainer_email": "cookbooks@opscode.com",
Expand All @@ -23,6 +23,9 @@
] ]
}, },
"dependencies": { "dependencies": {
"build-essential": [

]
}, },
"recommendations": { "recommendations": {
}, },
Expand All @@ -39,7 +42,11 @@
"groupings": { "groupings": {
}, },
"recipes": { "recipes": {
"python": "Installs python, pip, and virtualenv" "python": "Installs python, pip, and virtualenv",
"python::package": "Installs python using packages.",
"python::source": "Installs python from source.",
"python::pip": "Installs pip from source.",
"python::virtualenv": "Installs virtualenv using the python_pip resource."
}, },
"version": "1.0.1" "version": "1.0.2"
} }
10 changes: 8 additions & 2 deletions python/metadata.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,16 @@
maintainer "Opscode, Inc." maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com" maintainer_email "cookbooks@opscode.com"
license "Apache 2.0" license "Apache 2.0"
description "Installs python packages. Includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments." description "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments."
version "1.0.1" version "1.0.2"

depends "build-essential"


recipe "python", "Installs python, pip, and virtualenv" recipe "python", "Installs python, pip, and virtualenv"
recipe "python::package", "Installs python using packages."
recipe "python::source", "Installs python from source."
recipe "python::pip", "Installs pip from source."
recipe "python::virtualenv", "Installs virtualenv using the python_pip resource."


%w{ debian ubuntu centos redhat fedora }.each do |os| %w{ debian ubuntu centos redhat fedora }.each do |os|
supports os supports os
Expand Down
42 changes: 3 additions & 39 deletions python/recipes/default.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,42 +18,6 @@
# limitations under the License. # limitations under the License.
# #


python_pkgs = value_for_platform( include_recipe "python::#{node['python']['install_method']}"
["debian","ubuntu"] => { include_recipe "python::pip"
"default" => ["python","python-dev"] include_recipe "python::virtualenv"
},
["centos","redhat","fedora"] => {
"default" => ["python26","python26-devel"]
},
"default" => ["python","python-dev"]
)

python_pkgs.each do |pkg|
package pkg do
action :install
end
end

# Ubuntu's python-setuptools, python-pip and python-virtualenv packages
# are broken...this feels like Rubygems!
# http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
# https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux
bash "install-pip" do
cwd Chef::Config[:file_cache_path]
code <<-EOH
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
EOH
not_if "which pip"
action :nothing
end
remote_file "#{Chef::Config[:file_cache_path]}/distribute_setup.py" do
source "http://python-distribute.org/distribute_setup.py"
notifies :run, "bash[install-pip]", :immediate
not_if "which pip"
end

python_pip "virtualenv" do
action :install
end
36 changes: 36 additions & 0 deletions python/recipes/package.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Author:: Seth Chisamore <schisamo@opscode.com>
# Cookbook Name:: python
# Recipe:: package
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

python_pkgs = value_for_platform(
["debian","ubuntu"] => {
"default" => ["python","python-dev"]
},
["centos","redhat","fedora"] => {
"default" => ["python26","python26-devel"]
},
"default" => ["python","python-dev"]
)

python_pkgs.each do |pkg|
package pkg do
action :install
end
end

38 changes: 38 additions & 0 deletions python/recipes/pip.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Author:: Seth Chisamore <schisamo@opscode.com>
# Cookbook Name:: python
# Recipe:: pip
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Ubuntu's python-setuptools, python-pip and python-virtualenv packages
# are broken...this feels like Rubygems!
# http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
# https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux
remote_file "#{Chef::Config[:file_cache_path]}/distribute_setup.py" do
source "http://python-distribute.org/distribute_setup.py"
mode "0644"
not_if "which pip"
end

bash "install-pip" do
cwd Chef::Config[:file_cache_path]
code <<-EOF
python distribute_setup.py
easy_install pip
EOF
not_if "which pip"
end
52 changes: 52 additions & 0 deletions python/recipes/source.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Author:: Seth Chisamore <schisamo@opscode.com>
# Cookbook Name:: python
# Recipe:: source
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

configure_options = node['python']['configure_options'].join(" ")

packages = value_for_platform(
["centos","redhat","fedora"] =>
{"default" => ["openssl-devel","bzip2-devel","zlib-devel","expat-devel","db4-devel","sqlite-devel","ncurses-devel","readline-devel"]},
"default" =>
["libssl-dev","libbz2-dev","zlib1g-dev","libexpat1-dev","libdb4.8-dev","libsqlite3-dev","libncursesw5-dev","libncurses5-dev","libreadline-dev"]
)

packages.each do |dev_pkg|
package dev_pkg
end

version = node['python']['version']
install_path = "#{node['python']['prefix_dir']}/lib/python#{version.split(/(^\d+\.\d+)/)}"

remote_file "#{Chef::Config[:file_cache_path]}/Python-#{version}.tar.bz2" do
source "#{node['python']['url']}/#{version}/Python-#{version}.tar.bz2"
checksum node['python']['checksum']
mode "0644"
not_if { ::File.exists?(install_path) }
end

bash "build-and-install-python" do
cwd Chef::Config[:file_cache_path]
code <<-EOF
tar -jxvf Python-#{version}.tar.bz2
(cd Python-#{version} && ./configure #{configure_options})
(cd Python-#{version} && make && make install)
EOF
not_if { ::File.exists?(install_path) }
end
25 changes: 25 additions & 0 deletions python/recipes/virtualenv.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Author:: Seth Chisamore <schisamo@opscode.com>
# Cookbook Name:: python
# Recipe:: virtualenv
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "python::pip"

python_pip "virtualenv" do
action :install
end

0 comments on commit c8b3887

Please sign in to comment.