Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7cc9b15

Browse files
committed
added recipe to install from source and refactored based on PyCon feedback.
1 parent 6985ee1 commit 7cc9b15

File tree

9 files changed

+234
-47
lines changed

9 files changed

+234
-47
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Description
22
===========
33

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

66
Requirements
77
============
@@ -15,10 +15,17 @@ Platform
1515
Cookbooks
1616
---------
1717

18+
* build-essential
19+
1820
Attributes
1921
==========
2022

21-
None at this time.
23+
* `node["python"]["install_method"]` = method to install python with, default `package`.
24+
25+
The file also contains the following attribute types:
26+
27+
* platform specific locations and settings.
28+
* source installation settings
2229

2330
Resource/Provider
2431
=================
@@ -109,7 +116,31 @@ Install packages using the new hotness in Python package management...[`pip`](ht
109116
Usage
110117
=====
111118

112-
Simply include the recipe where you want Python 2.6 installed.
119+
default
120+
-------
121+
122+
Include default recipe in a run list, to get `python`, `pip` and `virtualenv`. Installs python by package or source depending on the platform.
123+
124+
package
125+
-------
126+
127+
Installs Python from packages.
128+
129+
source
130+
------
131+
132+
Installs Python from source.
133+
134+
pip
135+
---
136+
137+
Installs `pip` from source.
138+
139+
virtualenv
140+
----------
141+
142+
Installs virtualenv using the `python_pip` resource.
143+
113144

114145
License and Author
115146
==================

attributes/default.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Author:: Seth Chisamore (<[email protected]>)
3+
# Cookbook Name:: python
4+
# Attribute:: default
5+
#
6+
# Copyright 2011, Opscode, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
default['python']['install_method'] = 'package'
22+
23+
default['python']['url'] = 'http://www.python.org/ftp/python'
24+
default['python']['version'] = '2.7.1'
25+
default['python']['checksum'] = '80e387bcf57eae8ce26726753584fd63e060ec11682d1145af921e85fd612292'
26+
default['python']['prefix_dir'] = '/usr/local'
27+
28+
default['python']['configure_options'] = %W{--prefix=#{python['prefix_dir']}}

metadata.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "python",
3-
"description": "Installs python packages. Includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments.",
3+
"description": "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments.",
44
"long_description": "",
55
"maintainer": "Opscode, Inc.",
66
"maintainer_email": "[email protected]",
@@ -23,6 +23,9 @@
2323
]
2424
},
2525
"dependencies": {
26+
"build-essential": [
27+
28+
]
2629
},
2730
"recommendations": {
2831
},
@@ -39,7 +42,11 @@
3942
"groupings": {
4043
},
4144
"recipes": {
42-
"python": "Installs python, pip, and virtualenv"
45+
"python": "Installs python, pip, and virtualenv",
46+
"python::package": "Installs python using packages.",
47+
"python::source": "Installs python from source.",
48+
"python::pip": "Installs pip from source.",
49+
"python::virtualenv": "Installs virtualenv using the python_pip resource."
4350
},
44-
"version": "1.0.1"
51+
"version": "1.0.2"
4552
}

metadata.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
maintainer "Opscode, Inc."
22
maintainer_email "[email protected]"
33
license "Apache 2.0"
4-
description "Installs python packages. Includes LWRPs for managing `pip` packages and `virtualenv` isolated Python environments."
5-
version "1.0.1"
4+
description "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments."
5+
version "1.0.2"
6+
7+
depends "build-essential"
68

79
recipe "python", "Installs python, pip, and virtualenv"
10+
recipe "python::package", "Installs python using packages."
11+
recipe "python::source", "Installs python from source."
12+
recipe "python::pip", "Installs pip from source."
13+
recipe "python::virtualenv", "Installs virtualenv using the python_pip resource."
814

915
%w{ debian ubuntu centos redhat fedora }.each do |os|
1016
supports os

recipes/default.rb

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,6 @@
1818
# limitations under the License.
1919
#
2020

21-
python_pkgs = value_for_platform(
22-
["debian","ubuntu"] => {
23-
"default" => ["python","python-dev"]
24-
},
25-
["centos","redhat","fedora"] => {
26-
"default" => ["python26","python26-devel"]
27-
},
28-
"default" => ["python","python-dev"]
29-
)
30-
31-
python_pkgs.each do |pkg|
32-
package pkg do
33-
action :install
34-
end
35-
end
36-
37-
# Ubuntu's python-setuptools, python-pip and python-virtualenv packages
38-
# are broken...this feels like Rubygems!
39-
# http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
40-
# https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux
41-
bash "install-pip" do
42-
cwd Chef::Config[:file_cache_path]
43-
code <<-EOH
44-
curl -O http://python-distribute.org/distribute_setup.py
45-
python distribute_setup.py
46-
easy_install pip
47-
EOH
48-
not_if "which pip"
49-
action :nothing
50-
end
51-
remote_file "#{Chef::Config[:file_cache_path]}/distribute_setup.py" do
52-
source "http://python-distribute.org/distribute_setup.py"
53-
notifies :run, "bash[install-pip]", :immediate
54-
not_if "which pip"
55-
end
56-
57-
python_pip "virtualenv" do
58-
action :install
59-
end
21+
include_recipe "python::#{node['python']['install_method']}"
22+
include_recipe "python::pip"
23+
include_recipe "python::virtualenv"

recipes/package.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# Author:: Seth Chisamore <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: package
5+
#
6+
# Copyright 2011, Opscode, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
python_pkgs = value_for_platform(
22+
["debian","ubuntu"] => {
23+
"default" => ["python","python-dev"]
24+
},
25+
["centos","redhat","fedora"] => {
26+
"default" => ["python26","python26-devel"]
27+
},
28+
"default" => ["python","python-dev"]
29+
)
30+
31+
python_pkgs.each do |pkg|
32+
package pkg do
33+
action :install
34+
end
35+
end
36+

recipes/pip.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Author:: Seth Chisamore <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: pip
5+
#
6+
# Copyright 2011, Opscode, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
# Ubuntu's python-setuptools, python-pip and python-virtualenv packages
22+
# are broken...this feels like Rubygems!
23+
# http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python
24+
# https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux
25+
remote_file "#{Chef::Config[:file_cache_path]}/distribute_setup.py" do
26+
source "http://python-distribute.org/distribute_setup.py"
27+
mode "0644"
28+
not_if "which pip"
29+
end
30+
31+
bash "install-pip" do
32+
cwd Chef::Config[:file_cache_path]
33+
code <<-EOF
34+
python distribute_setup.py
35+
easy_install pip
36+
EOF
37+
not_if "which pip"
38+
end

recipes/source.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Author:: Seth Chisamore <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: source
5+
#
6+
# Copyright 2011, Opscode, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
configure_options = node['python']['configure_options'].join(" ")
22+
23+
packages = value_for_platform(
24+
["centos","redhat","fedora"] =>
25+
{"default" => ["openssl-devel","bzip2-devel","zlib-devel","expat-devel","db4-devel","sqlite-devel","ncurses-devel","readline-devel"]},
26+
"default" =>
27+
["libssl-dev","libbz2-dev","zlib1g-dev","libexpat1-dev","libdb4.8-dev","libsqlite3-dev","libncursesw5-dev","libncurses5-dev","libreadline-dev"]
28+
)
29+
30+
packages.each do |dev_pkg|
31+
package dev_pkg
32+
end
33+
34+
version = node['python']['version']
35+
install_path = "#{node['python']['prefix_dir']}/lib/python#{version.split(/(^\d+\.\d+)/)}"
36+
37+
remote_file "#{Chef::Config[:file_cache_path]}/Python-#{version}.tar.bz2" do
38+
source "#{node['python']['url']}/#{version}/Python-#{version}.tar.bz2"
39+
checksum node['python']['checksum']
40+
mode "0644"
41+
not_if { ::File.exists?(install_path) }
42+
end
43+
44+
bash "build-and-install-python" do
45+
cwd Chef::Config[:file_cache_path]
46+
code <<-EOF
47+
tar -jxvf Python-#{version}.tar.bz2
48+
(cd Python-#{version} && ./configure #{configure_options})
49+
(cd Python-#{version} && make && make install)
50+
EOF
51+
not_if { ::File.exists?(install_path) }
52+
end

recipes/virtualenv.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Author:: Seth Chisamore <[email protected]>
3+
# Cookbook Name:: python
4+
# Recipe:: virtualenv
5+
#
6+
# Copyright 2011, Opscode, Inc.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
#
20+
21+
include_recipe "python::pip"
22+
23+
python_pip "virtualenv" do
24+
action :install
25+
end

0 commit comments

Comments
 (0)