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

Skip to content

Commit 06266b4

Browse files
author
kouroshparsa
committed
adding windows support
1 parent 68edd40 commit 06266b4

File tree

9 files changed

+119
-11
lines changed

9 files changed

+119
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ python Cookbook CHANGELOG
22
=========================
33
This file is used to list changes made in each version of the python cookbook.
44

5+
v1.4.7
6+
------
7+
Added windows support for python cookbook
8+
59
v1.4.6
610
------
711

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Requirements
1111
### Platforms
1212
- Debian, Ubuntu
1313
- CentOS, Red Hat, Fedora
14+
- Windows
1415

1516
### Cookbooks
1617
- build-essential
@@ -132,7 +133,7 @@ Include default recipe in a run list, to get `python`, `pip` and `virtualenv`. I
132133
Installs Python from packages.
133134

134135
### source
135-
Installs Python from source.
136+
Installs Python from source (not supported on windows).
136137

137138
### pip
138139
Installs `pip` from source.
@@ -144,7 +145,7 @@ Installs virtualenv using the `python_pip` resource.
144145

145146
License & Authors
146147
-----------------
147-
- Author:: Seth Chisamore (<[email protected]>)
148+
- Authors:: Seth Chisamore (<[email protected]>), Kourosh Parsa([email protected])
148149

149150
```text
150151
Copyright:: 2011, Chef Software, Inc

attributes/default.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,26 @@
3131
default['python']['prefix_dir'] = '/usr/local'
3232
end
3333

34-
default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python"
35-
3634
default['python']['url'] = 'http://www.python.org/ftp/python'
3735
default['python']['version'] = '2.7.7'
3836
default['python']['checksum'] = '7f49c0a6705ad89d925181e27d0aaa025ee4731ce0de64776c722216c3e66c42'
3937
default['python']['configure_options'] = %W{--prefix=#{node['python']['prefix_dir']}}
4038
default['python']['make_options'] = %W{install}
4139

42-
default['python']['pip_location'] = "#{node['python']['prefix_dir']}/bin/pip"
43-
default['python']['virtualenv_location'] = "#{node['python']['prefix_dir']}/bin/virtualenv"
4440
default['python']['setuptools_version'] = nil # defaults to latest
4541
default['python']['virtualenv_version'] = nil
42+
43+
ver = default['python']['version']
44+
default['python']['ez_setup'] = 'https://bootstrap.pypa.io/ez_setup.py'
45+
46+
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
47+
default['python']['home'] = "#{ENV['SYSTEMDRIVE']}\\Python#{ver.split('.')[0..1].join('')}"
48+
default['python']['easy_install'] = "#{node['python']['home']}\\Scripts\\easy_install.exe"
49+
default['python']['binary'] = "#{node['python']['home']}/python.exe"
50+
default['python']['pip_location'] = "#{node['python']['home']}\\Scripts\\pip.exe"
51+
default['python']['virtualenv_location'] = "#{node['python']['home']}\\Scripts\\virtualenv"
52+
else
53+
default['python']['binary'] = "#{node['python']['prefix_dir']}/bin/python"
54+
default['python']['pip_location'] = "#{node['python']['prefix_dir']}/bin/pip"
55+
default['python']['virtualenv_location'] = "#{node['python']['prefix_dir']}/bin/virtualenv"
56+
end

metadata.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
recipe "python::source", "Installs python from source."
1414
recipe "python::pip", "Installs pip from source."
1515
recipe "python::virtualenv", "Installs virtualenv using the python_pip resource."
16-
17-
%w{ debian ubuntu centos redhat fedora freebsd smartos }.each do |os|
16+
recipe "python::windows", "Installs python on windows"
17+
recipe "python::windows_pip", "Installs easy_install and pip"
18+
%w{ debian ubuntu centos redhat fedora freebsd smartos windows}.each do |os|
1819
supports os
1920
end
21+
depends 'windows'

recipes/default.rb

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

21-
include_recipe "python::#{node['python']['install_method']}"
22-
include_recipe "python::pip"
23-
include_recipe "python::virtualenv"
21+
if Chef::Platform.windows?
22+
include_recipe 'python::windows'
23+
include_recipe 'python::windows_pip'
24+
else
25+
include_recipe "python::#{node['python']['install_method']}"
26+
include_recipe "python::pip"
27+
include_recipe "python::virtualenv"
28+
end
29+

recipes/test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python_pip "x" do
2+
package_name "nose"
3+
action :install
4+
end

recipes/windows.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Author:: Kourosh Parsa <[email protected]>
2+
# Cookbook Name:: python
3+
# Recipe:: windows
4+
#
5+
# Copyright 2015
6+
# All rights reserved
7+
# This recipe installs python on windows
8+
#
9+
def is_windows_64bit?
10+
ENV['PROCESSOR_ARCHITECTURE'].include?("64")
11+
end
12+
13+
version = node['python']['version']
14+
bitness = ''
15+
if is_windows_64bit?
16+
bitness = '.amd64'
17+
end
18+
19+
bin_name = "python-#{version}#{bitness}.msi"
20+
download_path = "#{Chef::Config[:file_cache_path]}\\#{bin_name}"
21+
22+
windows_package 'Install Python' do
23+
source "#{node['python']['url']}/#{version}/#{bin_name}"
24+
action :install
25+
not_if do ::File.exist?(node['python']['home']) end
26+
end
27+
28+
windows_path node['python']['home'] do
29+
action :add
30+
end
31+

recipes/windows_pip.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Author:: Kourosh Parsa <[email protected]>
2+
# Cookbook Name:: python
3+
# Recipe:: windows_pip
4+
#
5+
# Copyright 2015
6+
# All rights reserved
7+
# This recipe installs ez_install and pip on windows
8+
#
9+
10+
ez_setup_path = "#{Chef::Config[:file_cache_path]}\\ez_setup.py"
11+
remote_file ez_setup_path do
12+
source node['python']['ez_setup']
13+
not_if do ::File.exist?("#{Chef::Config[:file_cache_path]}\\#{ez_setup_path}") end
14+
end
15+
16+
batch "install easy_install" do
17+
code "#{node['python']['binary']} #{ez_setup_path}"
18+
not_if do ::File.exist?(node['python']['easy_install']) end
19+
end
20+
21+
windows_path "#{node['python']['home']}\\Scripts" do
22+
action :add
23+
end
24+
25+
batch "install pip" do
26+
code "#{node['python']['easy_install']} pip"
27+
not_if do ::File.exist?(node['python']['pip_location']) end
28+
end

recipes/windows_virtualenv.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Author:: Kourosh Parsa <[email protected]>
2+
# Cookbook Name:: python
3+
# Recipe:: windows_virtualenv
4+
#
5+
# Copyright 2015
6+
# All rights reserved
7+
# This recipe installs virtualenv on windows
8+
#
9+
10+
default['python']['virtualenv_location']
11+
12+
ez_setup_path = "#{Chef::Config[:file_cache_path]}\\ez_setup.py"
13+
remote_file ez_setup_path do
14+
source node['python']['pip']
15+
not_if do ::File.exist?("#{Chef::Config[:file_cache_path]}\\#{ez_setup_path}") end
16+
end
17+
18+
batch "install virtualenv" do
19+
code "#{node['python']['pip_location']} install virtualenv"
20+
not_if do ::File.exist?("#{node['python']['home']}\\Scripts\\virtualenv.exe") end
21+
end

0 commit comments

Comments
 (0)