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

Skip to content

Commit 4476791

Browse files
committed
pip from package where appropriate
1 parent 02a7bdd commit 4476791

File tree

3 files changed

+67
-32
lines changed

3 files changed

+67
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Installs Python from packages.
135135
Installs Python from source.
136136

137137
### pip
138-
Installs `pip` from source.
138+
Installs `pip` from system package if `node["python"]["install_method"] == "package"` and the OS system packages are 2.6+, otherwise will install `pip` from source ( source located in `files/default/*.py` ).
139139

140140
### virtualenv
141141

metadata.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
maintainer_email "[email protected]"
44
license "Apache 2.0"
55
description "Installs Python, pip and virtualenv. Includes LWRPs for managing Python packages with `pip` and `virtualenv` isolated Python environments."
6-
version "1.4.5"
6+
version "1.4.6"
77

88
depends "build-essential"
99
depends "yum"
1010

1111
recipe "python", "Installs python, pip, and virtualenv"
1212
recipe "python::package", "Installs python using packages."
1313
recipe "python::source", "Installs python from source."
14-
recipe "python::pip", "Installs pip from source."
14+
recipe "python::pip", "Installs pip from package or source."
1515
recipe "python::virtualenv", "Installs virtualenv using the python_pip resource."
1616

1717
%w{ debian ubuntu centos redhat fedora freebsd smartos }.each do |os|

recipes/pip.rb

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,75 @@
2323
# redhat/package: /usr/bin/pip (sha a8a3a3)
2424
# omnibus/source: /opt/local/bin/pip (sha 29ce9874)
2525

26+
major_version = node['platform_version'].split('.').first.to_i
27+
if node['python']['install_method'] == 'package'
28+
# COOK-1016 Handle RHEL/CentOS namings of python packages, by installing EPEL
29+
# repo & package
30+
case node["platform_family"]
31+
when 'rhel'
32+
include_recipe 'yum::epel'
33+
if major_version < 6
34+
# rhel 5 defaults of py24 is laffable, better use source.
35+
install_ez_from_source = true
36+
install_pip_from_source = true
37+
else
38+
pip_pkgs = ["python-setuptools", "python-pip"]
39+
end
40+
when 'debian'
41+
pip_pkgs = ["python-pip", "python-setuptools"]
42+
else
43+
install_ez_from_source = true
44+
install_pip_from_source = true
45+
end
46+
if pip_pkgs
47+
pip_pkgs.each do |pkg|
48+
package pkg do
49+
action :install
50+
end
51+
end
52+
end
53+
end
54+
2655
if node['python']['install_method'] == 'source'
2756
pip_binary = "#{node['python']['prefix_dir']}/bin/pip"
28-
elsif platform_family?("rhel")
29-
pip_binary = "/usr/bin/pip"
30-
elsif platform_family?("smartos")
31-
pip_binary = "/opt/local/bin/pip"
57+
install_ez_from_source = true
58+
install_pip_from_source = true
3259
else
33-
pip_binary = "/usr/local/bin/pip"
34-
end
35-
36-
cookbook_file "#{Chef::Config[:file_cache_path]}/ez_setup.py" do
37-
source 'ez_setup.py'
38-
mode "0644"
39-
not_if "#{node['python']['binary']} -c 'import setuptools'"
40-
end
41-
42-
cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do
43-
source 'get-pip.py'
44-
mode "0644"
45-
not_if { ::File.exists?(pip_binary) }
60+
if platform_family?("rhel")
61+
pip_binary = "/usr/bin/pip"
62+
elsif platform_family?("smartos")
63+
pip_binary = "/opt/local/bin/pip"
64+
else
65+
pip_binary = "/usr/local/bin/pip"
66+
end
4667
end
4768

48-
execute "install-setuptools" do
49-
cwd Chef::Config[:file_cache_path]
50-
command <<-EOF
51-
#{node['python']['binary']} ez_setup.py
52-
EOF
53-
not_if "#{node['python']['binary']} -c 'import setuptools'"
69+
if install_ez_from_source
70+
cookbook_file "#{Chef::Config[:file_cache_path]}/ez_setup.py" do
71+
source 'ez_setup.py'
72+
mode "0644"
73+
not_if "#{node['python']['binary']} -c 'import setuptools'"
74+
end
75+
execute "install-setuptools" do
76+
cwd Chef::Config[:file_cache_path]
77+
command <<-EOF
78+
#{node['python']['binary']} ez_setup.py
79+
EOF
80+
not_if "#{node['python']['binary']} -c 'import setuptools'"
81+
end
5482
end
5583

56-
execute "install-pip" do
57-
cwd Chef::Config[:file_cache_path]
58-
command <<-EOF
59-
#{node['python']['binary']} get-pip.py
60-
EOF
61-
not_if { ::File.exists?(pip_binary) }
84+
if install_pip_from_source
85+
cookbook_file "#{Chef::Config[:file_cache_path]}/get-pip.py" do
86+
source 'get-pip.py'
87+
mode "0644"
88+
not_if { ::File.exists?(pip_binary) }
89+
end
90+
execute "install-pip" do
91+
cwd Chef::Config[:file_cache_path]
92+
command <<-EOF
93+
#{node['python']['binary']} get-pip.py
94+
EOF
95+
not_if { ::File.exists?(pip_binary) }
96+
end
6297
end

0 commit comments

Comments
 (0)