Permalink
Browse files

added recipe to install from source and refactored based on PyCon fee…

…dback.
  • Loading branch information...
1 parent 39658d2 commit c8b3887e85826b9e494f837fa042a3372149bacb @schisamo schisamo committed Mar 17, 2011
View
@@ -1,7 +1,7 @@
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
============
@@ -15,10 +15,17 @@ Platform
Cookbooks
---------
+* build-essential
+
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
=================
@@ -109,7 +116,31 @@ Install packages using the new hotness in Python package management...[`pip`](ht
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
==================
@@ -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']}}
View
@@ -1,6 +1,6 @@
{
"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": "",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
@@ -23,6 +23,9 @@
]
},
"dependencies": {
+ "build-essential": [
+
+ ]
},
"recommendations": {
},
@@ -39,7 +42,11 @@
"groupings": {
},
"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"
}
View
@@ -1,10 +1,16 @@
maintainer "Opscode, Inc."
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
-description "Installs python packages. Includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments."
-version "1.0.1"
+description "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments."
+version "1.0.2"
+
+depends "build-essential"
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|
supports os
@@ -18,42 +18,6 @@
# 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
-
-# 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
+include_recipe "python::#{node['python']['install_method']}"
+include_recipe "python::pip"
+include_recipe "python::virtualenv"
@@ -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
+
View
@@ -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
@@ -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
@@ -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.